how to pick up object using mouse?

Started by
3 comments, last by Moagly 19 years, 5 months ago
Hi everybody,is there any article on how to pick up object such as mesh,face,vertex,edge in a 3D viewport?
Advertisement
What you want is a technique called 'Picking.' It involves projecting a ray from the eyepoint, through the point on the near plane that you clicked on, and out into your scene (you then collide it with objects to find out what it hits). If you're using DirectX there are D3DX functions that can help you with it; if you're using OpenGL I think there might be some GLU functions for it.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

I've you're using OpenGL, take a look here; http://www.mevis.de/~uwe/opengl/glSelectBuffer.html

:)
| Stein Nygård - http://steinware.dk |
An alternative approach is to have a second frame buffer which holds a second render of your scene, but this time you don't bother lighting the objects at all but set the colour of each one to a unique ID colour, then when the user clicks on the screen the x and y coordinates can be used to get the appropriate location in the offscreen buffer, using the colour at that location to retrieve the object ID.

Advantages : No ray/object intersection tests are needed.
Disadvantages : You have to render twice.

hope this helps
Sorry just read ur post again, tutorial available :

http://www.codeguru.com/Cpp/G-M/opengl/article.php/c5579/

This topic is closed to new replies.

Advertisement