How would I get absolute pos with DInput?

Started by
8 comments, last by Kavos 23 years, 11 months ago
How do I get absolute position with DInput like the kind GetCursorPos has, where its shows the correct position of the cursor relative to the screen (0,0 is the top left corner ect.) When I try to get the abs position when using DInput it give it to me relative to where the cursor was when the app started. So basically where the cursor starts is 0,0, not a good thing... ~Kavos
Advertisement
To get the abs position of the mouse in direct input you have to calculate it yourself from the relative position. Here''s what to do:

first, create two variables one for the x coordinate and one for the y coordinate, they should be globals and you should never reset them to 0 or you''ll lose the coordinates of the mouse.

second, add the relative position of the mouse, that direct input gives, to the appropiate variable (x or y).

third, stop the x and y coordinates so they don''t give values off of the screen.

ex. if(x <= 0) x=0;

that''s it, you can probably see that this will not really give you the abs value that windows uses, but it works well and i think it''s the only way to do it in direct input.

+AA_970+
Ya, I know, Thats what i''ve been doing but as I siad it sets 0,0 as where the mouse was when the app started, not at the top left corner.

Well, I guess there doesn''t seem to be a way to get the real abs position, so mabey I''ll just use GetCursorPos for movement and DInput for the button presses.

~Kavos
Giving up already? Set the cursor position to (0,0) at app start-up.
Nah, that wont work, But hey! what if I use GetCursorPos just to get the inital position of the cursor when the app starts, then I could use DInput to track it!

~Kavos
Usually the ''real'' mouse position is irrelevant for DirectDraw apps anyway, as you often change the resolution. I find it perfectly acceptable to just centre the mouse in the screen when my game starts, and so do most commercial developers
Use the
SetProperty(REFGUID rguidProp,LPCDIPROPHEADER pdiph);
function.
Use DIPROP_AXISMODE as the first prameter and set the dwData member of the structure in the second paramter to DIPROPAXISMODE_ABS.
Check the MSDN for more info (platform sdk/graphics and mltimedia services/directx)

Edited by - octavsoft on May 21, 2000 10:22:42 AM
OctavianE-mail: [email=octav@octavsoft.com]octav@octavsoft.com[/email]Webpage: http://www.octavsoft.com
Ya, I got it to work. I wasn''t drawing my own mouse sprite, once I did that it was easy ;p
You can also do it like this:

Say you set the resolution to 640x480, then when the app
starts the mouse is always in the middle, so all you have
to do is to create to variables and initialize them to
half the screen resolution, like this:

int mouse_x = 320,mouse_y = 240;

then just add the relative values you get from DInput to these variables.
With directinput, the mouse will start at the very center of the screen, so at the game start up, preset
x_mouse_pos = x_resolution/2;
y_mouse_pos = y_resolution/2;

then, in directinput, just add the relative pos to the x & y_mouse_pos, then put in the mouse pos limits

if (x_mouse_pos < 0)
x_mouse_pos = 0 ect...

Also, have an excluse mouse, dont use non-exclusive. If your using a non-exclusive mouse, then windows will draw the mouse pointer and you will notice that the direct input absolute coordinates will be different from the mouse on the screen, so use excluse mode and draw the mouse your self from the absolute position you get from directinput.

Possibility

This topic is closed to new replies.

Advertisement