Jump to content
  • Advertisement
Sign in to follow this  
iedoc

ray picking

This topic is 3873 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

sorry, i know theres a bunch of these. i just saw one below this one. i can't figure whats wrong, when the object is in view, when i pick it automatically explodes. but when it isn't in view it doesn't, which is good. how do i get it so it only explodes when i aim at it, not when its just in view?

Share this post


Link to post
Share on other sites
Advertisement
A 2D point on the screen (where your mouse click happens) can be converted into a 3D line between the near and far planes. You can use D3DXVec3Unproject() for this job (specify your mouse XY along with Z=0 and then again with Z=1).

Once you have a line segment you need to test it against your geometry - you can look up the various ray-object intersection methods as there are a few variations and sample code is quite common. You can either test every single triangle in a model or you can check bounding volumes.

Is that enough to get you started?

Jack

PS. Moved to 'Maths & Physics' for further discussion

Share this post


Link to post
Share on other sites
thanks jolleyjeffers, that does help. im curious, how would i go about coloring that line segment? i want to be able to see my ray when i click

Share this post


Link to post
Share on other sites
If you draw it, you will draw 1 pixel! That should help you ask the right questions ;)

In OpenGL, you would use "gluUnProject" at near and far clip planes to form your ray, but you can test at any 2 z values; 1.0+ is best for the near unproject even if you have your actual nearClip set microscopically close.

Presuming you use DirectX though, so however they do it!

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!