-
Hey there ! I know there is plugin which allows to do that but it only works with meshes and I'd need to interact with collision boxes that may be outside meshes. Here is the setup that I got, I took most of the code from 3D scene example.
How would I cast the ray so that it hits an object under the mouse ? I know that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I use a ray starting from the screen, which is at Z=1 in screen space, pointing towards the infinite far plane at Z=0. To do this, with You could also just compute a ray from the camera's origin through the point on the screen for perspective projections, but that won't work for orthographic projections. |
Beta Was this translation helpful? Give feedback.
I use a ray starting from the screen, which is at Z=1 in screen space, pointing towards the infinite far plane at Z=0.
To do this, with
Vec2
normalized device coordinatesndc
, calculate the starting point withndc.extend(1.)
towards another point atndc.extend(0.5)
(halfway to infinity, hah), and useprojection_matrix.inverse().project_point3(...)
to take them from NDC space to camera space, and apply the camera transform to take them to world space.You could also just compute a ray from the camera's origin through the point on the screen for perspective projections, but that won't work for orthographic projections.