tags:

views:

84

answers:

3

Hi All. My question has a general nature. I would like to ask to you to share some ideas about how do you implement an animation support in your OpenGL application. For example, if we would like in case of the some event fired from the user input, animate a Ball particle on the screen, how do we need organize our code ? :

  1. Set Animation property like a member of Ball particle object ? (That contains a set of matricies to apply to the owner model, delay of between them, is playback animation or not and so on..)
  2. Need to have some central repository that contains a relation between a Ball particle and applied animation to it (I, honestly, would prefer this one). ?

  3. Somethihg else ...?

And after what about a rendering ? How to do it fluid and fast ? (I know this is very context sensitive, but just to give an idea..)

Thank you in advance.

+1  A: 

OpenGL doesn't offer support for animation; you will need to write your own framework (for example using GLX, see this article) or use an existing framework like the ones mentioned here.

Aaron Digulla
I know, and my question actually was, how to organize a code to implement it. Thanks for lnks.
Tigran
+3  A: 

As far as "fluid and fast" goes, you may want to look into various easing equations to apply to your animation interpolation value.

genpfault
+1  A: 

I would define an Animation class, which can implement the following animations:

  • Rotation/translation/scale animation
  • Key frame animation
  • Skinning animation

Of course, one of the animation techniques listed above need some generic access to the Object class.

RotoTranslation animation requires access to the Object model view matrix; KeyFrame animation requires access to the model vertices buffers; Skinning animation requires access to the rendering state of the Object (shader attributes and programs, or vertex attributes using extensions).

Apart skinning, the interpolation of generic values (floats, vector or matrices) shall be implemented, in order to change the values using an interpolation formula (nice those linked by genpfault). So an Interpolator class shall be able to ease the introduction of new interpolation equations.

An Animation class uses a set of Interpolator instances to execute the animation (changing the values to be interpolated). How the values are choosed, accessed and modified (ranges) shall be defined at Object class.

At this point there must be a TimeLine class which defines the time elapsed (which could not be the real one), which trigger Animation instances (or perhaps the single Interpolator instances) making the interpolated values advance the intermediate value.

The Animation instances are queued on the TimeLine class, so it knows which Animation instances are active. The activation could be caused by user input or programmatically using internally generated events. To terminate the Animation execution, the Animation class could define a IsTerminated method is order to be dequeued from the TimeLine instance (perhaps the Animation could loop back the animation to have a continuous animation).


Of course everything depending on your real needs.

In the case the computation of the animation could take long time, you could cache the entire model data and run the animation in a separated thread. Once terminated, the model could be updated blocking the rendering loop.

However, I would consider to inline the animation processing by issuing proper data to shader programs allowing a faster computation, which could enhances system performances.

Luca
Wow, thank you for detailed explanation of your ideas.
Tigran