Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Detect Mouse over Object (OpenGL)

Posted on 2004-03-24
4
Medium Priority
?
4,837 Views
Last Modified: 2013-12-26
Ok. How do I detect a mouse over an object? Please be easy...
0
Comment
Question by:rossryan
  • 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

877 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