how to pick up object using mouse?
Hi everybody,is there any article on how to pick up object such as mesh,face,vertex,edge in a 3D viewport?
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.
I've you're using OpenGL, take a look here; http://www.mevis.de/~uwe/opengl/glSelectBuffer.html
:)
:)
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
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/
http://www.codeguru.com/Cpp/G-M/opengl/article.php/c5579/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement