public static Direction inDirection(int x, int y, int z) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(y)) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) { return (x > 0) ? LEFT : RIGHT; } } else if (TeraMath.fastAbs(y) > TeraMath.fastAbs(z)) { return (y > 0) ? UP : DOWN; } return (z > 0) ? FORWARD : BACKWARD; }
public static Side inDirection(int x, int y, int z) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(y)) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) { return (x > 0) ? RIGHT : LEFT; } } else if (TeraMath.fastAbs(y) > TeraMath.fastAbs(z)) { return (y > 0) ? TOP : BOTTOM; } return (z > 0) ? BACK : FRONT; }
/** * Determines which horizontal direction the player is facing * * @param x right/left * @param z back/front * @return Side enum with the appropriate direction */ public static Direction inHorizontalDirection(float x, float z) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) { return (x > 0) ? LEFT : RIGHT; } return (z > 0) ? FORWARD : BACKWARD; }
/** * Determines which horizontal direction the player is facing * * @param x right/left * @param z back/front * @return Side enum with the appropriate direction */ public static Side inHorizontalDirection(double x, double z) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) { return (x > 0) ? RIGHT : LEFT; } return (z > 0) ? BACK : FRONT; }
/** * Determines which direction the player is facing * * @param x right/left * @param y top/bottom * @param z back/front * @return Side enum with the appropriate direction */ public static Direction inDirection(float x, float y, float z) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(y)) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) { return (x > 0) ? LEFT : RIGHT; } } else if (TeraMath.fastAbs(y) > TeraMath.fastAbs(z)) { return (y > 0) ? UP : DOWN; } return (z > 0) ? FORWARD : BACKWARD; }
/** * Determines which direction the player is facing * * @param x right/left * @param y top/bottom * @param z back/front * @return Side enum with the appropriate direction */ public static Side inDirection(double x, double y, double z) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(y)) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) { return (x > 0) ? RIGHT : LEFT; } } else if (TeraMath.fastAbs(y) > TeraMath.fastAbs(z)) { return (y > 0) ? TOP : BOTTOM; } return (z > 0) ? BACK : FRONT; }
@Override public Vector3i next() { Vector3i result = new Vector3i(origin.x + x, origin.y + y, origin.z + z); if (z < 0) { z *= -1; } else if (y < 0) { y *= -1; z = -(level - TeraMath.fastAbs(x) - TeraMath.fastAbs(y)); } else { y = -y + 1; if (y > 0) { if (++x <= level) { y = TeraMath.fastAbs(x) - level; z = 0; } else { level++; x = -level; y = 0; z = 0; } } else { z = -(level - TeraMath.fastAbs(x) - TeraMath.fastAbs(y)); } } return result; }
private static void assertEqualParticles( final ParticlePool expected, final int expIndex, final ParticlePool actual, final int actIndex, final float epsilon ) { final int expIndex3 = expIndex * 3; final int expIndex4 = expIndex * 4; final int actIndex3 = actIndex * 3; final int actIndex4 = actIndex * 4; assertTrue(TeraMath.fastAbs(expected.energy[expIndex] - actual.energy[actIndex]) < epsilon); for (int i = 0; i < 3; i++) { assertTrue(TeraMath.fastAbs(expected.position[expIndex3 + i] - actual.position[actIndex3 + i]) < epsilon); assertTrue(TeraMath.fastAbs(expected.previousPosition[expIndex3 + i] - actual.previousPosition[actIndex3 + i]) < epsilon); assertTrue(TeraMath.fastAbs(expected.velocity[expIndex3 + i] - actual.velocity[actIndex3 + i]) < epsilon); assertTrue(TeraMath.fastAbs(expected.scale[expIndex3 + i] - actual.scale[actIndex3 + i]) < epsilon); } for (int i = 0; i < 4; i++) { assertTrue(TeraMath.fastAbs(expected.color[expIndex4 + i] - actual.color[actIndex4 + i]) < epsilon); } }
private void addTiles(MeshBuilder builder, Rect2i drawRegion, Rect2f subDrawRegion, Vector2i textureSize, Rect2f subTextureRegion) { int tileW = textureSize.x; int tileH = textureSize.y; int horizTiles = TeraMath.fastAbs((drawRegion.width() - 1) / tileW) + 1; int vertTiles = TeraMath.fastAbs((drawRegion.height() - 1) / tileH) + 1; int offsetX = (drawRegion.width() - horizTiles * tileW) / 2; int offsetY = (drawRegion.height() - vertTiles * tileH) / 2; for (int tileY = 0; tileY < vertTiles; tileY++) { for (int tileX = 0; tileX < horizTiles; tileX++) { int left = offsetX + tileW * tileX; int top = offsetY + tileH * tileY; float vertLeft = subDrawRegion.minX() + subDrawRegion.width() * Math.max((float) left / drawRegion.width(), 0); float vertTop = subDrawRegion.minY() + subDrawRegion.height() * Math.max((float) top / drawRegion.height(), 0); float vertRight = subDrawRegion.minX() + subDrawRegion.width() * Math.min((float) (left + tileW) / drawRegion.width(), 1); float vertBottom = subDrawRegion.minY() + subDrawRegion.height() * Math.min((float) (top + tileH) / drawRegion.height(), 1); float texCoordLeft = subTextureRegion.minX() + subTextureRegion.width() * (Math.max(left, 0) - left) / tileW; float texCoordTop = subTextureRegion.minY() + subTextureRegion.height() * (Math.max(top, 0) - top) / tileH; float texCoordRight = subTextureRegion.minX() + subTextureRegion.width() * (Math.min(left + tileW, drawRegion.width()) - left) / tileW; float texCoordBottom = subTextureRegion.minY() + subTextureRegion.height() * (Math.min(top + tileH, drawRegion.height()) - top) / tileH; addRectPoly(builder, vertLeft, vertTop, vertRight, vertBottom, texCoordLeft, texCoordTop, texCoordRight, texCoordBottom); } } }