So, I've been dabbling with some OpenGL, and I thought I'd give a try at OpenGL picking.
My code right now is strewn across multiple files and I don't have time to post a good unit test, so I'm going to attempt to 'talk' my way through it. If it seems like what I'm describing 'should' work, then I'll see about making a unit test and posting it to see what the pundits have to say.
Anyhow, my 'Picking' isn't working as I'd like -- it seems to always be picking my UI object. I have a hunch, so let me describe my system.
I set up my 'UI' objects by describing them in model space (-1.0,1.0 = Top Left, 1.0, -1.0 = Bottom Right), and then setting the model and projection matrices to identity. I make sure to push/pop them before/after rendering my UI item.
Now, if I end up running picking using the default algorithm, it seems to *always* pick my UI, and I'm guessing my glPushMatrix(); glLoadIdentity(); for both Matrix/Projection is messing things up. I'm betting that the gluPickingMatrix() call I'm using is supposed to set up an 'area' of the window that I'm to render to, and my glLoadIdentity is then saying, "Alright, render into the entire damned thing.", which messes up picking.
... That seems a touch long winded. Apologies if that's confusing, but I'm short on time for this post, so I thought I'd cast this out there and see if anyone can make sense of it. I'll clear up the post come Monday (moving this weekend), but if anyone could affirm my mistake, or say "No, that should be OK", that would be great. :)
I'll see if I can get a unit test in the meantime.
Thanks. :)
OpenGL Picking and my UI.
Started by eddie, Oct 21 2006 04:07 AM
3 replies to this topic
#1
Posted 21 October 2006 - 04:07 AM
#2
Posted 21 October 2006 - 05:11 AM
Ah!
So I was right. Turns out that messing with your GL_PROJECTION matrix is bad for business if you're doing picking. Making sure to disable that when picking is occuring, makes things MUCH better. :)
So I was right. Turns out that messing with your GL_PROJECTION matrix is bad for business if you're doing picking. Making sure to disable that when picking is occuring, makes things MUCH better. :)
#3
Posted 21 October 2006 - 06:44 AM
eddie said:
I set up my 'UI' objects by describing them in model space (-1.0,1.0 = Top Left, 1.0, -1.0 = Bottom Right), and then setting the model and projection matrices to identity. I make sure to push/pop them before/after rendering my UI item.
Now, if I end up running picking using the default algorithm, it seems to *always* pick my UI, and I'm guessing my glPushMatrix(); glLoadIdentity(); for both Matrix/Projection is messing things up. I'm betting that the gluPickingMatrix() call I'm using is supposed to set up an 'area' of the window that I'm to render to, and my glLoadIdentity is then saying, "Alright, render into the entire damned thing.", which messes up picking.
Now, if I end up running picking using the default algorithm, it seems to *always* pick my UI, and I'm guessing my glPushMatrix(); glLoadIdentity(); for both Matrix/Projection is messing things up. I'm betting that the gluPickingMatrix() call I'm using is supposed to set up an 'area' of the window that I'm to render to, and my glLoadIdentity is then saying, "Alright, render into the entire damned thing.", which messes up picking.
I haven't quite followed exactly what you are trying to do. Anyways, if you are designing a UI system, you would be better of using a co-ordinate reference system like all UIs do instead of picking. A co-ordinate space is a planar space that locates two-dimensional objects by using two reference axes that are perpendicular to each other. The third axis (I am assuming Z) is eliminated.
Picking is generally used to select 3D objects in 3D world space. UI is screen space, so you don't need picking as as such. It will work no doubt, but it will be a lot more messy (from a coding perspective) to implement picking for 2D UI objects.
Setting up a screen co-ordinate reference system is easy. Just set the projection matrix to orthographic projection. Now all your mouse co-ordinates are are direct UI co-ordinates. Design your UI like any other UI. No need for picking, just translate Screen co-ordinates to window co-ordinates or vice-versa (just like Win32 APIs ScreenToClient and ClientToScreen) on a mouse click.
#4
Posted 22 October 2006 - 12:49 AM
Interesting.
It turns out that setting up picking wasn't so hard once I removed my glLoadIdentity() for my projection matrix -- turns out I didn't really need it (:$).
It sounds like I could do this several ways, to get picking to work appropriately, but I think I'm going to stick with using OpenGL's method for now, since it was the easiest to get up and running. Although what you suggest would probably be better in terms of performance, since it doesn't need to depth test as heartily...
Thanks for the info -- I'll probably get around to doing it after I get some gameplay going and need the extra CPU cycles. :)
It turns out that setting up picking wasn't so hard once I removed my glLoadIdentity() for my projection matrix -- turns out I didn't really need it (:$).
It sounds like I could do this several ways, to get picking to work appropriately, but I think I'm going to stick with using OpenGL's method for now, since it was the easiest to get up and running. Although what you suggest would probably be better in terms of performance, since it doesn't need to depth test as heartily...
Thanks for the info -- I'll probably get around to doing it after I get some gameplay going and need the extra CPU cycles. :)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












