I made a simple OpenGL program but I can figure out why the camera is not working, here it's a little fragment of the Camera class:
public Matrix4f getView() { // initializes the view matrix
return new Matrix4f().lookAt(
new Vector3f(0f, 0f, 1f), // camera position at 0,0,1
new Vector3f(0f, 0f, 0f), // camera target at 0,0,0
new Vector3f(0f, 1f, 0f)); // up axis set to "worldUp" (0,1,0)
}
public Matrix4f getProjection() {
return new Matrix4f().perspective(
(float) Math.toRadians(fieldOfView), // the fov has a value between 0f and 180f, by default I set it to 90°
viewportAspectRatio, // the aspect ratio is equal to 1024 / 960 (screen height / screen width)... even if I've not understood what is it...
0.1f, 1000f); // I've not really understood what near and far planes are...
}
public Matrix4f getMatrix() { // with this function I obtain the final camera matrix
return getView().mul(getProjection());
}
And it's how I handle the camera Matrix in GLSL, created using camera.getMatrix()
:
gl_Position = camera * model * vec4(position, 1.0);
Without the camera all is fine: here's the program running using gl_Position = model * vec4(position, 1.0);
:
(Yeah, it's a cube)
But using the camera in the way I showed you before, increasing the FOV, I get this:
Could anyone look at my code and tell me where I'm wrong? I would be really happy... D:
getMatrix
to your answer and I'll compare them to my DX RH methods. \$\endgroup\$