Animation

Everything DG Kernel: Technical discussions and issues
Post Reply
gerard12
Posts: 20
Joined: Tue Jun 18, 2024 6:09 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
Prashant Kande
Posts: 65
Joined: Tue Jun 18, 2024 6:12 am

Re: Animation

Post by Prashant Kande »

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.

Regards
Post Reply