Model and view matrix are often combined into the modelview matrix.
Since you are saying your near plane is at -1 I’m guessing you want normalized device coordinates?[/QUOTE]
Right now I am doing partially what you say. I go from the object space down to the window space (or as you call it, pixel), then from there up to the camera space by setting the window depth window.z equal to 0, that is the near plane.
Note that to get the camera space from the unProject I just pass in as modelview matrix an identity matrix “new Mat4(1f)”:
public Vec3 getCameraSpacePositionOnNearPlane(Vec2i mousePoint) {
int[] viewport = new int[]{0, 0, glViewer.getGlWindow().getWidth(), glViewer.getGlWindow().getHeight()};
Vec3 window = new Vec3();
window.x = mousePoint.x;
window.y = viewport[3] - mousePoint.y - 1;
window.z = 0;
return Jglm.unProject(window, new Mat4(1f), glViewer.getVehicleCameraToClipMatrix(), new Vec4(viewport));
}
Is there a better way (more efficient) to get it without going down to the window space and come back to the camera one?
The ‘direct’ approach if you will would be to apply the modelview matrix to get a position in eye space. There the camera is at the origin looking along the negative z axis, the near plane is located at z coordinate -near, and parallel to the camera xy plane. What you are looking for is the intersection of the ray from the origin to the eye space position with that plane. You can find it by scaling the vector such that it’s z component is -near.
I doubt it would be a big difference in performance (unless you do this for a very large number of points each frame) and which way is easier to understand is perhaps also a matter of taste