Jump to content
  • Advertisement
Sign in to follow this  
tirengarfio

OpenGL Returning from the Window Coordinates to Object Coordinates

This topic is 4353 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

Hi to all, First of all i wanted to see if the stages for transforming coordinates works. So i have used the coordinate (10, 10, 10) this way: First, I have converted the Object Coordinates to Eye Coordinates with the MODELVIEW matrix:
[ xe ]     [ 3  0  0  10 ] [10]     [ 40 ]
[ ye ]  =  [ 0  3  0   6 ] [10]  =  [ 36 ]
[ ze ]     [ 0  0  3   0 ] [10]     [ 30 ]
[ we ]     [ 0  0  0   1 ] [ 1]     [  1 ]
Then, with the PROJECTION matrix, I find the Clip Coordinates, that are the same as the Normalized Device Coordinates
[ xd ]    [ 0.010  0.000  0.000  0.000 ] [ 40 ]     [ 0.40 ]
[ yd ] =  [ 0.000  0.010  0.000  0.000 ] [ 36 ]  =  [ 0.36 ]
[ zd ]    [ 0.000  0.000  0.005  0.000 ] [ 30 ]     [ 0.15 ]
[ wc ]    [ 0.000  0.000  0.000  1.000 ] [  1 ]     [   1  ]
And finally, I get the Window Coordinates with this relation:
[ xw ]     [     (px/2)xd + ox      ] 
[ yw ]  =  [     (py/2]yd + oy      ]
[ zw ]     [ (f-n)/2]zd + (n + f)/2 ]
 
px=200
py=200
ox=0
ox=0
n=200
f=-200

[ xw ]      [       100 * 0.40         ]      [  40 ]
[ yw ]  =   [       100 * 0.36         ]  =   [  36 ]
[ zw ]      [   ((-400)/2)*0.15 + 0/2  ]      [ -30 ]
It works ok, but, what is zw (-30)? Now, i would like to find an Object Coordinate from a Window Coordinate, but, how can i find it if i dont know zw? Or in other words, What is the winz value in the gluUnproject function? [Edited by - tirengarfio on September 20, 2006 10:20:35 AM]

Share this post


Link to post
Share on other sites
Advertisement
I think i have found the answer here:

http://nehe.gamedev.net/data/articles/article.asp?article=13


Anyway, lets imagine I have a cube drawn in my OGL space but in the window it is showed as a square because i dont rotate it.

how can the program know if the upper-right corner of the "squere" belongs to the vertex of the frontal face of the cube or the vertex of the back of the cube?

[Edited by - tirengarfio on September 18, 2006 1:41:29 PM]

Share this post


Link to post
Share on other sites
Quote:

Now, i would like to find a Object Coordinate from a Window Coordinate, but, how can i find it if i dont know zw?


You don't. You need zw. It's usually the depth of the pixel (NDC space, the range depends on the API / projection matrix). If you don't have it, depending on what you are back-transforming for, you can make it up.

Incidentially, the projection matrix your calculation uses is atypical (it's not what gluPerspective() would generate), and you are missing the division by w, presumably because your w has worked out to be one so its a no-op. In general, clip space coordinates and normalized-device coordinates are not the same.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!