# OpenGL Returning from the Window Coordinates to Object Coordinates

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

## 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 on other sites
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 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 on other sites
Quote:
 Original post by jpetrieYou don't. You need zw.

So I need or not Zw? It is not enough clear, I think..:)

##### Share on other sites
someone knows anything?

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633294
• Total Posts
3011242
• ### Who's Online (See full list)

There are no registered users currently online

×