PDA

View Full Version : Returning from the Window Coordinates to Object Coordinates

tirengarfio
09-18-2006, 09:28 AM
Hi to all,

First of all i wanted to see if the stages (http://scr.csc.noctrl.edu/courses/csc425/Resources/transform.gif) for transforming coordinates works. So i have used the coordinate (10, 10, 10) this way:

First, I have convert the Object Coordinates to Eye Coordinates:

[ 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, 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 a 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 (http://www.mevis.de/opengl/gluUnProject.html) function?

tirengarfio
09-18-2006, 11:48 AM
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?

k_szczech
09-19-2006, 06:23 AM
how can the program know if the upper-right corner of the "squere" belongs to the vertex of the frontal face of the cubeBy comparing coordinates of unprojected vertex and each of the cube vertices.
Of course you must assume that these coordinates will not be ideally the same - so you can just search for cube vertex that is closest to unprojected vertex.

On the other hand, I'm beginning to think you're trying to implement something that could be done in much better way.

tirengarfio
09-19-2006, 09:31 AM
Thanks k!

Originally posted by k_szczech:
[QUOTE]
On the other hand, I'm beginning to think you're trying to implement something that could be done in much better way. I just want to set 3 vertices of a cube to three 2d positions (of an OpenGL window, of course..) i choose.

This (http://nehe.gamedev.net/data/articles/article.asp?article=13) can help me, i suppose... any idea?