gluUnproject implementation

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Does using glGetDoublev instead of glGetFloatv buy you anything?

The source code for gluUnProject is in Mesa CVS
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
OneSadCookie Wrote:Does using glGetDoublev instead of glGetFloatv buy you anything?

The source code for gluUnProject is in Mesa CVS

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.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
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 )

[Image: WorldHud.png]

Thanks,
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL gluUnProject() pixelDepth question WhatMeWorry 3 8,756 Jan 15, 2011 10:54 AM
Last Post: Oddity007
  Suggestions for Sound Implementation soulstorm 15 7,303 May 15, 2009 07:54 PM
Last Post: Gillissie
  Shader implementation questions akb825 12 5,194 Jun 5, 2006 04:39 PM
Last Post: akb825
  gluProject <-> gluUnproject help please szgezu 9 7,136 Feb 26, 2006 11:50 AM
Last Post: szgezu
  Help with mouse click position to OGL coords using gluUnproject hyn 14 13,842 Aug 6, 2004 07:57 AM
Last Post: GioFX