PDA

View Full Version : gluUnproject implementation


TomorrowPlusX
2006.09.14, 06:00 PM
Could somebody help me with implementing my own gluUnProject? I read the manpage to learn how it works but I'm a little uncertain... I unfortunately threw out my own implementation ( which didn't work ) months ago in frustration or else I'd post it here for you all to help me with.

The reason I want to write my own is I'm about to write some code which will use gluUnProject heavily -- right now I'm wasting a bit of time converting my modelview and projection matrices from floats to doubles each time I call gluUnproject. It would be nice to have a gluUnProjectf which doesn't need to work with doubles...

Thanks,

(specifically, the situation is that I'm implementing render to texture for my user interface code so you can have a working UI in 3d in a game, say on a computer screen in a room or whatever. To be able to interact with this UI, I need to be able to convert mouse coordinates to a vector in world space which I can then do plane intersections with to get the location on the virtual screen in the 3d world. It would be nice to not have to convert 2 4x4 float matrices to double with each update of the game state... my wee powerbook is taxed enough as it is )

EDIT:

I'm a big fat idiot. I found the gluUnProject source in MESA... nevermind. Moderators, delete me if you want.

OneSadCookie
2006.09.14, 06:08 PM
Does using glGetDoublev instead of glGetFloatv buy you anything?

The source code for gluUnProject is in Mesa CVS (http://webcvs.freedesktop.org//mesa/Mesa/)

TomorrowPlusX
2006.09.14, 08:14 PM
Does using glGetDoublev instead of glGetFloatv buy you anything?

The source code for gluUnProject is in Mesa CVS (http://webcvs.freedesktop.org//mesa/Mesa/)

That's a good point, but this is actually being used in a situation where the current modelview/projection may not correspond to the matrices I'm needing. I keep my modelview & projection in my camera class, as float, and use them because I know they're always valid -- for *that* camera.

Anyway, I did find the source, I'm making certain I understand it before I start running with it. I think my old version didn't work because it's possible my mat4 inversion function is wrong/naive.

TomorrowPlusX
2006.09.19, 12:27 PM
Hey, I'm excited that this works. I've got a hud, rendered in the 3d world ( on a cube ) which can be interacted with, thanks to the help above ( and the help in my question on 3d math )

http://zakariya.net/shamyl/Screenshots/WorldHud.png

Thanks,