Advertisement

direct input and the mouse

Started by March 08, 2000 08:33 PM
2 comments, last by +AA_970+ 25 years ago
hi, i just added support for the mouse in direct input for my game but i don''t know if what i''m doing is a good & efficient way of doing things. Ok, i''ll explain what i''m doing: first, i coded a way to get the coordinates of the mouse (since dinput only gives relative coordinates )and control the coordinates so they don''t go beyond the screen. After i did this i wanted a mouse cursor so within my game loop i drew a bitmap that i wanted for my cursor at the mouse coordinates. Now i want a way to adjust the sensitivity, i''m unsure about this but what i''m currently doing is multiplying the relative coordinates of the mouse by a value and then adding the resulting # to the current coordinates. Well that''s what i came up with, can someone tell me if this is a good way of handling mouse support or is one or more of my methods inefficient?
That is how I do it. Just to let you know., I think it is almost impossible to imitate the Windows/Mac mouse with DInput. If someone knows how to imitate it(using DInput), I''d like to see how.
Advertisement
It seems OK to me.

You may want to add acceleration to the mouse, so that the sensitivity is low when the user start moving and then grows as he continue to move the mouse.

Also if you have low frame rate on your game you will get very choppy movement of the mouse. If this ever happens you may consider moving the mouse handling routine to a separate thread. (Read this to learn how). Personally I wouldn't use multiple threads unless absolutely necessary.

Edited by - Spellbound on 3/9/00 6:20:50 AM
A bit Delphi Code :-)

Get the Mouse-Parameters of windows
SystemParametersInfo(SPI_GETMOUSE, 0, @WinMouseParam, 0);

then read DInput
DirectInputDevice7_Mouse.GetDeviceState(SizeOf(DIMouseState), @DIMouseState);

later

with WinMouseParam,MousePos do
begin
case speed of
1 : with DIMouseState do
begin
if Abs(lX) > threshold1 then Inc(x, 2 * lX) else Inc(x, lX);
if Abs(lY) > threshold1 then Inc(y, 2 * lY) else Inc(y, lY);
end;
2 : with DIMouseState do
begin
if Abs(lX) > threshold2 then Inc(x, 4 * lX) else
if Abs(lX) > threshold1 then Inc(x, 2 * lX) else
Inc(x, lX);
if Abs(lY) > threshold2 then Inc(y, 4 * lY) else
if Abs(lY) > threshold1 then Inc(y, 2 * lY) else
Inc(y, lY);
end;
else with DIMouseState do
begin
Inc(x, lX);
Inc(y, ly);
end;
end;

Well thats it
-crent-

This topic is closed to new replies.

Advertisement