I have some code to calculate the view matrix, following code from LearnOpenGL. I'm only really using LWJGL and JOML.
This is my method to get the view matrix:
public Matrix4f getViewMatrix() {
Matrix4f viewMatrix = new Matrix4f();
viewMatrix = viewMatrix.identity();
/*direction = new Vector3f(Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)), Math.sin(Math.toRadians(pitch)), Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)));
direction.normalize();
First do the rotation so camera rotates over its position
viewMatrix.rotate((float)pitch, new Vector3f(1, 0, 0))
.rotate((float)yaw, new Vector3f(0, 1, 0));
Then do the translation*/
viewMatrix.translate(-position.x, -position.y, -position.z);
updateCameraVectors();
viewMatrix.lookAt(position, position.add(cameraFront) , cameraUp, viewMatrix);
return viewMatrix;
}
And my function to update the vectors
public void updateCameraVectors() {
cameraFront.x = Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch));
cameraFront.y = Math.sin(Math.toRadians(pitch));
cameraFront.z = Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch));
cameraFront.normalize();
//cross product of camerafront and 0,1,0 stored in cameraRight
cameraFront.cross(new Vector3f(0, 1, 0), cameraRight);
cameraRight.normalize();
//gets the cross product of camera right with camera front and stores it in cameraUp
cameraRight.cross(cameraFront, cameraUp);
cameraUp.normalize();
}
The problem I'm having is that when I do viewMatrix.lookAt(position, position.add(cameraFront) , cameraUp, viewMatrix), it's equal to NaN. I can't really tell what I'm doing wrong, any help would be appreciated.