Archived

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

Mouse coordinates

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

Sorry if this has been asked before: I need to find out when the mouse is clicked whether it is inside a certain area - basically, the area of 2 polygons that my sprite is loaded onto. I''m using it for a menu options screen thing. Basically my problem is that DirectInput reports the mouse to be at nonsensical positions rather than a value between 0-800 on the x and 0-640 on the y. Can I get "real" coordinates for my window and if not, what is the best way to accomplish what I want to do? Cheers Dave

Share this post


Link to post
Share on other sites
If you are using DirectInput, then you must track the screen coordinates yourself. At the start of your program, define two variables that represent the cursor''s position. Whenever you poll the mouse for data, add the values from the mouse structure''s .lx and .ly variables to the two variables that represent the screen coordinates.

If, on the other hand, you are using a windowed application and the cursor is visible, skip DirectInput and get the mouse coordinates directly from Windows using GetCursorPos or by processing WM_MOUSEMOUSE messages.


Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX

Share this post


Link to post
Share on other sites
quote:
Original post by Jim Adams
If you are using DirectInput, then you must track the screen coordinates yourself. At the start of your program, define two variables that represent the cursor''s position. Whenever you poll the mouse for data, add the values from the mouse structure''s .lx and .ly variables to the two variables that represent the screen coordinates.



Thanks but how would that help to find where the mouse actually is? The coordinates I store would all be relative to an unknown origin would they not?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Two words

D3D PICK EXAMPLE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
READ THE D3D PICK CODE!!!

It first asks for the coordinates in screen coordinates and then it makes a ray with an origin, then you just need to test intersection. If you can provide already transformed tris then you can bypass the whole untranformation routine.

Share this post


Link to post
Share on other sites