Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Detect Mouse over Object (OpenGL)

Posted on 2004-03-24
4
Medium Priority
?
4,801 Views
Last Modified: 2013-12-26
Ok. How do I detect a mouse over an object? Please be easy...
0
Comment
Question by:rossryan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:trylle
ID: 10675929
You can do this by casting a ray from where the mouse coordinates on the screen and project it into your scene, usually with the gluUnProject function (then checking if it intersects any of the objects bounding boxes, spheres, etc., then searching through the triangles, etc.).

OR you can use the OpenGL selection buffer which is much easier to use.

The basic idea with the OpenGL selection buffer is that you do your rendering as you usually do it. Then you have a second cycle (in your case this would happen every frame) where you initialize a select buffer, set the GL_SELECT render mode, set up view transformations and a pick matrix, and draw your objects again. When you go back to the GL_RENDER render mode, the hits are returned in the select buffer. You can get multiple hits, because there may be objects stacked on top of each other in the view.

There is an example and more in-depth explanation of it here (http://www.helsinki.fi/~tksuoran/selection.html).
0
 

Author Comment

by:rossryan
ID: 10693534
Hmm. Have a select buffer, thought that you needed to click on an object for that to work...

So you're saying that if it (the mouse cursor) floats (not clicks) over an object, that will show up in the select buffer?
0
 
LVL 1

Expert Comment

by:Tuomas
ID: 10693917
Here is a link to a tutorial, which shows how to select an object with left mousebutton:

http://www.ultimategameprogramming.com/zips/Gl_GlutSelection.ZIP

Here are other simple tutorials from the same page:

http://www.ultimategameprogramming.com/Tutorial.php?category=OpenGL&page=1
0
 
LVL 1

Accepted Solution

by:
trylle earned 2000 total points
ID: 10700786
Just call the select buffer code with cursor coordinates (from e.g. GetCursorPos) after (or before, for that matter) your rendercode instead of only when you receive a mouse click event.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question