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);
}
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;
}
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;
}
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;
}