views:

469

answers:

1

Hey there!

I'd like to map from normalized device coordinates back to viewspace.

The other way arround works like this:

viewspace -> clip space : multiply the homogeneous coordinates by the projection matrix

clip space -> normalized device coordinates: divide the (x,y,z,w) by w

now in normalized device coordinates all coordinates which were within the view frustum fall into the cube x,y,z € [-1,1] and w=1

Now i'd like to transform some points on the boundary of that cube back into view coordinates. The projection matrix is nonsingular, so I can use the inverse to get from clipsace to viewspace. but i don't know how to get from normalized device space to clipspace, since i don't know how to calculate the 'w' i need to multiply the other coordinates with.

can someone help me with that? thanks!

A: 

Unless you actually want to recover your clip space values for some reason you don't need to calculate the W. Multiply your NDC point by the inverse of the projection matrix and then divide by W to get back to view space.

Andrew Khosravian
thank youAre you sure that i simply need to divide by W?I'm confused because of this page:http://www.opengl.org/wiki/GluProject_and_gluUnProject_codei'm particularily confused by the last four lines out[3]=1.0/out[3]; objectCoordinate[0]=out[0]*out[3]; objectCoordinate[1]=out[1]*out[3]; objectCoordinate[2]=out[2]*out[3];they divide x,y,z by the W value - BUT they replace the W value by 1/W - so the returned homogeneous coordinates do not have 1 in the W coordinate and therefore would have to be divided AGAIN by new W in order to get effective x,y,z coordinates
The W value isn't returned by the gluUnProject function you'll notice the 1/W value isn't copied into objectCoordinate vector. The W component will always be one if the unproject op succeeded so there is no point in providing it to the caller.
Andrew Khosravian