Can anyone explain gluProject

Started by
3 comments, last by Sneftel 18 years ago
int gluProject(GLdouble objx, GLdouble objy, GLdouble objz, const GLdouble modelMatrix[16], const GLdouble projMatrix[16], const GLint viewport[4], GLdouble *winx, GLdouble *winy, GLdouble *winz) the last three parameter is winx,winy,winz the API doc say it is screen coordinate of point, but in screen, we only need winx and winy why there is winz here, screen is a 2D plane
Advertisement
Well I can't give you a real answer, but since the winx winy and winz parameters are pointers, why not give the function a pointer for winz and see what it spits out? You might be able to make sense of it, if you haven't tried already. Sorry but thats all I can offer. Good luck. :)
A vector transformation is done as
v' := P * M * v
where P is the PROJECTION matrix and M is the MODELVIEW matrix.

Then (stolen from man page)
winX := view(0) + view(2) * (v'(0) + 1)/2
winY := view(1) + view(3) * (v'(1) + 1)/2
winZ := (v'(2) + 1)/ 2

So, winZ is a normalized depth co-ordinate, suitable to be compared with a stored value from a depth buffer. That is just a necessity for a way (typically done by hardware) to let surfaces in the foreground hide surfaces in the background (if the set-up is chosen so). It is done well in the "pixel domain", since it allows the depth buffer to show the same resolution as the frame buffer does, so that each pixel has a depth value attached. So you could understand the depth buffer as the 3rd spatial dimension of your window.


EDIT: As soon as you try to do the opposite operation (gluUnproject) you'll see that in general not a location in 3D space but infine many locations are valid for a single pixel, where all locations are ordered so that they build-up a ray. Only if supplying a depth value (say a travel distance along the ray's track) you are able to defined a single locations.
*cough*
Member of the NeHe team.
Quote:Original post by xlvector
why there is winz here, screen is a 2D plane

Without the Z component, how would you do Z-buffering?

This topic is closed to new replies.

Advertisement