diff --git a/src/animations/animation_base.cpp b/src/animations/animation_base.cpp index 029273cf7..8c4c191a3 100644 --- a/src/animations/animation_base.cpp +++ b/src/animations/animation_base.cpp @@ -46,6 +46,14 @@ AnimationBase::AnimationBase(const XMLNode &node) m_playing = false; } reset(); + + m_animation_duration = -1.0f; + for (const Ipo* currIpo : m_all_ipos) + { + m_animation_duration = std::max(m_animation_duration, + currIpo->getEndTime()); + } + } // AnimationBase // ---------------------------------------------------------------------------- /** Special constructor which takes one IPO (or curve). This is used by the diff --git a/src/animations/animation_base.hpp b/src/animations/animation_base.hpp index 8f5430542..4bd370a85 100644 --- a/src/animations/animation_base.hpp +++ b/src/animations/animation_base.hpp @@ -62,7 +62,9 @@ protected: /** True if the animation is currently playing. */ bool m_playing; - + + float m_animation_duration; + public: AnimationBase(const XMLNode &node); AnimationBase(Ipo *ipo); @@ -85,18 +87,7 @@ public: void setPlaying(bool playing) {m_playing = playing; } // ------------------------------------------------------------------------ - - float getAnimationDuration() const - { - float duration = -1; - - for (const Ipo* currIpo : m_all_ipos) - { - duration = std::max(duration, currIpo->getEndTime()); - } - - return duration; - } + float getAnimationDuration() const { return m_animation_duration; } }; // AnimationBase diff --git a/src/animations/three_d_animation.cpp b/src/animations/three_d_animation.cpp index cbe260d33..5627d0dc0 100644 --- a/src/animations/three_d_animation.cpp +++ b/src/animations/three_d_animation.cpp @@ -69,17 +69,21 @@ ThreeDAnimation::~ThreeDAnimation() // ---------------------------------------------------------------------------- /** Updates position and rotation of this model. Called once per time step. - * \param dt Time since last call. */ -void ThreeDAnimation::update(float dt) +void ThreeDAnimation::updateWithWorldTicks() { Vec3 xyz = m_object->getPosition(); Vec3 scale = m_object->getScale(); - //make the object think no time has passed to pause it's animation - if (m_is_paused)dt = 0; + float position = 0.0f; + if (!m_is_paused) + { + int cur_ticks = World::getWorld()->getTicksSinceStart(); + float cur_time = stk_config->ticks2Time(cur_ticks); + position = fmodf(cur_time, m_animation_duration); + } - AnimationBase::update(dt, &xyz, &m_hpr, &scale); //updates all IPOs + AnimationBase::getAt(position, &xyz, &m_hpr, &scale); //updates all IPOs //m_node->setPosition(xyz.toIrrVector()); //m_node->setScale(scale.toIrrVector()); diff --git a/src/animations/three_d_animation.hpp b/src/animations/three_d_animation.hpp index 4ed22c08f..bc42f13d2 100644 --- a/src/animations/three_d_animation.hpp +++ b/src/animations/three_d_animation.hpp @@ -68,12 +68,13 @@ private: */ bool m_important_animation; - //scene::ISceneNode* m_node; public: ThreeDAnimation(const XMLNode &node, TrackObject* object); virtual ~ThreeDAnimation(); - virtual void update(float dt); + virtual void update(float dt) {} + // ------------------------------------------------------------------------ + void updateWithWorldTicks(); // ------------------------------------------------------------------------ /** Returns true if a collision with this object should * trigger a rescue. */ diff --git a/src/tracks/track_object.cpp b/src/tracks/track_object.cpp index 392388868..58b9636ac 100644 --- a/src/tracks/track_object.cpp +++ b/src/tracks/track_object.cpp @@ -530,25 +530,18 @@ void TrackObject::resetEnabled() */ void TrackObject::updateGraphics(float dt) { - - // FIXME: At this stage neither m_presentation nor m_animator - // have been converted to use separate updateGraphics() calls. - if (m_physical_object) m_physical_object->updateGraphics(dt); - if (m_animator) m_animator->update(dt); - } // update // ---------------------------------------------------------------------------- -/** This updates all only graphical elements. It is only called once per - * rendered frame, not once per time step. +/** This updates once per physics time step. * float dt Time since last rame. */ void TrackObject::update(float dt) { if (m_presentation) m_presentation->update(dt); if (m_physical_object) m_physical_object->update(dt); - + if (m_animator) m_animator->updateWithWorldTicks(); } // update // ----------------------------------------------------------------------------