DirectX 10, Collision detection with mouse question.

Started by
2 comments, last by 0r0d 11 years, 3 months ago

I'm trying to make it so I can drag objects, like a box, around with my mouse in a DirectX 10/Windows application. So far I only have a plane for the floor, a few boxes, and my mouse coordinates displayed to the screen. What would be the best technique to detect when my mouse is over an object? Do I need to figure out where the box edges are in terms of screen coordinates and then do a compare with my mouse coordinates? If so, how do I determine the location of an object in terms of screen coordinates instead of my world coordinate system?

Advertisement
Google 3d picking

Thank you :)

I'm trying to make it so I can drag objects, like a box, around with my mouse in a DirectX 10/Windows application. So far I only have a plane for the floor, a few boxes, and my mouse coordinates displayed to the screen. What would be the best technique to detect when my mouse is over an object? Do I need to figure out where the box edges are in terms of screen coordinates and then do a compare with my mouse coordinates? If so, how do I determine the location of an object in terms of screen coordinates instead of my world coordinate system?

1. Get the projection-space point of your screen click position (Pos_Proj)

2. Combine your world-to-view, and view-to-projection matrices into a single world-to-projection matrix

3. Do an inverse matrix multiply with Pos_Proj, this will give you the world-space point (Pos_World)

4. Get the world-space direction vector (Dir = Pos_World - Pos_Camera)

5. Now you can do an intersection test between the position and direction vectors and whatever geometry you have

This topic is closed to new replies.

Advertisement