PDA

View Full Version : Clicking Objects in the gamewindow



Tivoilos
03-01-2010, 12:47 PM
In all games your able to click on NPC's, Items, Players etc to either bring up a window or to pick up a something off the ground or to even attack. How is this done with OpenGL?

Stanley L
03-01-2010, 03:31 PM
I believe this is typically done without using any OpenGL. Most games probably cast a ray based on the position of the mouse on the screen and do an intersection test against the bounding volumes of pickable objects in the game. Did you need per-pixel picking accuracy?

Tivoilos
03-01-2010, 04:22 PM
not really, sure I am just trying to figure out how this type of thing is done. I would like to move on from text based games to something more visual. An that type of thing comes with it

zeeta
03-01-2010, 05:28 PM
Maybe you want to check out one of the following cross-platform libraries that are used to handle windows.
SDL at http://www.libsdl.org/
wxWidgets at http://www.wxwidgets.org/

OpenGL by itself does not provide any functionality for this purpose.

Jason Anderssen
03-01-2010, 05:51 PM
Opengl is for display objects to the user. The best method for this is to have a scenegraph, that contains all the geometry of the objects you are displaying. Then when the user clicks on the screen, get the near and far points to create a ray, of which you project through your objects in memory, and test if it intersects with any of them.

Hope this helps
Cheers