Jump to content
  • Advertisement
Sign in to follow this  
tomneo2004

[Help] Ray picking

This topic is 3310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!