Sign in to follow this  
tomneo2004

[Help] Ray picking

Recommended Posts

tomneo2004    112
I have load a mesh and then i draw a AABB bounding box for the mesh. the bounding box will move and rotation with mesh. Now i want to create a ray to detect that if ray hit the mesh, bounding box or not hit any thing. Anyone got the idea how to do that or example? in my guess, i have to use getcursorpos() to get the mouse position and compute vector origin and direction and then translate those into view space -> project space -> world space -> model's local space then check if it hit the mesh or bounding box. is this theory correct? Buy the way, when i load a mesh what space it is? [Edited by - tomneo2004 on June 22, 2009 7:19:15 AM]

Share this post


Link to post
Share on other sites
EJH    315
The general idea is that you cast a ray:

- origin is the image plane pixel where the mouse pointer is
- through a point on the near clip plane (creating a ray)
- intersect that ray with stuff

Google "language" + "API" + "picking example" (e.g. C# XNA picking) and you should get a ton of examples.

Share this post


Link to post
Share on other sites
Waterwalker    431
If using OpenGL google for gluUnproject and its source code which is, for example, to be found in the Mesa implementation.

If using Direct3D google for D3DXUnproject. Both should yield enough results to get you the idea of how its done. Your approach is already the correct way to do it.

When loading a mesh its considered to be in local coordinate space with its own origin and axis system. If you render it as is without any additional transformation except for the camera space then this local space equals the world space.

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