Jump to content
  • Advertisement
Sign in to follow this  
xlvector

Can anyone explain gluProject

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

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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. :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!