Search in sources :

Example 11 with Vec3

use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.

the class SunRenderer method faceCamera.

private static final Mat4 faceCamera(final Vec3 position, final float scale, final Mat4 viewMatrix) {
    final Mat4 modelMatrix = new Mat4();
    Mat4.translate(position, modelMatrix, modelMatrix);
    modelMatrix.m00 = viewMatrix.m00;
    modelMatrix.m01 = viewMatrix.m10;
    modelMatrix.m02 = viewMatrix.m20;
    modelMatrix.m10 = viewMatrix.m01;
    modelMatrix.m11 = viewMatrix.m11;
    modelMatrix.m12 = viewMatrix.m21;
    modelMatrix.m20 = viewMatrix.m02;
    modelMatrix.m21 = viewMatrix.m12;
    modelMatrix.m22 = viewMatrix.m22;
    Mat4.scale(new Vec3(scale, scale, scale), modelMatrix, modelMatrix);
    final Mat4 modelViewMatrix = Mat4.mul(viewMatrix, modelMatrix, null);
    return modelViewMatrix;
}
Also used : Mat4(org.asassecreations.engine.math.vector.Mat4) Vec3(org.asassecreations.engine.math.vector.Vec3)

Example 12 with Vec3

use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.

the class GameState method tick.

public void tick() {
    ChunkSystem.removeDistantChunks();
    final int cameraChunkX = (int) (GameCamera.position.x / Chunk.H_SIZE);
    final int cameraChunkZ = (int) (GameCamera.position.z / Chunk.H_SIZE);
    ChunkSystem.addNewChunks(cameraChunkX, cameraChunkZ);
    player.tick();
    if (MouseInput.isButtonJustPressed(0))
        ChunkSystem.checkLeftClick(inventory);
    if (MouseInput.isButtonJustPressed(1))
        ChunkSystem.checkRightClick();
    ChunkModelQueue.queue();
    ChunkSaveQueue.queue();
    Time.updateTime(1200);
    final float time = Mathf.sinNormalized(Time.rawTime);
    sun.position.y = -time;
    sun.position.x = Mathf.cosNormalized(Time.rawTime) * .2f;
    sun.position.z = Mathf.cosNormalized(Time.rawTime);
    sun.brightness = Mathf.map(Mathf.max(time, -.4f), 1f, -.4f, 1f, 0f);
    Settings.CURRENT_SKY_COLOR = new Color(ImageBilinearFilter.getColor(AMBIENT, sun.brightness, 0));
    final Color sunColor = new Color(ImageBilinearFilter.getColor(AMBIENT, sun.brightness, 1));
    sun.color = new Vec3(sunColor.getRed(), sunColor.getGreen(), sunColor.getBlue());
    Debugger.chunksLoaded = Chunk.CHUNKS.size();
    Debugger.playerPosition = player.position;
    GameCamera.updateMatrix(Player.sprinting);
    if (autosaveTimer.isComplete()) {
        autosaveTimer.reset();
        for (final Chunk c : Chunk.CHUNKS) new ChunkSaveQueue(c);
        PlayerSave.save(player);
        inventory.save();
        System.out.println("Autosave");
    }
}
Also used : ChunkSaveQueue(org.asassecreations.voxelgame.world.chunk.queue.ChunkSaveQueue) Color(org.asassecreations.engine.render.Color) Vec3(org.asassecreations.engine.math.vector.Vec3) Chunk(org.asassecreations.voxelgame.world.chunk.Chunk)

Example 13 with Vec3

use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.

the class HandRenderer method render.

public static final void render(final Light sun) {
    final float time = Mathf.cos(Timings.globalTime_f);
    final float yBobbing = time / 12f;
    shader.start();
    shader.loadLight(sun);
    shader.loadViewMatrix(GameCamera.view);
    final Mat4 matrix = MatrixCreation.createTransformationMatrix(new Vec3(UserSettings.WALK_OFFSET_HORIZONTAL, UserSettings.WALK_OFFSET_VERTICLE + yBobbing, UserSettings.WALK_OFFSET_DEPTH), new Vec3(10f + time * 5f, -5f, 5f + time * 5f), new Vec3(0.3f, 0.3f, 0.3f));
    shader.loadTransformationMatrix(matrix);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, HandModel.MODEL.vertexCount);
    shader.stop();
}
Also used : Mat4(org.asassecreations.engine.math.vector.Mat4) Vec3(org.asassecreations.engine.math.vector.Vec3)

Example 14 with Vec3

use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.

the class BlockRaycast method ray.

public static Vec3 ray() {
    final Vec2 normalizedDevice = new Vec2(0, 0);
    final Vec4 clipCoords = new Vec4(normalizedDevice.x, normalizedDevice.y, -1f, 1f);
    final Vec4 eyeSpace = eyeSpace(clipCoords, -1);
    final Vec3 direction = worldSpace(eyeSpace);
    return direction;
}
Also used : Vec2(org.asassecreations.engine.math.vector.Vec2) Vec3(org.asassecreations.engine.math.vector.Vec3) Vec4(org.asassecreations.engine.math.vector.Vec4)

Example 15 with Vec3

use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.

the class BlockRaycast method worldSpace.

private static final Vec3 worldSpace(final Vec4 eye) {
    final Mat4 intertedView = Mat4.invert(GameCamera.view, null);
    final Vec4 world = Mat4.transform(intertedView, eye, null);
    final Vec3 ray = new Vec3(world.x, world.y, world.z);
    ray.normalise();
    return ray;
}
Also used : Mat4(org.asassecreations.engine.math.vector.Mat4) Vec3(org.asassecreations.engine.math.vector.Vec3) Vec4(org.asassecreations.engine.math.vector.Vec4)

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