#### Archived

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

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

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

## 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 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.

1. 1
2. 2
Rutin
29
3. 3
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633647
• Total Posts
3013108
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!