#include <Magnum/SceneGraph/Animable.h>
template<UnsignedInt dimensions, class T>
Animable class
Animable.
Adds animation feature to object. Each Animable is part of some AnimableGroup, which takes care of running the animations.
Usage
First thing is to add Animable feature to some object and implement animationStep(). You can do it conveniently using multiple inheritance (see Object features for introduction). Override animationStep() to implement your animation, the function provides both absolute animation time and time delta. Example:
typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D> Object3D; typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D> Scene3D; class AnimableObject: public Object3D, public SceneGraph::Animable3D { public: AnimableObject(Object3D* parent = nullptr, SceneGraph::AnimableGroup3D* group = nullptr): Object3D{parent}, SceneGraph::Animable3D{*this, group} { setDuration(10.0f); // ... } private: void animationStep(Float, Float delta) override { rotateX(15.0_degf*delta); // rotate at 15 degrees per second } };
Similarly to Drawable feature, there is no way to just animate all the objects in the scene. You need to create animable group and use it to control given set of animations. You can also use AnimableGroup::
Scene3D scene; SceneGraph::AnimableGroup3D animables; (new AnimableObject(&scene, &animables)) ->setState(SceneGraph::AnimationState::Running); …
Animation step is performed by calling AnimableGroup::
MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} { // ... timeline.start(); } void MyApplication::drawEvent() { animables.step(timeline.previousFrameTime(), timeline.previousFrameDuration()); // ... timeline.nextFrame(); }
Using multiple animable groups to improve performance
AnimableGroup is optimized for case when no animation is running — it just puts itself to rest and waits until some animation changes its state to AnimationState::
Explicit template specializations
The following specializations are explicitly compiled into SceneGraph library. For other specializations (e.g. using Double type) you have to use Animable.hpp implementation file to avoid linker errors. See also Template headers and implementation files for more information.
Base classes
-
template<UnsignedInt dimensions, class Derived, class T>class AbstractGroupedFeature<dimensions, Animable<dimensions, T>, T>
- Base for grouped features.
Constructors, destructors, conversion operators
- Animable(AbstractObject<dimensions, T>& object, AnimableGroup<dimensions, T>* group = nullptr) explicit
- Constructor.
Public functions
- auto duration() const -> Float
- Animation duration.
- auto state() const -> AnimationState
- Animation state.
- auto setState(AnimationState state) -> Animable<dimensions, T>&
- Set animation state.
- auto isRepeated() const -> bool
- Whether the animation is repeated.
- auto setRepeated(bool repeated) -> Animable<dimensions, T>&
- Enable/disable repeated animation.
- auto repeatCount() const -> UnsignedShort
- Repeat count.
- auto setRepeatCount(UnsignedShort count) -> Animable<dimensions, T>&
- Set repeat count.
- auto animables() -> AnimableGroup<dimensions, T>*
- Group containing this animable.
- auto animables() const -> const AnimableGroup<dimensions, T>*
Protected functions
- auto setDuration(Float duration) -> Animable<dimensions, T>&
- Set animation duration.
- void animationStep(Float time, Float delta) pure virtual
- Perform animation step.
- void animationStarted() virtual
- Action on animation start.
- void animationPaused() virtual
- Action on animation pause.
- void animationResumed() virtual
- Action on animation resume.
- void animationStopped() virtual
- Action on animation stop.
Function documentation
template<UnsignedInt dimensions, class T>
Magnum:: SceneGraph:: Animable<dimensions, T>:: Animable(AbstractObject<dimensions, T>& object,
AnimableGroup<dimensions, T>* group = nullptr) explicit
Constructor.
Parameters | |
---|---|
object | Object this animable belongs to |
group | Group this animable belongs to |
Creates stopped non-repeating animation with infinite duration, adds the feature to the object and also to group, if specified.
template<UnsignedInt dimensions, class T>
Animable<dimensions, T>& Magnum:: SceneGraph:: Animable<dimensions, T>:: setState(AnimationState state)
Set animation state.
Returns | Reference to self (for method chaining) |
---|
Note that changing state from AnimationState::
template<UnsignedInt dimensions, class T>
bool Magnum:: SceneGraph:: Animable<dimensions, T>:: isRepeated() const
Whether the animation is repeated.
template<UnsignedInt dimensions, class T>
Animable<dimensions, T>& Magnum:: SceneGraph:: Animable<dimensions, T>:: setRepeated(bool repeated)
Enable/disable repeated animation.
Returns | Reference to self (for method chaining) |
---|
Default is false
.
template<UnsignedInt dimensions, class T>
UnsignedShort Magnum:: SceneGraph:: Animable<dimensions, T>:: repeatCount() const
Repeat count.
template<UnsignedInt dimensions, class T>
Animable<dimensions, T>& Magnum:: SceneGraph:: Animable<dimensions, T>:: setRepeatCount(UnsignedShort count)
Set repeat count.
Returns | Reference to self (for method chaining) |
---|
Has effect only if repeated animation is enabled. 0
means infinitely repeated animation. Default is 0
.
template<UnsignedInt dimensions, class T>
AnimableGroup<dimensions, T>* Magnum:: SceneGraph:: Animable<dimensions, T>:: animables()
Group containing this animable.
If the animable doesn't belong to any group, returns nullptr
.
template<UnsignedInt dimensions, class T>
const AnimableGroup<dimensions, T>* Magnum:: SceneGraph:: Animable<dimensions, T>:: animables() const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<UnsignedInt dimensions, class T>
Animable<dimensions, T>& Magnum:: SceneGraph:: Animable<dimensions, T>:: setDuration(Float duration) protected
Set animation duration.
Returns | Reference to self (for method chaining) |
---|
Sets duration of the animation cycle in seconds. Set to 0.0f
for infinite non-repeating animation. Default is 0.0f
.
template<UnsignedInt dimensions, class T>
void Magnum:: SceneGraph:: Animable<dimensions, T>:: animationStep(Float time,
Float delta) pure virtual protected
Perform animation step.
Parameters | |
---|---|
time | Time from start of the animation |
delta | Time delta for current frame |
This function is periodically called from AnimableGroup::
If the animation is resumed from AnimationState::time
continuing from the point when it was paused. If the animation is resumed from AnimationState::time
starts with zero.
template<UnsignedInt dimensions, class T>
void Magnum:: SceneGraph:: Animable<dimensions, T>:: animationStarted() virtual protected
Action on animation start.
Called from AnimableGroup::
Default implementation does nothing.
template<UnsignedInt dimensions, class T>
void Magnum:: SceneGraph:: Animable<dimensions, T>:: animationPaused() virtual protected
Action on animation pause.
Called from AnimableGroup::
Default implementation does nothing.
template<UnsignedInt dimensions, class T>
void Magnum:: SceneGraph:: Animable<dimensions, T>:: animationResumed() virtual protected
Action on animation resume.
Called from AnimableGroup::
Default implementation does nothing.
template<UnsignedInt dimensions, class T>
void Magnum:: SceneGraph:: Animable<dimensions, T>:: animationStopped() virtual protected
Action on animation stop.
Called from AnimableGroup::
You may want to use this function to properly finish the animation in case the framerate is not high enough to have animationStep() called enough times. Default implementation does nothing.