Jump to content
  • Advertisement
Sign in to follow this  
walle

Smooth mouse motion

This topic is 4960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I'm trying to get a smooth mouse motion in SDL for moving a paddle. Perhaps even timebased movment. Ideas anyone? //walle

Share this post


Link to post
Share on other sites
Advertisement
At first I put the paddle exactly where the mouse was, but it was to fast. Then I thought to move the paddle in the same speed towards were the mouse was, I checked if the paddle were to the right or the left to the paddle and moved left or right acordingly the mouse were over the paddle I didn't move. But it doesn't feel good. I've seen people use a mouse sensitivity variable, but I havn't got it to work.

Hope it makes any sense at all, just out of bed =)

///walle

Share this post


Link to post
Share on other sites
You could use the frame time and multiply your mouse delta values by frame time and pixels per second, e.g.

static const float pixelsPerSecond = WindowHeight / 4.0;

int newY = mouseDeltaY * frameTimeInSeconds * pixelsPerSecond;

playerPaddle.SetNewY(newY);

Something along that line should be good, I guess. You don't even need to check every frame - sum up delta values until frameTime > threshold, with threshold being at least 0.02s (50 FPS) because sometimes movement will be jerky (e.g. abrupt position changes if frameTime varies too much).
To get it really smooth, you can sample the last 4 - 8 frames and interpolate frame times.

Good luck,
Pat.

Share this post


Link to post
Share on other sites
I can't really get it to work...it is for a breakout style of game, so I changed the window hight to window width and such...but the paddle just sitts at one corner all the time.
What did you mean with "frameTimeInSeconds"? How do you get it?

//walle

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!