Archived

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

How do i know where the mouse pointing at?

This topic is 5043 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

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 this post


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


Link to post
Share on other sites
Guest Anonymous Poster
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.


Please give us a hint ,link to what these techniques are

Share this post


Link to post
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

Share this post


Link to post
Share on other sites