Re: New from Iain's hack factory



On Mon, Feb 17, 2003 at 10:23:46PM +0000, iain wrote:
> man, 2003-02-17 kl. 22:20 skrev MArk Finlay:
> > This looks pretty cool. But could do with being a bit smoother. It's a
> > bit flickery for my tastes. But cool, yeah, very cool.
> 
> The problem is making it any smoother slows it dow till its actually
> REALLY annoying...
> 

I haven't looked at the patch, but the typical way to do animations is
to base them on total time rather than just doing a timeout. This
keeps the animation as smooth as possible regardless of machine speed
or load. The idea is essentially to drop frames, on a sufficiently
crap machine you'll drop all frames except the last one so end up
without animation.

The way it works is:

 - when you start the animation, save the current time

 - do an iteration of the animation in an idle if you want to use all
   machine resources to be as smooth as you can, in a timeout if you
   want to put a cap on the frame rate

 - in each iteration, get the current time and subtract from the start 
   time, then compute the fraction of total desired animation time:

    animation_percentage = (current - start) / total;

   then your current frame is:  

     n_frames * animation_percentage

   or perhaps for this:     
 
     transparency = min_transparency + max_transparency * percentage

   so you render that frame or that transparency level.

 - be sure you always draw the last frame

That's pretty much it. Should work on all machines. It may still look
choppy on slow machines, but it will look as good as the machine
allows.

Havoc


   



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]