当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils类代码示例

本文整理汇总了Java中org.andengine.util.math.MathUtils的典型用法代码示例。如果您正苦于以下问题:Java MathUtils类的具体用法?Java MathUtils怎么用?Java MathUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MathUtils类属于org.andengine.util.math包,在下文中一共展示了MathUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ETC1Texture

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
public ETC1Texture(final TextureManager pTextureManager, final TextureOptions pTextureOptions, final ITextureStateListener pTextureStateListener) throws IOException {
	super(pTextureManager, PixelFormat.RGB_565, pTextureOptions, pTextureStateListener);

	InputStream inputStream = null;
	try {
		inputStream = this.getInputStream();

		this.mETC1TextureHeader = new ETC1TextureHeader(StreamUtils.streamToBytes(inputStream, ETC1.ETC_PKM_HEADER_SIZE));

		if (BuildConfig.DEBUG) {
			if (!(MathUtils.isPowerOfTwo(this.mETC1TextureHeader.mWidth) && MathUtils.isPowerOfTwo(this.mETC1TextureHeader.mHeight))) {
				Debug.w("ETC1 textures with NPOT sizes can cause a crash on PowerVR GPUs!");
			}
		}
	} finally {
		StreamUtils.close(inputStream);
	}
}
 
开发者ID:mediamonks,项目名称:tilt-game-android,代码行数:19,代码来源:ETC1Texture.java

示例2: convertSurfaceTouchEventToSceneTouchEvent

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
public void convertSurfaceTouchEventToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	final float relativeX;
	final float relativeY;

	final float surfaceTouchEventX = pSurfaceTouchEvent.getX();
	final float surfaceTouchEventY = pSurfaceTouchEvent.getY();

	final float rotation = this.mRotation;
	if (rotation == 0) {
		relativeX = surfaceTouchEventX / pSurfaceWidth;
		relativeY = 1 - (surfaceTouchEventY / pSurfaceHeight);
	} else if (rotation == 180) {
		relativeX = 1 - (surfaceTouchEventX / pSurfaceWidth);
		relativeY = surfaceTouchEventY / pSurfaceHeight;
	} else {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = surfaceTouchEventX;
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = surfaceTouchEventY;

		MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!

		relativeX = Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] / pSurfaceWidth;
		relativeY = 1 - (Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] / pSurfaceHeight);
	}

	this.convertAxisAlignedSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, relativeX, relativeY);
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:27,代码来源:Camera.java

示例3: convertSceneTouchEventToSurfaceTouchEvent

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
public void convertSceneTouchEventToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	this.convertAxisAlignedSceneToSurfaceTouchEvent(pSceneTouchEvent, pSurfaceWidth, pSurfaceHeight);

	final float rotation = this.mRotation;
	if (rotation == 0) {
		/* Nothing. */
	} else if (rotation == 180) {
		pSceneTouchEvent.setY(pSurfaceHeight - pSceneTouchEvent.getY());
		pSceneTouchEvent.setX(pSurfaceWidth - pSceneTouchEvent.getX());
	} else {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, -rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:19,代码来源:Camera.java

示例4: getBezierCurveLength

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
/**
 * Calculates the length of a Bézier curve by taking <code>pSamples</code> samples.
 *
 * @param pXs x-coordinates of the control points of the Bézier curve.
 * @param pYs y-coordinates of the control points of the Bézier curve.
 * @param pSamples the number of samples to take. The higher the more accurate.
 * @return
 */
public static final float getBezierCurveLength(final float[] pXs, final float[] pYs, final int pSamples) {
	float length = 0;
	final int n = pXs.length - 1;

	float lastX = pXs[0];
	float lastY = pYs[0];
	for (int k = 1; k <= LENGTH_SAMPLES_DEFAULT; k++) {
		final float t = (1f * k) / LENGTH_SAMPLES_DEFAULT;

		float x = 0;
		float y = 0;
		for (int i = 0; i <= n; i++) {
			final float bernstein = BezierCurveUtils.getBernsteinPolynomial(t, i, n);
			x += pXs[i] * bernstein;
			y += pYs[i] * bernstein;
		}

		length += MathUtils.distance(lastX, lastY, x, y);

		lastX = x;
		lastY = y;
	}

	return length;
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:34,代码来源:BezierCurveUtils.java

示例5: LongMap

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
/**
 * Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity * loadFactor items
 * before growing the backing table.
 */
public LongMap (int initialCapacity, float loadFactor) {
	if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
	if (capacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity);
	capacity = MathUtils.nextPowerOfTwo(initialCapacity);

	if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor);
	this.loadFactor = loadFactor;

	threshold = (int)(capacity * loadFactor);
	mask = capacity - 1;
	hashShift = 31 - Integer.numberOfTrailingZeros(capacity);
	stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) + 1);
	pushIterations = Math.max(Math.min(capacity, 32), (int)Math.sqrt(capacity) / 4);

	keyTable = new long[capacity + stashCapacity];
	valueTable = (V[])new Object[keyTable.length];
}
 
