PDA

View Full Version : Simplifying gluUnProject



Uflenu
05-14-2001, 06:03 AM
Hi everybody,

I'm using glReadPixels and gluUnProject to get the 3D coordinates of all the pixels of a picture (my purpose is to calculate a simulated sonar profile of the scene).
gluUnProject is time consuming, and returns absolute coordinates which I need to convert into new coords relative to the viewpoint.
I guess that this transformation is made twice (once, reversed, inside of the unproject subroutine and once by myself). I think that I would save time if I could directly unproject the winZ, winY, winZ into the viewpoint coordinates system.
The 2 ideas I have are:
- do the unproj myself with a simplified algorithm
- pass modified proj and/or model matrices to the gluUnProject routine

Could somebody help in any of these directions ?

Thanks,

Eric

cass
05-14-2001, 07:37 AM
Why don't you look at what gluUnProject() in the sample implementation source? It's a pretty straightforward calculation, but the way that gluUnProject is specified, I expect they have to perform a matrix inversion each call.

If you're going to unproject a lot of points by the same matrices, you can probably do much better.

Cass

ET3D
05-14-2001, 12:44 PM
Sounds like you just want to undo the projection matrix without the modelview. I'm too lazy to think how the inverse of the perspective projection will look, but with some luck it could result in a matrix with some zeroes, which would make it faster to multiply. You could probably get additional speed by calculating some differences beforehand. That's because you're using equally spaced X and Y values, so terms that use them should grow by a fixed amount every pixel.

Another thought - you may be able to get a similar result by drawing the scene again without the perspective projection. It might not get you the exact same result (certainly the view frustum will be different), but it may be a direction worth thinking about.

john
05-14-2001, 03:14 PM
Sounds like you just want to undo the projection matrix without the modelview. I'm too lazy to think how the inverse of the perspective projection will look

<homer like voice> hmm. lazy. goOOod. <drools>

the inverse ot the projection matricies are given in the back of the red book! You can compute the inverse when you build your projection matrix, without doing some generic matrix reduction code. Is nice =)

cheers,
John

[This message has been edited by john (edited 05-14-2001).]

ET3D
05-15-2001, 04:46 AM
Knew there'd be somewhere. See, that's why I never like to do work. Someone always did it for me before. Just have to find it http://www.opengl.org/discussion_boards/ubb/smile.gif

Now, it's a pity that I only have the blue book at home...