• Create Account

## DirectX 10, Collision detection with mouse question.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Kevn  Members

165
Like
0Likes
Like

Posted 02 January 2013 - 06:47 PM

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?

### #2kidman171  Members

498
Like
1Likes
Like

Posted 02 January 2013 - 07:08 PM

### #3Kevn  Members

165
Like
0Likes
Like

Posted 02 January 2013 - 07:17 PM

Thank you

### #40r0d  Members

1572
Like
0Likes
Like

Posted 02 January 2013 - 07:49 PM

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.