Advertisement

Smooth Mouse Movement

Started by August 16, 2001 05:34 AM
5 comments, last by duckbob 23 years, 6 months ago
right now i''m using GetCursorPos for mouse movement i found tho because it only returns integers the movement is jerky when my character turns...is there a good way to smooth movement without losing sharp control of the mouse... duckbob
I use this:

GetCursorPos(&mpos);
SetCursorPos(512, 384);
player.yrot += (float)(512 - mpos.x)/100*12;
player.xrot -= (float)(384 - mpos.y)/100*12;

and I get very smooth mouse-movements

btw I use 1024x768 pixels
Advertisement
have a look at nehe''s tutorial lesson #23 its movement is quite smooth
Theres no such thing as stupid people... only people with under clocked brains. -dirty
It would seem MarcJ''s approach is very hardcoded to the screen dimensions he uses, so as an addenda you should probably store the dimensions of the screen in a couple of variables and then calculate the halves from them so you have resolution independant mouse movement.

Alternatively, try using DirectInput if you feel you are up to it. It''s not too difficult to get simple mouse movement working with it.

-Mezz
quote:
Original post by Mezz
It would seem MarcJ''s approach is very hardcoded to the screen dimensions he uses, so as an addenda you should probably store the dimensions of the screen in a couple of variables and then calculate the halves from them so you have resolution independant mouse movement.

Alternatively, try using DirectInput if you feel you are up to it. It''s not too difficult to get simple mouse movement working with it.

-Mezz


I just didn''t get that far yet
But how do you use the mous in DirectInput. I know how to create the device, but how do you detect if/how the mouse is being moved?
hehe, the whole point of use getcursorpos is that i don''t want to use directx...

i hate directx and don''t want to use any part of it...although i know how and have implemented direct input before i just don''t like it...

what i would like is somthing that scales the movement, if you move a lot it moves quiclky, but if the mouse moves slow then you move only small inrements but this magnifys the jerkyness even worse when you move the mouse quickly...
something like mousemovement*2 so if you move the mouse slow you get refined movement but quickly gets fast turning rates...

curently i''m using somthing similar to MarcJ''s approach, i''m not sure what he is trying to acomplish with the /100*12, which could just be /8.333, you also don''t need to put the cursor in the middle of the screen but the main problem i run into with this, besides jerky movement, is that in windowed mode the mouse won''t move when the app is running windowed in the background, just somthing i noticed, i''m sure you could just have an event trigger if the app is on top then reset mfor movement...

btw, what is the name of the mouse click event?

duckbob
Advertisement
The mouse click is (for windows, not DirectX) WM_[L/R/M]_BUTTON[DOWN/UP]

As for scaling, you could try putting in some logic to calculate the change based on pixels traveled.

If you don''t want that try: sqrt(fabs(mousemovement)/scale1)*scale2. As mousemovement approaches scale1 from 0 it grows exponentially. Once past it, growth shrinks.

If you don''t want a sqrt, just try squaring it, but be careful with scaling.

This topic is closed to new replies.

Advertisement