Smooth mouse motion
Hello. I'm trying to get a smooth mouse motion in SDL for moving a paddle. Perhaps even timebased movment. Ideas anyone? //walle
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
Hope it makes any sense at all, just out of bed =)
///walle
You could use the frame time and multiply your mouse delta values by frame time and pixels per second, e.g.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement