Skip to main content
gamedev.net
🔒 Locked

SIMPLE Object Picking

Started by neonfaktory Feb 19, 2003 at 12:56 PM 1 replies 450+ views
Original Post
neonfaktory
neonfaktory
I was wondering if anyone could help me with some SIMPLE object picking in OpenGL... I''ve read the tutorials out there (NeHe, DigiBen, etc.) about it, and it all seems over-complicated... At least for my purposes. So i was hoping someone could help me - I''d hate to do all that stuff when I could possibly manage with something much more simple. It''s a 2D OGL game, but it is NOT in Ortho Mode (there is Zooming In/Out, and I''m letting OpenGL handle the size/perspective changes and stuff). ANYWAY, is there some way I could do a simple X/Y Coordinate Picking check for specific objects if I know the objects'' Z distance away, thier difference in X and Y from the Camera''s X and Y position and the Projection Matrix values? I mean... there''s GOT to be a way, but I''m not quite sure how I''d utilize it. For example, maybe by comparing the X/Y of the mouse on screen to the Screen Resolution and using that with the projection angle of my projection matrix I could do some trig to figure out if an object was selected? Eh, I''m confused tho - thanks for any help you can provide.
weee!
Blivvy
Blivvy
Are you after pixel perfect selection or just an approximation?

If the former, then you have little choice other than using OpenGLs selection buffer or writing your own ray picking routine.

If you''re just after an approximation, then there are a quite few things you could try.

As a simple example, let''s say the camera always faces down the z axis and each object has an axis-aligned bounding box. You could project the four vertices of the box face that is facing the camera yourself and test the mouse coordinates against the resultant 2D rectangle.

You can use glGetFloatv() to get the model view and projection matrices. You would still need to write a function to perform the vertex-matrix multiplication, but this shouldn''t pose a problem.
neonfaktory
neonfaktory
Thanks for the response Bliv, and you are right - the camera is always facing down the Z Axis and the objects do have simple axis-aligned bounding boxes that I would use for the selection.

Basically, this is how I see it. Let''s say I zoom out in my game, and an object slides in on the right side of the screen. OpenGL did some wacky math based on the projection matrix vals and the difference in the object position and the camera position(X, Y, AND Z) to determine that the object center is (600, 400) PIXEL Coordinates. Using the same math and information, shouldnt I be able to reverse that to get a mouse World Coordinate (on the same plane as my 2d objects) based off the PIXEL Coordinates to start? Or does it not work that way, haha - I dont know, but again thanks for any help
weee!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.