Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / What's under the mouse cursor? Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Russell Klenk

March 11, 1999, 10:47 AM

Anybody know how to determine which polygon is under the mouse cursor when in a 3d view? (like in a level editor)

Russ

 
Thierry Tremblay

March 11, 1999, 11:01 AM

>>Anybody know how to determine which polygon is under the mouse cursor when in a 3d view? (like in a level editor)



Sure, just cast a ray into your scene starting from your eye (viewpoint) and going through a point on the projection plane. Basically, you have to convert a screen coordinate (x,y) on the projection plane (usually, Z=1) to 3D world space. Then you have 2 points defining a ray (viewpoint, point on the projection plane). You then do a ray tracing into your world until you hit a polygon, and voila. This is also called "picking".

Thierry

 
Colas

March 12, 1999, 04:42 AM



Russell Klenk wrote:
>>Anybody know how to determine which polygon is under the mouse cursor when in a 3d view? (like in a level editor)
>>
>>Russ

use the projected coordinate of you polygon (screen space)
then test if the mouse pointer (a point on the screen) is in each polygons.

what you need:

a method to fin if a point is in a polygon (very easy to find)
some optimisation to quikly determine wich polys could be under the mouse pointer
(usefull if you want to know wich polys in a 10000 polys scene)
bsp
octree
other spaces subdivision (use a grid for example)


Colas

 
Harmless

April 06, 1999, 01:45 AM


Russell Klenk wrote:
>>Anybody know how to determine which polygon is under the mouse cursor when in a 3d view? (like in a level editor)
>>Russ

If you are using an un-broken implementation of OpenGL in the editor you can use:

glRenderMode(GL_SELECTION);

glSelectBuffer() to set a buffer for polygons overlapping the selection

set the GL_PROJECTION matrix with gluPickMatrix() to set the region you are interested in, apply perspective and 'render' the scene.

Although, I'd only use this approach under duress. Usually I'd do what Thierry Tremblay suggested and cast a ray. =)

-Harmless

 
This thread contains 4 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.