简体   繁体   中英

Adding a mouse listener to an object within a GL space

As part of a game I am writing, I have a textured ground plane that is currently implemented as a quad.

I need to be able to listen for mouse clicks and pin point their coordinates on the ground plane.

I can easily implement a listener that returns the coordinates within the viewspace. However, the viewpoint is moveable, so a pixel in the viewspace does not always correspond to the same coordinates on the ground plane.

Is it possible to implement a mouse listener for a quad?

Otherwise, is there an alternative plane implementation that will allow me to texture the plane and listen for mouse events.

Any advice greatly appreciated!

The first thing I thought of reading your question was ( Picking ). But since you've only a single quad you won't be able to determine positions within the quad.

Another solution would be to solve this problem outside the scope of OpenGL and calculate the intersection of the ray and the quad. To determine the ray that goes from the point of view to the scene you would still need the OpenGL context though.

OpenGL just draws stuff to the screen. In particular it draws points, lines, triangles, quads and convex planar polygons. Once the pixels have been set, OpenGL has no persistency about what it drew.

The terms in which you're thinking in is called a scene graph , but OpenGL is not such a thing.

However you can of course implement a scene graph that used OpenGL for drawing stuff, and this scene graph could implement event management and associate event listeners to stuff it drew.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM