Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

OpenGL Emulating gluUnProject

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

Hi,

I'm writing a ray-tracer that will act as a plugin to my OpenGL renderer. I need to get the rays from the camera through the screen. My ray tracer works with gluUnProject. However, when I try to emulate it with my matrix classes, it doesn't work; all the rays are wrong. I would very much like to emulate it with my matrix classes, because they let me save time (I don't, for example, need to recompute (P*MV)<sup>-1</sup> for every pixel).

I've confirmed that the modelview and projection matrices are the same for both algorithms. I've also confirmed that, in my code, P*MV is calculated correctly. Further, I've tested matrix inversion, and know that it also works. But, for some reason, when multiplying the clip-space pixel, the result is not the same.

My code has a lot of interdependencies, so before I post about a dozen different files containing code, anyone have any ideas for a quick fix?

Thanks,
-G

Share this post


Link to post
Share on other sites
Advertisement
Well its hard to say really what you could have done wrong. Are you following the same equations as gluUnProject? They're listed on its documentation page.

http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml

Note that gluUnProject documentation mentions multiplying modelview*proj, not proj*modelview like you've described. Maybe that's your error?

Share this post


Link to post
Share on other sites
That is something I haven't understood about GL. There is this M * P concept all over the place but in fact it is P * M.
Even in GLSL, there was gl_ModelViewProjectionMatrix.
Look into GLU's source if you want. It's P *M and then they invert the matrix.

Share this post


Link to post
Share on other sites
That is something I haven't understood about GL. There is this M * P concept all over the place but in fact it is P * M.
Even in GLSL, there was gl_ModelViewProjectionMatrix.
Look into GLU's source if you want. It's P *M and then they invert the matrix.
I had found the source for Mesa, and saw that they did it that way there. Just in case, I did try switching them around a couple times. It's bewildering; any way it's done, the matrices are being multiplied correctly (I've printf-ed them out and checked), but when used to transform the points, they don't work. It's very strange. I understand I'm not being very helpful--it's just one of those bugs that are hard to fix because they *shouldn't* exist, yet do. Hate those.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!