#### Archived

This topic is now archived and is closed to further replies.

# How do i know where the mouse pointing at?

This topic is 5381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How do i know where the mouse pointing at in DX? You know, in a game you always use the mouse to click on something (characters, buttons, tiles, items...that sort of things). How could i do that? Is there any function in DX to do that? or we have to do it ourselves? if so, then how? any info/links? Thanks for helping

##### Share on other sites
Thanks, CrazedGenius.

( I never notice there''s a ''pick'' example there before. I guess i spent too much time looking at the D3D examples there... )

Thanks~

##### Share on other sites
If you imagine a line that goes from the camera to the point on the near plane that the cursor is resting on and extend it further. That''s the pick line. A very crude (yet simple) way to find what is under the cursor is to do an intersect with every object and that line and see what is the closest. More advanced techniques exist.

##### Share on other sites
quote:
Original post by Anonymous Poster
If you imagine a line that goes from the camera to the point on the near plane that the cursor is resting on and extend it further. That''s the pick line. A very crude (yet simple) way to find what is under the cursor is to do an intersect with every object and that line and see what is the closest. More advanced techniques exist.

##### Share on other sites
I have an openGL demo of picking, not sure if you want it posted, since its, uh, openGL. I also used my own collision routines for line segment to object and line segment to world tsting, which is a much deeper discussion involving line to triangle tests.

But basically the method is to use a line segment, that starts at the camera position, and ends at the far clip plane of the viewing frustum. Using the clip and projection matrices, you can derive where on the far clip plane the line segment ends (the intersection point of the near clip plane should be where you clicked your mouse)

Once you have this line segment, you run collision checks against it and the objects in the scene (and any additional geometry as well)

If anyone is interested I will post my math on using the projection and clip matrices to derive the end point, but you might want to check the DX9 SDK example. I havn''t so I''m not sure what they have.

-Zaya

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633325
• Total Posts
3011372
• ### Who's Online (See full list)

There are no registered users currently online

×