Browse Source

SceneGraph: don't pass duration in Animable constructor.

It gets lost in the whole parameter list, using protected function
setDuration() instead. Default is `0.0f`, which means infinite duration.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
5e8625bd98
  1. 30
      src/SceneGraph/Animable.h
  2. 2
      src/SceneGraph/Animable.hpp
  3. 12
      src/SceneGraph/Test/AnimableTest.cpp

30
src/SceneGraph/Animable.h

@ -60,8 +60,8 @@ which takes care of running the animations.
First thing is add Animable feature to some object and implement
animationStep(). You can do it conveniently using multiple inheritance (see
@ref scenegraph-features for introduction). You need to pass animation
duration to constructor, animationStep() provides both absolute animation
@ref scenegraph-features for introduction). Override animationStep() to
implement your animation, the function provides both absolute animation
time and time delta. Example:
@code
typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D<>> Object3D;
@ -69,7 +69,8 @@ typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D<>> Scene3D;
class AnimableObject: public Object3D, SceneGraph::Animable3D<> {
public:
AnimableObject(Object* parent = nullptr, SceneGraph::DrawableGroup3D<>* group = nullptr): Object3D(parent), SceneGraph::Animable3D<>(this, 10.0f, group) {
AnimableObject(Object* parent = nullptr, SceneGraph::DrawableGroup3D<>* group = nullptr): Object3D(parent), SceneGraph::Animable3D<>(this, group) {
setDuration(10.0f);
// ...
}
@ -141,15 +142,13 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature<dimension
/**
* @brief Constructor
* @param object %Object this animable belongs to
* @param duration Duration of the animation cycle in seconds. Set to
* 0 for infinite non-repeating animation.
* @param group Group this animable belongs to
*
* Creates stopped non-repeating animation with specified duration,
* Creates stopped non-repeating animation with infinite duration,
* adds the feature to the object and also to group, if specified.
* @see setRepeated(), AnimableGroup::add()
* @see setDuration(), setState(), setRepeated(), AnimableGroup::add()
*/
explicit Animable(AbstractObject<dimensions, T>* object, GLfloat duration, AnimableGroup<dimensions, T>* group = nullptr);
explicit Animable(AbstractObject<dimensions, T>* object, AnimableGroup<dimensions, T>* group = nullptr);
/** @brief Animation duration */
inline GLfloat duration() const { return _duration; }
@ -213,6 +212,19 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature<dimension
const AnimableGroup<dimensions, T>* group() const;
protected:
/**
* @brief Set animation duration
* @return Pointer 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`.
*/
/* Protected so only animation implementer can change it */
inline Animable<dimensions, T>* setDuration(GLfloat duration) {
_duration = duration;
return this;
}
/**
* @brief Perform animation step
* @param time Time from start of the animation
@ -294,7 +306,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature<dimension
inline virtual void animationStopped() {}
private:
const GLfloat _duration;
GLfloat _duration;
GLfloat startTime, pauseTime;
AnimationState previousState;
AnimationState currentState;

2
src/SceneGraph/Animable.hpp

@ -26,7 +26,7 @@
namespace Magnum { namespace SceneGraph {
template<std::uint8_t dimensions, class T> Animable<dimensions, T>::Animable(AbstractObject<dimensions, T>* object, GLfloat duration, AnimableGroup<dimensions, T>* group): AbstractGroupedFeature<dimensions, Animable<dimensions, T>, T>(object, group), _duration(duration), startTime(std::numeric_limits<GLfloat>::infinity()), pauseTime(-std::numeric_limits<GLfloat>::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {}
template<std::uint8_t dimensions, class T> Animable<dimensions, T>::Animable(AbstractObject<dimensions, T>* object, AnimableGroup<dimensions, T>* group): AbstractGroupedFeature<dimensions, Animable<dimensions, T>, T>(object, group), _duration(0.0f), startTime(std::numeric_limits<GLfloat>::infinity()), pauseTime(-std::numeric_limits<GLfloat>::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {}
template<std::uint8_t dimensions, class T> Animable<dimensions, T>* Animable<dimensions, T>::setState(AnimationState state) {
if(currentState == state) return this;

12
src/SceneGraph/Test/AnimableTest.cpp

@ -51,7 +51,9 @@ AnimableTest::AnimableTest() {
void AnimableTest::state() {
class StateTrackingAnimable: public SceneGraph::Animable<3> {
public:
StateTrackingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 1.0f, group) {}
StateTrackingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, group) {
setDuration(1.0f);
}
std::string trackedState;
@ -139,7 +141,8 @@ void AnimableTest::state() {
class OneShotAnimable: public SceneGraph::Animable<3> {
public:
OneShotAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 10.0f, group), time(-1.0f) {
OneShotAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, group), time(-1.0f) {
setDuration(10.0f);
setState(AnimationState::Running);
}
@ -163,7 +166,7 @@ class OneShotAnimable: public SceneGraph::Animable<3> {
void AnimableTest::step() {
class InifiniteAnimable: public SceneGraph::Animable<3> {
public:
InifiniteAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 0.0f, group), time(-1.0f), delta(0.0f) {}
InifiniteAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, group), time(-1.0f), delta(0.0f) {}
GLfloat time, delta;
@ -222,7 +225,8 @@ void AnimableTest::duration() {
void AnimableTest::repeat() {
class RepeatingAnimable: public SceneGraph::Animable<3> {
public:
RepeatingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 10.0f, group), time(-1.0f) {
RepeatingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, group), time(-1.0f) {
setDuration(10.0f);
setState(AnimationState::Running);
setRepeated(true);
}

Loading…
Cancel
Save