View Full Version : constant speed at any given moment

01-08-2016, 05:33 AM
So I have currently a program displaying a cube. Whenever the user keeps pressing an arrow key the value of 0.20 gets added to a rotation variable to make the cube turn. But sometimes my pc is slower (because of load from other programs or idk why..) and then the cube starts turning slower because the WM_KEYDOWN message is not received as often and thus the 0.20 doesn't get added the same amount of times.
I was thinking of changing the 0.20 to something like 0.20*(frame_rate) but what do you guys think would be the best way to get the cube turning at a constant speed at any given moment ?

Thanks in advance

carsten neumann
01-08-2016, 08:32 AM
Yes, the basic idea for constant speed animations is that you take the amount of time that has elapsed since the last time you rendered a frame and use that to scale the amount you rotate (or otherwise move) the object.
Or looking at it slightly different: you define a rotation speed in radians/sec (or some other unit of rotational speed) and every frame advance the cube's rotation by the appropriate amount based on elapsed time.