I would like to get the ray out of my current view.
I generate the following projection matrix:
QMatrix4x4 m_proj;
...
m_proj.perspective(camFOV, ar, camZnear, camZfar);
when I apply a point in 3d I get the normalized coordinates (range of [-1 1]).
If I get a click event, I normalize the coordinates to [-1 1] and multiply it by when m_proj.inverted()
, but I get weird results (a number greater than 1).
In other words, how do I transform a click in the screen (x,y) coordinates to a ray in the camera coordinate system?
EDIT:
This is similar question to Qt OpenGL- How to get the object based on the mouse click But how do I do it with modern opengl?
(v.x, v.y, v.z) / v.w
– Rabbid76QMatrix4x4::inverted()
provides the correct result. My "stone-old" red book mentions inverse projection matrix explicitly. (I remember roughly having read once that projection matrix is actually not invertable.) However, I found Inverse Projection on github. You may use this algorithm to check the invertedQMatrix4x4
. – Scheff's CatQMatrix4x4::perspective()
.) However, it couldn't hurt to use/check theinvertible
argument ofQMatrix4x4::inverted()
(just to be sure). – Scheff's Catz_near
parameter – Spektre