开发者ID:mediamonks,项目名称:tilt-game-android,代码行数:22,代码来源:LongMap.java

示例6: getSceneCoordinatesFromSurfaceCoordinates

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
public float[] getSceneCoordinatesFromSurfaceCoordinates(final float[] pSurfaceCoordinates, final int pSurfaceWidth, final int pSurfaceHeight) {
	final float relativeX;
	final float relativeY;

	final float rotation = this.mRotation;
	if (rotation == 0) {
		relativeX = pSurfaceCoordinates[Constants.VERTEX_INDEX_X] / pSurfaceWidth;
		relativeY = 1 - (pSurfaceCoordinates[Constants.VERTEX_INDEX_Y] / pSurfaceHeight);
	} else if (rotation == 180) {
		relativeX = 1 - (pSurfaceCoordinates[Constants.VERTEX_INDEX_X] / pSurfaceWidth);
		relativeY = pSurfaceCoordinates[Constants.VERTEX_INDEX_Y] / pSurfaceHeight;
	} else {
		MathUtils.rotateAroundCenter(pSurfaceCoordinates, rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!

		relativeX = pSurfaceCoordinates[Constants.VERTEX_INDEX_X] / pSurfaceWidth;
		relativeY = 1 - (pSurfaceCoordinates[Constants.VERTEX_INDEX_Y] / pSurfaceHeight);
	}

	this.convertAxisAlignedSurfaceCoordinatesToSceneCoordinates(pSurfaceCoordinates, relativeX, relativeY);

	return pSurfaceCoordinates;
}
 
开发者ID:mediamonks,项目名称:tilt-game-android,代码行数:23,代码来源:Camera.java

示例7: drawOrthogonal

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
/**
 * Call if this if the map is Orthogonal <br>
 * This is the original unmodified orthogonal render.
 * 
 * @param pGLState
 * @param pCamera
 */
private void drawOrthogonal(final GLState pGLState, final Camera pCamera) {
	final int tileColumns = this.mTileColumns;
	final int tileRows = this.mTileRows;
	final int tileWidth = this.mTMXTiledMap.getTileWidth();
	final int tileHeight = this.mTMXTiledMap.getTileHeight();

	final float scaledTileWidth = tileWidth * this.mScaleX;
	final float scaledTileHeight = tileHeight * this.mScaleY;

	final float[] cullingVertices = this.mCullingVertices;

	final float layerMinX = cullingVertices[SpriteBatch.VERTEX_INDEX_X];
	final float layerMinY = cullingVertices[SpriteBatch.VERTEX_INDEX_Y];

	final float cameraMinX = pCamera.getXMin();
	final float cameraMinY = pCamera.getYMin();
	final float cameraWidth = pCamera.getWidth();
	final float cameraHeight = pCamera.getHeight();

	/* Determine the area that is visible in the camera. */
	final float firstColumnRaw = (cameraMinX - layerMinX) / scaledTileWidth;
	final int firstColumn = MathUtils.bringToBounds(0, tileColumns - 1, (int) Math.floor(firstColumnRaw));
	final int lastColumn = MathUtils.bringToBounds(0, tileColumns - 1,
			(int) Math.ceil(firstColumnRaw + cameraWidth / scaledTileWidth));

	final float firstRowRaw = (cameraMinY - layerMinY) / scaledTileHeight;
	final int firstRow = MathUtils.bringToBounds(0, tileRows - 1, (int) Math.floor(firstRowRaw));
	final int lastRow = MathUtils.bringToBounds(0, tileRows - 1,
			(int) Math.floor(firstRowRaw + cameraHeight / scaledTileHeight));

	for (int row = firstRow; row <= lastRow; row++) {
		for (int column = firstColumn; column <= lastColumn; column++) {
			this.mSpriteBatchVertexBufferObject.draw(GLES20.GL_TRIANGLE_STRIP,
					this.getSpriteBatchIndex(column, row) * SpriteBatch.VERTICES_PER_SPRITE,
					SpriteBatch.VERTICES_PER_SPRITE);
		}
	}
}
 
开发者ID:Linguaculturalists,项目名称:Phoenicia,代码行数:46,代码来源:TMXLayer.java

示例8: clipForCamera

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
/**
  * Perform clipping using normal Scene coordinate transformations
  * @param pGLState
  * @param pCamera
  */
 private void clipForCamera(GLState pGLState, Camera pCamera) {
     final int surfaceHeight = pCamera.getSurfaceHeight();

/* In order to apply clipping, we need to determine the the axis aligned bounds in OpenGL coordinates. */

/* Determine clipping coordinates of each corner in surface coordinates. */
     final float[] lowerLeftSurfaceCoordinates = pCamera.getSurfaceCoordinatesFromSceneCoordinates(this.convertLocalCoordinatesToSceneCoordinates(0, 0, new float[2]));
     final int lowerLeftX = (int)Math.round(lowerLeftSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
     final int lowerLeftY = surfaceHeight - (int)Math.round(lowerLeftSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);

     final float[] upperLeftSurfaceCoordinates = pCamera.getSurfaceCoordinatesFromSceneCoordinates(this.convertLocalCoordinatesToSceneCoordinates(0, this.mHeight, new float[2]));
     final int upperLeftX = (int)Math.round(upperLeftSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
     final int upperLeftY = surfaceHeight - (int)Math.round(upperLeftSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);

     final float[] upperRightSurfaceCoordinates = pCamera.getSurfaceCoordinatesFromSceneCoordinates(this.convertLocalCoordinatesToSceneCoordinates(this.mWidth, this.mHeight, new float[2]));
     final int upperRightX = (int)Math.round(upperRightSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
     final int upperRightY = surfaceHeight - (int)Math.round(upperRightSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);

     final float[] lowerRightSurfaceCoordinates = pCamera.getSurfaceCoordinatesFromSceneCoordinates(this.convertLocalCoordinatesToSceneCoordinates(this.mWidth, 0, new float[2]));
     final int lowerRightX = (int)Math.round(lowerRightSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
     final int lowerRightY = surfaceHeight - (int)Math.round(lowerRightSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);

/* Determine minimum and maximum x clipping coordinates. */
     final int minClippingX = MathUtils.min(lowerLeftX, upperLeftX, upperRightX, lowerRightX);
     final int maxClippingX = MathUtils.max(lowerLeftX, upperLeftX, upperRightX, lowerRightX);

/* Determine minimum and maximum y clipping coordinates. */
     final int minClippingY = MathUtils.min(lowerLeftY, upperLeftY, upperRightY, lowerRightY);
     final int maxClippingY = MathUtils.max(lowerLeftY, upperLeftY, upperRightY, lowerRightY);

/* Determine clipping width and height. */
     final int clippingWidth = maxClippingX - minClippingX;
     final int clippingHeight = maxClippingY - minClippingY;
     //Debug.d("ClippingY: min="+minClippingY+", max="+maxClippingY);
     //Debug.d("clipForCamera: GLES20.glScissor("+minClippingX+", "+minClippingY+", "+clippingWidth+", "+clippingHeight+")");
     GLES20.glScissor(minClippingX, minClippingY, clippingWidth, clippingHeight);
 }
 
开发者ID:Linguaculturalists,项目名称:Phoenicia,代码行数:43,代码来源:Scrollable.java

示例9: applySceneToCameraSceneOffset

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
@Override
protected void applySceneToCameraSceneOffset(final float[] pSceneCoordinates) {
	final float zoomFactor = this.mZoomFactor;
	if(zoomFactor != 1) {
		MathUtils.scaleAroundCenter(pSceneCoordinates, zoomFactor, zoomFactor, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!
	}

	super.applySceneToCameraSceneOffset(pSceneCoordinates);
}
 
开发者ID:peterchaula,项目名称:ClassicF1,代码行数:10,代码来源:ZoomCamera.java

示例10: LevelStatsDBConnector

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
public LevelStatsDBConnector(final Context pContext, final String pSecret, final String pSubmitURL) {
	this.mSecret = pSecret;
	this.mSubmitURL = pSubmitURL;

	final SharedPreferences simplePreferences = SimplePreferences.getInstance(pContext);
	final int playerID = simplePreferences.getInt(PREFERENCES_LEVELSTATSDBCONNECTOR_PLAYERID_ID, -1);
	if(playerID != -1) {
		this.mPlayerID = playerID;
	} else {
		this.mPlayerID = MathUtils.random(1000000000, Integer.MAX_VALUE);
		SimplePreferences.getEditorInstance(pContext).putInt(PREFERENCES_LEVELSTATSDBCONNECTOR_PLAYERID_ID, this.mPlayerID).commit();
	}
}
 
开发者ID:peterchaula,项目名称:ClassicF1,代码行数:14,代码来源:LevelStatsDBConnector.java

示例11: applySceneRotation

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
private void applySceneRotation(final TouchEvent pCameraSceneTouchEvent) {
	final float rotation = this.mRotation;

	if (rotation != 0) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();

		MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, rotation, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!

		pCameraSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
开发者ID:mediamonks,项目名称:tilt-game-android,代码行数:13,代码来源:Camera.java

示例12: getRandomValueC

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
protected float getRandomValueC() {
	if (this.mMinValueC == this.mMaxValueC) {
		return this.mMaxValueC;
	} else {
		return MathUtils.random(this.mMinValueC, this.mMaxValueC);
	}
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:8,代码来源:BaseTripleValueParticleInitializer.java

示例13: updateControlKnob

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
private void updateControlKnob(final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
	final Sprite controlBase = this.mControlBase;

	final float relativeX = (MathUtils.bringToBounds(0, controlBase.getWidth(), pTouchAreaLocalX) / controlBase.getWidth()) - 0.5f;
	final float relativeY = (MathUtils.bringToBounds(0, controlBase.getHeight(), pTouchAreaLocalY) / controlBase.getHeight()) - 0.5f;

	this.onUpdateControlKnob(relativeX, relativeY);
}
 
开发者ID:mediamonks,项目名称:tilt-game-android,代码行数:9,代码来源:BaseOnScreenControl.java

示例14: updateControlKnob

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
private void updateControlKnob(final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
	final Sprite controlBase = this.mControlBase;

	final float relativeX = MathUtils.bringToBounds(0, controlBase.getWidth(), pTouchAreaLocalX) / controlBase.getWidth() - 0.5f;
	final float relativeY = MathUtils.bringToBounds(0, controlBase.getHeight(), pTouchAreaLocalY) / controlBase.getHeight() - 0.5f;

	this.onUpdateControlKnob(relativeX, relativeY);
}
 
开发者ID:peterchaula,项目名称:ClassicF1,代码行数:9,代码来源:BaseOnScreenControl.java

示例15: applySceneToCameraSceneOffset

import org.andengine.util.math.MathUtils; //导入依赖的package包/类
@Override
protected void applySceneToCameraSceneOffset(final TouchEvent pSceneTouchEvent) {
	final float zoomFactor = this.mZoomFactor;
	if (zoomFactor != 1) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.scaleAroundCenter(Camera.VERTICES_TMP, zoomFactor, zoomFactor, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}

	super.applySceneToCameraSceneOffset(pSceneTouchEvent);
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:15,代码来源:ZoomCamera.java


注:本文中的org.andengine.util.math.MathUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。