use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.
the class BlockRaycast method placeCast.
public static final Vec3 placeCast() {
int numberOfIterations = 0;
final Vec3 currentPosition = new Vec3(GameCamera.position);
final Vec3 currentDirection = new Vec3(ray());
currentDirection.normalise();
currentDirection.scale(CAST_SIZE);
Vec3 lastIntersection = new Vec3(currentDirection);
Vec3 blockIntersection = null;
while (blockIntersection == null) {
if ((int) currentPosition.x != (int) lastIntersection.x || (int) currentPosition.y != (int) lastIntersection.y || (int) currentPosition.z != (int) lastIntersection.z)
lastIntersection = new Vec3(currentPosition);
currentPosition.x += currentDirection.x;
currentPosition.y += currentDirection.y;
currentPosition.z += currentDirection.z;
final BlockModeled block = Chunk.getBlock(currentPosition.x, currentPosition.y, currentPosition.z);
if (block != null) {
blockIntersection = new Vec3(currentPosition.x, currentPosition.y, currentPosition.z);
break;
}
numberOfIterations++;
if (numberOfIterations >= MAX_ITERATIONS)
return null;
}
return lastIntersection;
}
use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.
the class ChunkSystem method checkRightClick.
public static final void checkRightClick() {
final Vec3 block = BlockRaycast.placeCast();
if (block != null) {
final Chunk chunk = Chunk.getChunk((int) Math.floor(block.x / Chunk.H_SIZE), (int) Math.floor(block.z / Chunk.H_SIZE));
if (chunk != null) {
final Vector3f blockToSet = Chunk.getBlockCoordinates(block.x, block.y, block.z);
chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z] = new BlockModeled(BlockPlacement.getSelection());
chunk.modified.put(new Vector3f((int) blockToSet.x, (int) blockToSet.y, (int) blockToSet.z), new ArrayList<>(Block.BLOCKS.values()).indexOf(BlockPlacement.getSelection()));
{
final int cx = chunk.x;
final int cz = chunk.z;
addToQueues(chunk);
addToQueues(Chunk.getChunk(cx - 1, cz));
addToQueues(Chunk.getChunk(cx + 1, cz));
addToQueues(Chunk.getChunk(cx, cz - 1));
addToQueues(Chunk.getChunk(cx, cz + 1));
}
}
}
}
Aggregations