This topic is now archived and is closed to further replies.

Getting the 3D coord from 2D coord at specified Z

This topic is 5146 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello members, I have a little problem. I want to draw a 3D object at a specified window position. So I convert the 2D point into a 3D point using gluUnproject. That works fine, except for one thing: The Z coord of my new 3D point is not the same as the Z coord that I pass as input. This results in the behaviour that I can''t control the zoom of the 3D object that I want to draw. The 3D object is smaller (or bigger) than I would expect. Is there any way how to compute a 3D point from a 2D point with a specified Z coordinate? Thanks for help, Lyve

Share this post

Link to post
Share on other sites
one possibility is to find the point with the specified z coordinate on the line from the camera c to the unprojected point p:

a = point on line
a = c + t*(p - c)

now set the z-coordinate to your desired z=z0:

a.z = c.z + t*(p.z - c.z) = z0

you get for the parameter t:

t = (z0-c.z)/(p.z - c.z)

with this value of t you can calculate the point a with a.z = z0.

Share this post

Link to post
Share on other sites