Add 3d animation ipo copying to child track objects

This commit is contained in:
Benau 2020-02-28 19:52:23 +08:00
parent 607c6932f0
commit 885aec8020
5 changed files with 34 additions and 14 deletions

View File

@ -61,6 +61,13 @@ AnimationBase::AnimationBase(Ipo *ipo)
calculateAnimationDuration(); calculateAnimationDuration();
} // AnimationBase(Ipo) } // AnimationBase(Ipo)
// ----------------------------------------------------------------------------
AnimationBase::~AnimationBase()
{
for (Ipo* ipo : m_all_ipos)
delete ipo;
} // ~AnimationBase
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void AnimationBase::calculateAnimationDuration() void AnimationBase::calculateAnimationDuration()
{ {
@ -81,7 +88,7 @@ void AnimationBase::calculateAnimationDuration()
void AnimationBase::setInitialTransform(const Vec3 &xyz, void AnimationBase::setInitialTransform(const Vec3 &xyz,
const Vec3 &hpr) const Vec3 &hpr)
{ {
for_var_in(Ipo*, curr, m_all_ipos) for (Ipo* curr : m_all_ipos)
{ {
curr->setInitialTransform(xyz, hpr); curr->setInitialTransform(xyz, hpr);
} }
@ -93,7 +100,7 @@ void AnimationBase::setInitialTransform(const Vec3 &xyz,
void AnimationBase::reset() void AnimationBase::reset()
{ {
m_current_time = 0; m_current_time = 0;
for_var_in(Ipo*, curr, m_all_ipos) for (Ipo* curr : m_all_ipos)
{ {
curr->reset(); curr->reset();
} }
@ -115,7 +122,7 @@ void AnimationBase::update(float dt, Vec3 *xyz, Vec3 *hpr, Vec3 *scale)
assert(!std::isnan(m_current_time)); assert(!std::isnan(m_current_time));
for_var_in (Ipo*, curr, m_all_ipos) for (Ipo* curr : m_all_ipos)
{ {
curr->update(m_current_time, xyz, hpr, scale); curr->update(m_current_time, xyz, hpr, scale);
} }
@ -135,7 +142,7 @@ void AnimationBase::getAt(float time, Vec3 *xyz, Vec3 *hpr, Vec3 *scale)
// Don't do anything if the animation is disabled // Don't do anything if the animation is disabled
if (!m_playing) return; if (!m_playing) return;
for_var_in(Ipo*, curr, m_all_ipos) for (Ipo* curr : m_all_ipos)
{ {
curr->update(time, xyz, hpr, scale); curr->update(time, xyz, hpr, scale);
} }
@ -148,7 +155,7 @@ void AnimationBase::getAt(float time, Vec3 *xyz, Vec3 *hpr, Vec3 *scale)
*/ */
void AnimationBase::getDerivativeAt(float time, Vec3 *xyz) void AnimationBase::getDerivativeAt(float time, Vec3 *xyz)
{ {
for_var_in(Ipo*, curr, m_all_ipos) for (Ipo* curr : m_all_ipos)
{ {
curr->getDerivative(time, xyz); curr->getDerivative(time, xyz);
} }

View File

@ -26,14 +26,11 @@
*/ */
#include <vector> #include <vector>
// Note that ipo.hpp is included here in order that PtrVector<Ipo> can call
// the proper destructor!
#include "animations/ipo.hpp"
#include "utils/ptr_vector.hpp"
#include <algorithm> #include <algorithm>
#include "utils/vec3.hpp"
class Ipo;
class XMLNode; class XMLNode;
/** /**
@ -57,7 +54,7 @@ private:
protected: protected:
/** All IPOs for this animation. */ /** All IPOs for this animation. */
PtrVector<Ipo> m_all_ipos; std::vector<Ipo*> m_all_ipos;
/** True if the animation is currently playing. */ /** True if the animation is currently playing. */
bool m_playing; bool m_playing;
@ -70,7 +67,7 @@ protected:
public: public:
AnimationBase(const XMLNode &node); AnimationBase(const XMLNode &node);
AnimationBase(Ipo *ipo); AnimationBase(Ipo *ipo);
virtual ~AnimationBase() {} virtual ~AnimationBase();
virtual void update(float dt, Vec3 *xyz=NULL, Vec3 *hpr=NULL, virtual void update(float dt, Vec3 *xyz=NULL, Vec3 *hpr=NULL,
Vec3 *scale=NULL); Vec3 *scale=NULL);
virtual void getAt(float time, Vec3 *xyz = NULL, Vec3 *hpr = NULL, virtual void getAt(float time, Vec3 *xyz = NULL, Vec3 *hpr = NULL,

View File

@ -21,6 +21,7 @@
#include <stdio.h> #include <stdio.h>
#include "audio/sfx_base.hpp" #include "audio/sfx_base.hpp"
#include "animations/ipo.hpp"
#include "graphics/material.hpp" #include "graphics/material.hpp"
#include "graphics/material_manager.hpp" #include "graphics/material_manager.hpp"
#include "graphics/mesh_tools.hpp" #include "graphics/mesh_tools.hpp"
@ -118,3 +119,15 @@ void ThreeDAnimation::updateWithWorldTicks(bool has_physics)
m_object->move(xyz.toIrrVector(), hpr, scale.toIrrVector(), true, false); m_object->move(xyz.toIrrVector(), hpr, scale.toIrrVector(), true, false);
} }
} // update } // update
// ----------------------------------------------------------------------------
/** Copying to child process of track object.
*/
ThreeDAnimation* ThreeDAnimation::clone(TrackObject* obj)
{
ThreeDAnimation* animation = new ThreeDAnimation(*this);
animation->m_object = obj;
for (unsigned i = 0; i < m_all_ipos.size(); i++)
animation->m_all_ipos[i] = m_all_ipos[i]->clone();
return animation;
} // clone

View File

@ -81,6 +81,8 @@ public:
bool isExplodeKartObject() const { return m_explode_kart; } bool isExplodeKartObject() const { return m_explode_kart; }
bool isFlattenKartObject() const { return m_flatten_kart; } bool isFlattenKartObject() const { return m_flatten_kart; }
void setPaused(bool mode){ m_is_paused = mode; } void setPaused(bool mode){ m_is_paused = mode; }
// ------------------------------------------------------------------------
ThreeDAnimation* clone(TrackObject* obj);
}; // ThreeDAnimation }; // ThreeDAnimation
#endif #endif

View File

@ -792,7 +792,8 @@ TrackObject* TrackObject::cloneToChild()
to_clone->m_visibility_condition.clear(); to_clone->m_visibility_condition.clear();
to_clone->m_presentation = NULL; to_clone->m_presentation = NULL;
to_clone->m_render_info.reset(); to_clone->m_render_info.reset();
to_clone->m_animator = NULL; if (m_animator)
to_clone->m_animator = m_animator->clone(to_clone);
to_clone->m_parent_library = NULL; to_clone->m_parent_library = NULL;
to_clone->m_movable_children.clear(); to_clone->m_movable_children.clear();
to_clone->m_children.clear(); to_clone->m_children.clear();