Search in sources :

Example 16 with Vec3

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;
}
Also used : Vec3(org.asassecreations.engine.math.vector.Vec3)

Example 17 with Vec3

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));
            }
        }
    }
}
Also used : BlockModeled(org.asassecreations.voxelgame.world.block.BlockModeled) Vec3(org.asassecreations.engine.math.vector.Vec3) Vector3f(org.lwjgl.util.vector.Vector3f) ArrayList(java.util.ArrayList)

Aggregations

Vec3 (org.asassecreations.engine.math.vector.Vec3)17 Mat4 (org.asassecreations.engine.math.vector.Mat4)4 Vec2 (org.asassecreations.engine.math.vector.Vec2)3 Vec4 (org.asassecreations.engine.math.vector.Vec4)3 ArrayList (java.util.ArrayList)2 Color (org.asassecreations.engine.render.Color)2 BlockModeled (org.asassecreations.voxelgame.world.block.BlockModeled)2 Chunk (org.asassecreations.voxelgame.world.chunk.Chunk)2 Vector3f (org.lwjgl.util.vector.Vector3f)2 List (java.util.List)1 ChunkSaveQueue (org.asassecreations.voxelgame.world.chunk.queue.ChunkSaveQueue)1