Animation

Technical discussions
Post Reply
gerard12
Posts: 21
Joined: Fri Jul 26, 2013 8:34 am

Animation

Post by gerard12 »

Hello everybody

I decided to share thoughts about animation, which are not mentioned in KC documentation.

The traditional way of animating is to setup a timer and process timer events in a OnTimer() handler. We believe now that a better way to do it is to avoid the timer altogether and simply to run an animation loop at full speed:
while(keepAnimating) DoTheAnimationLoop();

DoTheAnimationLoop() here is supposed to have basically the same code as the OnTimer() handler.

The difference is that there is no timer or events involved. Let’s assume for simplicity that animation is spinning of an object. DoTheAnimationLoop() would do something like myIFrame2.Rotate(angleIncrement, ...) and call KC.UpdateView().

The direct loop for animation is good because it is running the process at full speed, which is what you want. No need for external code executed and no need for guessing what the interval should be. So it is the smoothest possible rendering. This is how games are run.

The only thing which remains to control is the rotation angle angleIncrement. If it is small, rotation smooth but slow. If you increase it everything is faster but jerkier.

A drawback is that the animation blocks all message processing, etc. on the thread. In the eMotion sample, for example, when the simulation is running it is still possible to change the view point and zoom in. I believe, though, it is not very important as animation is supposed to apply heavy load and the user normally focuses its full attention on it. Also modern multi core processors allow running other applications without much trouble.

With the timer animation on the other hand the tricky part is to select time interval as small as possible for animation to be smooth, but it should not be shorter than duration of a single OnTimer() call. If it is the events are queued, possibly indefinitely many, which slows things down.
Gerard

GradyB
Posts: 7
Joined: Sun Jul 28, 2013 12:30 pm

Re: Animation

Post by GradyB »

How can it be stopped such animation?

gerard12
Posts: 21
Joined: Fri Jul 26, 2013 8:34 am

Re: Animation

Post by gerard12 »

Good question
It does need some attention. Frankly we did not have to do it properly yet as the animations we did were short.
You can use keys for example to stop. Inside DoTheAnimationLoop() you could check state of a specified key.

Ideally the loop should be on a separate thread. Or run animation in several increments with stops either to wait for another “Start Animation” or process already pressed button.

Post Reply