Sign in to follow this  
cisrudlow

selecting 3d object with mouse cursor

Recommended Posts

hi, well if you are using OpenGL you can use the standard picking method (see "Red Book", it has an excellent description) but this involves an extra rendering pass, or you can use ray picking, which involves casting a ray from your mouse screen position and check whether it intersects any of your objects (actually their bounding box or sphere or whatever).

Another way is to project your objects bounding box to 2D screen coordinates, then check your mouse position (or selection rectangle) to see if it intersects any of the rectangles. For OpenGL you'd use glProject and glUnproject, unfortunatly i can't give you any source examples now but there are a lot of topics on these 2 on gamedev.

Share this post


Link to post
Share on other sites
There are two basic ways of picking objects in a 3d space using the mouse cursor.

1. Shoot a ray/line into your 3d space and find the first object intersected by the line.
To do this you create a line in immage space and transform it using the transposed worldviewprojection matrix to get it in world space, then you do a line intersection test agains whatever spatial data structure you have build your world against.

2. Do the picking in immage space, this is done by assigning an id number as the color of each object viable for picking. Ie the elephant is colored 0x00000001 the tiger is colored 0x00000002 etc. Then when a mouse click is detected you set a texture as the render target clears it to color 0x00000000 renders all your pickable objects (possibly after view frustrum culling) you the lock the texture and reads the color at the mouse click coordinates. You can now get the object pointer from eg a map using myobjectmap[coloratmouse].

Hope this helps.

Rgs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this