Getting the 3D coord from 2D coord at specified Z
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
_____________________________________http://www.winmaze.de, a 3D shoot em up in OpenGL, nice graphics, multiplayer, chat rooms, a nice community, worth visiting! ;)http://www.spheretris.tk, an upcoming Tetrisphere clone for windows, a 3D tetris game on a sphere with powerful graphics for Geforce FX and similar graphics cards.
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.
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.
Visit our homepage: www.rarebyte.de.stGA
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement