Reputation: 1965
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?
Upvotes: 1
Views: 716
Reputation: 1965
For future users:
QVector4D uv(xy.x() / m_w * 2 - 1, -(xy.y() / m_h * 2 - 1),1,1);
QVector3D sv = m_proj.inverted() * uv;
where sv
is a point on the camera screen
Upvotes: 1