View Full Version : which z-values for glUnProject()?

10-14-2003, 03:38 AM

i hope someone can help me. this problem is worrying me for more than a week. i know there are a lot of posts about this subject and i really tried to find the answer to my problem but i didn't.

my program shows an object (data from an stl file). now i want to allow the user to zoom the object near and far (mousewheel). ok, this is no problem!

but i would be prefer this: the user clicks somewhere on the object and then the whole object moves in this way: the clicked point is moved to the center of the window. the zooming starts.

i don't know why this doesn't work, i will explain you how i'm trying to solve this.
(picking and selection works, i controlled this with another program)

Please correct me if my way is wrong:

1.) i render the object with the selection mode.
2.) i get the minimum z value from the selectBuf and want to use this z for the glUnProject(), but this is a real big number. i tried to scale it but i don't know how. the value (in GLdouble) has to be between 0.0 ans 1.0, i know. (if i scale with 100000000, i get something like 0.4)
or how can i scale it in another way?

2.) i use glReadPixel() with my mouse coordinates to get the z value, it is always 1.0. also if in the selectBuf the value is different. using glUnProject() with 1.0 returns acceptable values, but the translation doesn't move the point to the center.

2.) if use z=0.0, then i get very small values, almost no translation can be seen.

perhaps someone of you can help me,

thank you so much,


10-14-2003, 11:14 PM
i'm not quite shure, but maybe this could help you: http://nehe.gamedev.net/data/articles/article.asp?article=13
(nehe.gamedev.net article 13)

perhaps i could help you, if you will post or send(by mail) some code.

[This message has been edited by gvm (edited 10-15-2003).]

10-14-2003, 11:59 PM
hi gvm!

thank you for your help!
ok, i got it! sorry for posting here!

i found my solution some minutes before!

i don't delete this post, perhaps i'm not the only one with this beginner problem.

for those who may have the same problem:

i don't have to move my object, i just have to change the modelview matrix, by using
gluLookAt() with the clicked point coordinates (transfered in world coordinates) as new center.

it's really easy, no idea why i was thinking so wrong! for more than a week!?