Jump to content
  • Advertisement
Sign in to follow this  
bartiss

Picking 3D objects with mouse

This topic is 4997 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'm trying to find a way to select units with mouse cursor in a 3D RTS game. What's the fastest way? I figured out I'm supposed to create bounding boxes for all units (ComputeBoundingBox(...) ?) and then a vector from mouse click position paralell to the view axis would be useful. Am I supposed to walk from start of the "pick line" to the nearest object while checking if current point is inside any of bounding boxes? Or is there a math function checking intersection of a ray with a box (or set of boxes)? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I've been busy with this last week. I recommend not using the D3DXComputeBoundingBox function.

Why?

Well, it does what it says: box. Not a rectangle, but a box.

So imagine you want to have a bounding box around a piece of paper (long and thin). If you used the D3DX function, it will make the width (1mm?) of the paper have a bounding box of the length of the paper.. to make a box!

A rectangle would be a lot better, since it will fit exactly round the paper.

How to do this:

vector Max = 0
vector Min = 0
Loop through all vertices
if (vertices.x < Min.x) Min.x = vertices.x
if (vertices.x > Max.x) Max.x = vertices.x
//(repeat for y/z)
Next

And then you got yourself a vector min and max: min is top-left of you, vMax is far-right-top. Good luck ;)

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!