# Clock hand, how much should I rotate the hand by every frame?

I've got a virtual clock. The clock consists of the actual clock sprite, and a hand to go over it.

I'm able to set how long the clock duration is. Say I set it to: 5 seconds. While the clock time is going, it will eventually stop until it reaches 5 seconds. Until it has reached 5 seconds, the hand will start rotating.

The hand should theoretically be at the same position it was when the clock was initialized. So..the hand should go from 0 degrees to 360 degrees...

The only problem is...I don't know how many degrees I need to rotate the clock by every frame. Like take the 5 seconds for example, how would I know how many degrees the hand needs to rotate based on those 5 seconds, until it has rotated around to 360 degrees?

• With t being your total seconds, and dt being your deltatime this: 360 / 5 * dt might work for you Jan 26, 2012 at 0:37
• Sorry - Metacomment - @Gtoknu, that is an answer. Could you please move write it as such so an answer shows on the question, and to prevent John Doe having to answer it himself with your answer? Jan 26, 2012 at 4:00

What you want to do is something called LERP. Stands for Linear Interpolation, and you can do with the follow:

If you know how many seconds have passed, and what is the total, you might do the follow:

u = total / passedTime

u is your "progress" variable, on a LERP.

So, as your start value is 0 and the final value is 360, we do the following:

current = start + final * u

To your case, we can remap as:

current = 0 + 360 * u

That is, if you want to get it state for every frame. If you just want to know how much it has to be increased depending on how many time passed, you can do the following:

final / total * deltatime

This is a "specific" LERP case, this is how it is disposed:

deltatime is the time passed since last frame, final is the final value to interpolate(360, in the case), total is the total of the input (5 in the case).

360 / 5 * dt
I've forgotten to mention early, but this last formula will only work because the total is given as seconds, and the dt is given as seconds too.