本文整理汇总了Java中org.andengine.util.math.MathUtils.bringToBounds方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.bringToBounds方法的具体用法?Java MathUtils.bringToBounds怎么用?Java MathUtils.bringToBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.andengine.util.math.MathUtils
的用法示例。
在下文中一共展示了MathUtils.bringToBounds方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: 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);
}
示例3: 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);
}
示例4: onManagedUpdate
import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
@Override
protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) {
final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration);
/* Calculate active control point. */
final int p;
if (percentageDone == 1) {
p = this.mControlSegmentCount;
} else {
p = (int) (percentageDone / this.mControlSegmentCountInverse);
}
/* Retrieve control points. */
final int p0 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p - 1);
final float pX0 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p0];
final float pY0 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p0];
final int p1 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p);
final float pX1 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p1];
final float pY1 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p1];
final int p2 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p + 1);
final float pX2 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p2];
final float pY2 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p2];
final int p3 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p + 2);
final float pX3 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p3];
final float pY3 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p3];
/* Calculate new position. */
final float t = (percentageDone - (p * this.mControlSegmentCountInverse)) / this.mControlSegmentCountInverse;
final float tt = t * t;
final float ttt = tt * t;
/*
* Formula: s * (-ttt + 2tt – t) * P1 + s * (-ttt + tt) * P2 + (2ttt – 3tt + 1) * P2 + s(ttt – 2tt + t) * P3 + (-2ttt + 3tt) * P3 + s * (ttt – tt) * P4
*/
final float s = (1 - this.mCardinalSplineMoveModifierConfig.mTension) / 2;
final float b1 = s * ((-ttt + (2 * tt)) - t); // (s * (-ttt + 2tt – t)) * P1
final float b2 = (s * (-ttt + tt)) + (((2 * ttt) - (3 * tt)) + 1); // (s * (-ttt + tt) + (2ttt – 3tt + 1)) * P2
final float b3 = (s * ((ttt - (2 * tt)) + t)) + ((-2 * ttt) + (3 * tt)); // (s * (ttt – 2tt + t) + (-2ttt + 3tt)) * P3
final float b4 = s * (ttt - tt); // (s * (ttt – tt)) * P4
final float x = ((pX0 * b1) + (pX1 * b2) + (pX2 * b3) + (pX3 * b4));
final float y = ((pY0 * b1) + (pY1 * b2) + (pY2 * b3) + (pY3 * b4));
pEntity.setPosition(x, y);
}
示例5: onManagedUpdate
import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
@Override
protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) {
final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration);
/* Calculate active control point. */
final int p;
if(percentageDone == 1) {
p = this.mControlSegmentCount;
} else {
p = (int) (percentageDone / this.mControlSegmentCountInverse);
}
/* Retrieve control points. */
final int p0 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p - 1);
final float pX0 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p0];
final float pY0 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p0];
final int p1 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p);
final float pX1 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p1];
final float pY1 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p1];
final int p2 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p + 1);
final float pX2 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p2];
final float pY2 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p2];
final int p3 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p + 2);
final float pX3 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p3];
final float pY3 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p3];
/* Calculate new position. */
final float t = (percentageDone - (p * this.mControlSegmentCountInverse)) / this.mControlSegmentCountInverse;
final float tt = t * t;
final float ttt = tt * t;
/*
* Formula: s * (-ttt + 2tt – t) * P1 + s * (-ttt + tt) * P2 + (2ttt – 3tt + 1) * P2 + s(ttt – 2tt + t) * P3 + (-2ttt + 3tt) * P3 + s * (ttt – tt) * P4
*/
final float s = (1 - this.mCardinalSplineMoveModifierConfig.mTension) / 2;
final float b1 = s * ((-ttt + (2 * tt)) - t); // (s * (-ttt + 2tt – t)) * P1
final float b2 = (s * (-ttt + tt)) + (((2 * ttt) - (3 * tt)) + 1); // (s * (-ttt + tt) + (2ttt – 3tt + 1)) * P2
final float b3 = (s * ((ttt - (2 * tt)) + t)) + ((-2 * ttt) + (3 * tt)); // (s * (ttt – 2tt + t) + (-2ttt + 3tt)) * P3
final float b4 = s * (ttt - tt); // (s * (ttt – tt)) * P4
final float x = ((pX0 * b1) + (pX1 * b2) + (pX2 * b3) + (pX3 * b4));
final float y = ((pY0 * b1) + (pY1 * b2) + (pY2 * b3) + (pY3 * b4));
pEntity.setPosition(x, y);
}
示例6: onManagedUpdate
import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
/**
* Game loop
*/
@Override
public void onManagedUpdate(float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
if (_levelController == null) {
return;
}
if (_started) {
// update gravity from phone orientation
EulerAngles eulerAngles = _orientationProvider.getEulerAngles();
// get limited roll & pitch
float roll = MathUtils.bringToBounds(-MAX_ORIENTATION_ANGLE, MAX_ORIENTATION_ANGLE, eulerAngles.getRoll());
float pitch = MathUtils.bringToBounds(-MAX_ORIENTATION_ANGLE, MAX_ORIENTATION_ANGLE, eulerAngles.getPitch());
// correct for screen orientation, different on tablets than on phones
float swap;
switch (_screenRotation) {
case Surface.ROTATION_0:
break;
case Surface.ROTATION_270:
swap = pitch;
pitch = -roll;
roll = swap;
break;
case Surface.ROTATION_180:
pitch = -pitch;
roll = -roll;
break;
case Surface.ROTATION_90:
swap = pitch;
pitch = roll;
roll = -swap;
break;
}
_gravity.set(_radToGravity * roll, _radToGravity * pitch);
_gravity.add(_gravityCorrection);
_physicsWorld.setGravity(_gravity);
checkDestroyBall();
// update ball location, if there's a ball, we're not animating, and the level hasn't been completed
if (_ball != null && !_isAnimating && !_isLevelCompleted) {
_timePassed += pSecondsElapsed;
// update physics world
_physicsWorld.onUpdate(pSecondsElapsed);
// check if the ball needs to be destroyed
checkDestroyBall();
// recheck, since world update may have removed the ball
if (_ball != null && !_isAnimating) {
Vector2 ballPosition = _ball.getPosition();
ballPosition.mul(PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);
_ballSprite.setPosition(ballPosition.x, ballPosition.y);
}
if (_levelDuration > 0) {
updateTimer(pSecondsElapsed);
}
}
}
}