convert 3d to 2d #191
-
|
How can I convert a 3D position into a 2D screen position so that I can determine which (x, y) screen coordinates correspond to a 3D object with (x, y, z) coordinates, and check whether that object overlaps with the mouse position? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Generally speaking, you would multiply the 3D point by the modelview and projection matrices and then scale that value to the viewport size. pseudocode: You can find the matrices and viewport in the vsg::Camera object. |
Beta Was this translation helpful? Give feedback.
-
|
Following up on gwaldron. 1.) CPU version. This can also be implemented using Cuda or Compute Shaders but takes some work to play nice on the GPU. This is somewhat inefficient if you don't have a spatial acceleration structure (something to cull unrequired objects, say a frustum test around a bounding primitive type): ` 2.) Is hardware selection using rasterization. Bgfx has a good starter example. This is very useful if you need to sample many picks or you need simple picks against skinned or deformed geometry. 3.) Compute or using hardware raytracing. |
Beta Was this translation helpful? Give feedback.
Generally speaking, you would multiply the 3D point by the modelview and projection matrices and then scale that value to the viewport size.
pseudocode:
You can find the matrices and viewport in the vsg::Camera object.