How to map 3D object coordinates to 2D screen?

How to map 3D object coordinates to 2D screen?

You can do this simply by converting [-1,+1] to [0,+1] (add 1, multiply by 0.5) then scale appropriately (multiply by width or height). This can be put in matrix form if that’s easier for you. I notice that you aren’t using homogenous coordinates for your transformation.

How to get the correct 2D coordinates in Ogre?

Not sure if Ogre does it implicitely, but using a 4×4 matrix to transform a 3D point to get the correct 2D coordinates (as it would be rendered with the same matrix), requires a transition from homogeneous coordinates by dividing the result by w.

How to calculate 3D world coordinates in Unity?

I’d like to tap anywhere on the screen and find the proper position in 3d space that is on the same z-position as my player avatar but has the proper x, y coordinates. I’m trying to calculate the distance along the x,y axis between the spot tapped by the finger and the avatar. Assuming both are on the same z location.

How to get a 2D position in OpenGL?

I’m trying to get a 2D screen position so I unproject a point from 3D into 2D screen coordinates by that following function:

How to convert a 3D object to a 2D point?

Just in the last toScreenSpace operation I convert the 3D point into a 2D point. Because I previously converted the vertex into normal devices space, zero is in the center of the screen and values range between +1 and -1. Simply dividing by z gives you the depth.

Are there negative values for 3D world coordinates?

The 3D world coordinates can contain negative values aswell ranging from -4000 to 4000. I have read a few conversion articles on Wikipedia and a couple of SO threads but they either didn’t fit my needs or they were too complex for my limited math knowledge.

How to convert 3D object coordinates to homogenous coordinates?

Converting to homogenous coordinates is next as RobCurr pointed out (my Vector3 implementation has a w component) and finally to clip and screen space. The perspective projection done in toClipSpace using a perspective transform matrix does not give me the screencoordinates yet and still stores the depth of each vertex in the z component.