Search in sources :

Example 1 with Vec4

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

the class BlockRaycast method eyeSpace.

private static final Vec4 eyeSpace(final Vec4 clip, final float direction) {
    final Mat4 inverted = Mat4.invert(GameCamera.projection_primary, null);
    final Vec4 eyeCoords = Mat4.transform(inverted, clip, null);
    return new Vec4(eyeCoords.x, eyeCoords.y, direction, 0f);
}
Also used : Mat4(org.asassecreations.engine.math.vector.Mat4) Vec4(org.asassecreations.engine.math.vector.Vec4)

Example 2 with Vec4

use of org.asassecreations.engine.math.vector.Vec4 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 3 with Vec4

use of org.asassecreations.engine.math.vector.Vec4 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)

Example 4 with Vec4

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

the class GameRenderer method get2dPoint.

private static final Vec2 get2dPoint(final Vec3 point3D, final Mat4 viewMatrix, final Mat4 projectionMatrix, final int width, final int height) {
    final Vec4 clipSpacePos = Mat4.transform(projectionMatrix, Mat4.transform(viewMatrix, new Vec4(point3D.x, point3D.y, point3D.z, 1.0f), null), null);
    final Vec3 ndcSpacePos = new Vec3(clipSpacePos.x / clipSpacePos.w, clipSpacePos.y / clipSpacePos.w, clipSpacePos.z / clipSpacePos.w);
    final Vec2 vector = new Vec2(ndcSpacePos.x, ndcSpacePos.y);
    Vec2.add(vector, new Vec2(1, 1), vector);
    vector.x /= 2f;
    vector.y /= 2f;
    return vector;
}
Also used : Vec2(org.asassecreations.engine.math.vector.Vec2) Vec3(org.asassecreations.engine.math.vector.Vec3) Vec4(org.asassecreations.engine.math.vector.Vec4)

Aggregations

Vec4 (org.asassecreations.engine.math.vector.Vec4)4 Vec3 (org.asassecreations.engine.math.vector.Vec3)3 Mat4 (org.asassecreations.engine.math.vector.Mat4)2 Vec2 (org.asassecreations.engine.math.vector.Vec2)2