From 359c4686045ce89ab40053143051077770a33421 Mon Sep 17 00:00:00 2001 From: Benau <Benau@users.noreply.github.com> Date: Fri, 12 Oct 2018 00:55:37 +0800 Subject: [PATCH] Split track animation with physical or graphical objects --- src/animations/three_d_animation.cpp | 9 ++++++++- src/animations/three_d_animation.hpp | 3 +-- src/tracks/track_object.cpp | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/animations/three_d_animation.cpp b/src/animations/three_d_animation.cpp index a1ab67294..3ff30d893 100644 --- a/src/animations/three_d_animation.cpp +++ b/src/animations/three_d_animation.cpp @@ -70,8 +70,15 @@ ThreeDAnimation::~ThreeDAnimation() // ---------------------------------------------------------------------------- /** Updates position and rotation of this model. Called once per time step. */ -void ThreeDAnimation::updateWithWorldTicks() +void ThreeDAnimation::updateWithWorldTicks(bool has_physics) { + const bool track_object_with_physics = + m_object->getPhysicalObject() != nullptr; + + if ((has_physics && !track_object_with_physics) || + (!has_physics && track_object_with_physics)) + return; + Vec3 xyz = m_object->getPosition(); Vec3 scale = m_object->getScale(); diff --git a/src/animations/three_d_animation.hpp b/src/animations/three_d_animation.hpp index bc42f13d2..1da31c072 100644 --- a/src/animations/three_d_animation.hpp +++ b/src/animations/three_d_animation.hpp @@ -68,13 +68,12 @@ private: */ bool m_important_animation; - public: ThreeDAnimation(const XMLNode &node, TrackObject* object); virtual ~ThreeDAnimation(); virtual void update(float dt) {} // ------------------------------------------------------------------------ - void updateWithWorldTicks(); + void updateWithWorldTicks(bool with_physics); // ------------------------------------------------------------------------ /** 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 f3a7560f4..5bbe2df9c 100644 --- a/src/tracks/track_object.cpp +++ b/src/tracks/track_object.cpp @@ -530,6 +530,7 @@ void TrackObject::updateGraphics(float dt) { if (m_presentation) m_presentation->updateGraphics(dt); if (m_physical_object) m_physical_object->updateGraphics(dt); + if (m_animator) m_animator->updateWithWorldTicks(false/*has_physics*/); } // update // ---------------------------------------------------------------------------- @@ -540,7 +541,7 @@ 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(); + if (m_animator) m_animator->updateWithWorldTicks(true/*has_physics*/); } // update // ----------------------------------------------------------------------------