public Side rotate(Side side) { Side result = side; result = result.rollClockwise(roll.getIncrements()); result = result.pitchClockwise(pitch.getIncrements()); result = result.yawClockwise(yaw.getIncrements()); return result; }
protected int relChunkIndex(int x, int y, int z) { return TeraMath.calculate3DArrayIndex(ChunkMath.calcChunkPosX(x, chunkPower.x) + offset.x, ChunkMath.calcChunkPosY(y, chunkPower.y) + offset.y, ChunkMath.calcChunkPosZ(z, chunkPower.z) + offset.z, chunkRegion.size()); }
/** * Transform this AABB into a new AABB with the given rotation, offset and scale. * * @param rotation The rotation from the current AABB to the new AABB. * @param offset The offset between the current AABB and the new AABB. * @param scale The scale of the new AABB with respect to the old AABB. * @return The new transformed AABB. */ public AABB transform(Quat4f rotation, Vector3f offset, float scale) { Transform transform = new Transform(offset, rotation, scale); return transform(transform); }
static Region3i getChunkRegionAbove(Vector3f location) { Vector3i charecterPos = new Vector3i(location); Vector3i chunkAboveCharacter = ChunkMath.calcChunkPos(charecterPos); chunkAboveCharacter.addY(1); Vector3i chunkRelativePos = ChunkMath.calcBlockPos(charecterPos); Vector3i characterChunkOriginPos = new Vector3i(charecterPos); characterChunkOriginPos.sub(chunkRelativePos); Vector3i chunkAboveOrigin = new Vector3i(characterChunkOriginPos); chunkAboveOrigin.addY(ChunkConstants.CHUNK_SIZE.getY()); return ChunkConstants.CHUNK_REGION.move(chunkAboveOrigin); }
public void setChunkSize(Vector3i chunkSize) { this.chunkFilterSize = new Vector3i(TeraMath.ceilPowerOfTwo(chunkSize.x) - 1, TeraMath.ceilPowerOfTwo(chunkSize.y) - 1, TeraMath.ceilPowerOfTwo(chunkSize.z) - 1); this.chunkPower = new Vector3i(TeraMath.sizeOfPower(chunkSize.x), TeraMath.sizeOfPower(chunkSize.y), TeraMath.sizeOfPower(chunkSize.z)); Vector3i blockMin = new Vector3i(); blockMin.sub(offset); blockMin.mul(chunkSize.x, chunkSize.y, chunkSize.z); Vector3i blockSize = chunkRegion.size(); blockSize.mul(chunkSize.x, chunkSize.y, chunkSize.z); this.blockRegion = Region3i.createFromMinAndSize(blockMin, blockSize); }
public static Region3i getChunkRegionAroundWorldPos(Vector3i pos, int extent) { Vector3i minPos = new Vector3i(-extent, -extent, -extent); minPos.add(pos); Vector3i maxPos = new Vector3i(extent, extent, extent); maxPos.add(pos); Vector3i minChunk = calcChunkPos(minPos); Vector3i maxChunk = calcChunkPos(maxPos); return Region3i.createFromMinMax(minChunk, maxChunk); }
@Test public void testTwoRangesOverlapping() { IntegerRange range = new IntegerRange(); range.addNumbers(1, 4); range.addNumbers(3, 6); validateRange(range, 1, 2, 3, 4, 5, 6); }
public Quat4f getQuat4f() { Quat4f rotation = new Quat4f(yaw.getRadians(), pitch.getRadians(), roll.getRadians()); rotation.normalize(); return rotation; }
/** * The method tells the chunk mesh update manager where the camera is, so that is able to prioritize chunks near the * camera. It stores the values in volatile variables so that the change is visible to the chunk updating threads * immediately. */ public void setCameraPosition(Vector3f cameraPosition) { Vector3i chunkPos = ChunkMath.calcChunkPos(cameraPosition); cameraChunkPosX = chunkPos.x; cameraChunkPosY = chunkPos.y; cameraChunkPosZ = chunkPos.z; }
/** * Gets the index of the chunk in {@link #chunks} * * @param blockPos The position of the block in world coordinates * @return The index of the chunk in the array */ private int chunkIndexOf(Vector3i blockPos) { return ChunkMath.calcChunkPosX(blockPos.x, ChunkConstants.POWER_X) - topLeft.x + 3 * (ChunkMath.calcChunkPosY(blockPos.y, ChunkConstants.POWER_Y) - topLeft.y + 3 * (ChunkMath.calcChunkPosZ(blockPos.z, ChunkConstants.POWER_Z) - topLeft.z)); }
@Override public void setDirtyAround(Vector3i blockPos) { for (Vector3i pos : ChunkMath.getChunkRegionAroundWorldPos(blockPos, 1)) { chunks[pos.x + offset.x + chunkRegion.size().x * (pos.z + offset.z)].setDirty(true); } }
SubtractiveIterator(Region3i other) { this.other = other; innerIterator = iterator(); updateNext(); }
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 int packColor(float r, float g, float b, float a) { int iR = (int) (TeraMath.clamp(r, 0.0f, 1.0f) * 255.0f); int iG = (int) (TeraMath.clamp(g, 0.0f, 1.0f) * 255.0f); int iB = (int) (TeraMath.clamp(b, 0.0f, 1.0f) * 255.0f); int iA = (int) (TeraMath.clamp(a, 0.0f, 1.0f) * 255.0f); return iA << 24 | iB << 16 | iG << 8 | iR; } }
/** * Transform this AABB into a new AABB with the given rotation, offset and scale as represented by the {@link Transform}. * * @param transform The {@link Transform} representing the offset, rotation, and scale transformation from this AABB to the new AABB. * @return the new transformed AABB. */ public AABB transform(Transform transform) { return transform(transform, DEFAULT_MARGIN); }
/** * @param other * @return An iterator over the positions in this region that aren't in other */ public Iterator<Vector3i> subtract(Region3i other) { return new SubtractiveIterator(other); }
@Test public void testTwoRangesAtTheMaxInt() { IntegerRange range = new IntegerRange(); range.addNumbers(Integer.MAX_VALUE - 3, Integer.MAX_VALUE); range.addNumbers(Integer.MAX_VALUE - 1, Integer.MAX_VALUE); validateRange(range, Integer.MAX_VALUE - 3, Integer.MAX_VALUE - 2, Integer.MAX_VALUE - 1, Integer.MAX_VALUE); }
@Test public void testTwoRangesOneWithinAnother() { IntegerRange range = new IntegerRange(); range.addNumbers(1, 6); range.addNumbers(3, 5); validateRange(range, 1, 2, 3, 4, 5, 6); }
@Test public void testSimpleRange() { IntegerRange range = new IntegerRange(); range.addNumbers(1, 3); validateRange(range, 1, 2, 3); }