Archived

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

dj

Mouse coordinates in DInput

Recommended Posts

How can you get the mouse coordinates (using DInput) in screen coordinates? The GetDeviceState() returns coordinates in lX and lY members of DIMOUSESTAE structure in some strange units that don''t seem to correspond to pixels on the DirectX surface? Is there any easy (or not so easy) way to convert these to screen units? BR, dj

Share this post


Link to post
Share on other sites
As far as I know, it outputs only the relative position for the axes, meaning it tells you only how much the mouse has moved since you last called GetDeviceState(). In my implementation I use 2 variables - mouse_x and mouse_y, and add the output from GetDeviceState to them every frame.

Share this post


Link to post
Share on other sites
DirectInput returns the mouse positions in pixels, but it only returns the number of pixels the mouse has moved. If the mouse was at 5,5 and you move the mouse to position 10,10, then DirectInput would return 5 for the x and y axes because it moved 5 pixels. That''s usually best for most games, but if you want to find out the exact position, you can keep track of your own mouse coords like skallio said.

Share this post


Link to post
Share on other sites
Hi Midnight Coder and skallio,

That work fine, but it sill doesn't tell me the absolute screen coordinates (and that's what I need to get). It just tells me the offset from the previous position.
I need to know where the mouse pointer is exactly in order to determine if it is over an object that has absolute coordinates (in screen or map world).
I other words, how can you select an object that has known absolute screen (or map) coordinates using relative mode used by GetDeviceState().
GetDeviceState() can also return absolute values but the origin for the coordinates is somewhere on another planet

BR,
dj

Edited by - dj on July 24, 2001 9:09:06 AM

Share this post


Link to post
Share on other sites
Enless I have read it wrong, your question in the post above is pretty stupid (and I apologise now for saying that so blatently, I prefere not to critasize in that way).

Just use the relative coordinates to get the absolute coordinates using simple maths.

Take 2 varibles to store the x,y coords, and add/subtract as necesary. If the relative x coord is -5, then subtract 5 from your x variable. Use the variables to check where the mouse cursor is at on the screen.

I might have miss-understood, but there''s my reply, plain and simple!

G''luck,

Dachande

Share this post


Link to post
Share on other sites
As far as i know Dinput wont directly or indirectly tell you where the mouse is in screen coords..its been a while since i looked at it but i was running into the same problem..
you can use the getcursorpos() function however thats a windows function and it doesnt work so well if you have dinput mouse...i was running into funky things happening with that...anyways good luck

Share this post


Link to post
Share on other sites
If your game is running full-screen, you don''t need to know the actual position of the cursor. Most games make their own cursor and display it at it''s own coordinates. Just have two variables - x and y. When you draw your game''s cursor, draw them it in this location. Then, whenever you get input, just add the values that DirectInput gives you. For intanse if your game''s cursor is at 20,30, and the mouse moves -6 pixels, you would add -6 to 20 and get 14.

If you are running in windowed mode, this may or may not be a good idea. You could just disable the Windows cursor whenever your app has focus, but often you''ll want to use the regular cursor. In this case, you could just use GetCursorPos (I think).

Hope that helped, let me know if you still have problems.

Share this post


Link to post
Share on other sites