Mouse coordinates in DInput

Started by
7 comments, last by dj 22 years, 8 months ago
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
Advertisement
I don''t remember exactly, but you define a point like this:
POINT mouse;
then you call a function like GetCursorPos() or something like that and pass the mouse variable to the function. then you can access the updated cursor positions like this:
mouse.x
mouse.y

HHSDrum@yahoo.com
Polarisoft Home Page
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
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.
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.
Thanks a lot to all of you guys.

BR,
dj

Edited by - dj on July 24, 2001 8:35:04 AM
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
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
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
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.

This topic is closed to new replies.

Advertisement