Make track object with ipo animation depend on world up ticks
This commit is contained in:
parent
e67f0db7c1
commit
3347cac92d
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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. */
|
||||
|
@ -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
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user