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;
|
m_playing = false;
|
||||||
}
|
}
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
|
m_animation_duration = -1.0f;
|
||||||
|
for (const Ipo* currIpo : m_all_ipos)
|
||||||
|
{
|
||||||
|
m_animation_duration = std::max(m_animation_duration,
|
||||||
|
currIpo->getEndTime());
|
||||||
|
}
|
||||||
|
|
||||||
} // AnimationBase
|
} // AnimationBase
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Special constructor which takes one IPO (or curve). This is used by the
|
/** Special constructor which takes one IPO (or curve). This is used by the
|
||||||
|
@ -63,6 +63,8 @@ protected:
|
|||||||
/** True if the animation is currently playing. */
|
/** True if the animation is currently playing. */
|
||||||
bool m_playing;
|
bool m_playing;
|
||||||
|
|
||||||
|
float m_animation_duration;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AnimationBase(const XMLNode &node);
|
AnimationBase(const XMLNode &node);
|
||||||
AnimationBase(Ipo *ipo);
|
AnimationBase(Ipo *ipo);
|
||||||
@ -85,18 +87,7 @@ public:
|
|||||||
void setPlaying(bool playing) {m_playing = playing; }
|
void setPlaying(bool playing) {m_playing = playing; }
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
float getAnimationDuration() const { return m_animation_duration; }
|
||||||
float getAnimationDuration() const
|
|
||||||
{
|
|
||||||
float duration = -1;
|
|
||||||
|
|
||||||
for (const Ipo* currIpo : m_all_ipos)
|
|
||||||
{
|
|
||||||
duration = std::max(duration, currIpo->getEndTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
return duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
}; // AnimationBase
|
}; // AnimationBase
|
||||||
|
|
||||||
|
@ -69,17 +69,21 @@ ThreeDAnimation::~ThreeDAnimation()
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Updates position and rotation of this model. Called once per time step.
|
/** 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 xyz = m_object->getPosition();
|
||||||
Vec3 scale = m_object->getScale();
|
Vec3 scale = m_object->getScale();
|
||||||
|
|
||||||
//make the object think no time has passed to pause it's animation
|
float position = 0.0f;
|
||||||
if (m_is_paused)dt = 0;
|
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->setPosition(xyz.toIrrVector());
|
||||||
//m_node->setScale(scale.toIrrVector());
|
//m_node->setScale(scale.toIrrVector());
|
||||||
|
|
||||||
|
@ -68,12 +68,13 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool m_important_animation;
|
bool m_important_animation;
|
||||||
|
|
||||||
//scene::ISceneNode* m_node;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ThreeDAnimation(const XMLNode &node, TrackObject* object);
|
ThreeDAnimation(const XMLNode &node, TrackObject* object);
|
||||||
virtual ~ThreeDAnimation();
|
virtual ~ThreeDAnimation();
|
||||||
virtual void update(float dt);
|
virtual void update(float dt) {}
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
void updateWithWorldTicks();
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns true if a collision with this object should
|
/** Returns true if a collision with this object should
|
||||||
* trigger a rescue. */
|
* trigger a rescue. */
|
||||||
|
@ -530,25 +530,18 @@ void TrackObject::resetEnabled()
|
|||||||
*/
|
*/
|
||||||
void TrackObject::updateGraphics(float dt)
|
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_physical_object) m_physical_object->updateGraphics(dt);
|
||||||
if (m_animator) m_animator->update(dt);
|
|
||||||
|
|
||||||
} // update
|
} // update
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** This updates all only graphical elements. It is only called once per
|
/** This updates once per physics time step.
|
||||||
* rendered frame, not once per time step.
|
|
||||||
* float dt Time since last rame.
|
* float dt Time since last rame.
|
||||||
*/
|
*/
|
||||||
void TrackObject::update(float dt)
|
void TrackObject::update(float dt)
|
||||||
{
|
{
|
||||||
if (m_presentation) m_presentation->update(dt);
|
if (m_presentation) m_presentation->update(dt);
|
||||||
if (m_physical_object) m_physical_object->update(dt);
|
if (m_physical_object) m_physical_object->update(dt);
|
||||||
|
if (m_animator) m_animator->updateWithWorldTicks();
|
||||||
} // update
|
} // update
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user