View Single Post
Old 02-01-2009, 08:44 PM   #288
rps
Registered
 
Join Date: Oct 2008

Posts: 57
Actually, having thought about it, you don't really want to call trig functions on every refresh cycle, because they're time-consuming, and very expensive (in terms of clock cycles). If I were doing this, I would create an array [0..59] of coordinate positions, representing the positions of the end of the second hand at each whole second. (The other end of the second hand is in the center of the clock, and remains constant.) This table gets initialized on startup; once you've calculated the positions, they don't ever have to be recalculated. On any drawing cycle, the "current second" is determined by reading systemTime.wSecond. For a stuttering second hand, you simply look up "position[curSec]". For a sweep hand, you can calculate the position by reading the milliseconds, and calculating the difference in position between position[cursec] and position[curSec + 1]:

dx = (position[curSec + 1].x - position[cursec].x) * systemTime.wMilliseconds / 1000
position.x = position[curSec].x + dx;

Repeat these two statements for position.y.

This code is fairly simple, it can be done entirely using integer operation (which makes it very efficient) and it's very easy to skip over the millisecond adjustment to convert from a sweep hand to a ticking hand.

I hope you'll reconsider your decision to "never revisit the analog clock code" again.

~Ralph S.
rps is offline   Reply With Quote