Sign in to follow this  
Kevn

DirectX 10, Collision detection with mouse question.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

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