For some reason my x axis is flipped instead of -x<->x mine goes x<->-x. I have set up a projection matrix.
public class ProjectionMatrix {
private static final float FOV = 70;
private static final float NEAR_PLANE = 0.1f;
private static final float FAR_PLANE = 1000f;
public static Matrix4f create(){
Matrix4f projectionMatrix = new Matrix4f();
float aspectRatio = (float) Window.getWidth() / (float) Window.getHeight();
float frustum_length = FAR_PLANE - NEAR_PLANE;
//x scale
projectionMatrix.m00 = (float) (1f / Math.tan(Math.toRadians(FOV / 2f)));
//y scale
projectionMatrix.m11 = projectionMatrix.m00 * aspectRatio;
projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
projectionMatrix.m23 = -1;
projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);
projectionMatrix.m33 = 0;
return projectionMatrix;
}
}
I think this is right.
I have a view matrix.
public class ViewMatrix {
public static Matrix4f create() {
Matrix4f matrix = new Matrix4f();
matrix.rotate((float) Math.toRadians(Camera.getPitch()), new Vector3f(1, 0, 0));
matrix.rotate((float) Math.toRadians(Camera.getYaw()), new Vector3f(0, 1, 0));
matrix.rotate((float) Math.toRadians(Camera.getRoll()), new Vector3f(0, 0, 1));
Vector3f cameraPos = Game.CAMERA.position().get();
Vector3f negativeCameraPos = new Vector3f(-cameraPos.x, -cameraPos.y, -cameraPos.z);
matrix.translate(negativeCameraPos);
return matrix;
}
}
I think this is right.
and this is how I implement them into the shader vec4 worldPosition = transformationMatrix * vec4(position, 1.0);
gl_Position = projectionMatrix * viewMatrix * worldPosition;
I have no clue why the x-axis flipped. I thought I had a grasp on this but I am having trouble with this.