Commit 7d8307b1 authored by cutealien's avatar cutealien

- ISceneNodeAnimators can now be disabled and paused.

- Moved StartTime in the ISceneNodeAnimators class instead of derived classes.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4767 dfc29bdd-3216-0410-991c-e03cc46cb475
parent c11d706e
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- ISceneNodeAnimators can now be disabled and paused.
- Maya camera no longer get's stuck in "rotating" state when a mouse-up event is lost (thx @ JLouisB for reporting). - Maya camera no longer get's stuck in "rotating" state when a mouse-up event is lost (thx @ JLouisB for reporting).
- Focus behavior of IGUIEnvironment now controllable (right-click focus, mouse-over focus). Disabled elements no longer get the focus unless users enforce it. - Focus behavior of IGUIEnvironment now controllable (right-click focus, mouse-over focus). Disabled elements no longer get the focus unless users enforce it.
- Buttons can now now have 7 more image-states, 1 more sprite-state and the sprites are now scaleable. - Buttons can now now have 7 more image-states, 1 more sprite-state and the sprites are now scaleable.
......
...@@ -119,8 +119,11 @@ namespace scene ...@@ -119,8 +119,11 @@ namespace scene
// node without the iterator becoming invalid // node without the iterator becoming invalid
ISceneNodeAnimator* anim = *ait; ISceneNodeAnimator* anim = *ait;
++ait; ++ait;
if ( anim->isEnabled() )
{
anim->animateNode(this, timeMs); anim->animateNode(this, timeMs);
} }
}
// update absolute position // update absolute position
updateAbsolutePosition(); updateAbsolutePosition();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "vector3d.h" #include "vector3d.h"
#include "ESceneNodeAnimatorTypes.h" #include "ESceneNodeAnimatorTypes.h"
#include "IAttributeExchangingObject.h" #include "IAttributeExchangingObject.h"
#include "IAttributes.h"
#include "IEventReceiver.h" #include "IEventReceiver.h"
namespace irr namespace irr
...@@ -30,6 +31,10 @@ namespace scene ...@@ -30,6 +31,10 @@ namespace scene
class ISceneNodeAnimator : public io::IAttributeExchangingObject, public IEventReceiver class ISceneNodeAnimator : public io::IAttributeExchangingObject, public IEventReceiver
{ {
public: public:
ISceneNodeAnimator() : IsEnabled(true), PauseTimeSum(0), PauseTimeStart(0), StartTime(0)
{
}
//! Animates a scene node. //! Animates a scene node.
/** \param node Node to animate. /** \param node Node to animate.
\param timeMs Current time in milli seconds. */ \param timeMs Current time in milli seconds. */
...@@ -71,21 +76,90 @@ namespace scene ...@@ -71,21 +76,90 @@ namespace scene
//! Reset a time-based movement by changing the starttime. //! Reset a time-based movement by changing the starttime.
/** By default most animators start on object creation. /** By default most animators start on object creation.
Commonly you will use irr::ITimer::getTime().
This value is ignored by animators which don't work with a starttime. This value is ignored by animators which don't work with a starttime.
CSceneNodeAnimatorRotation currently overwrites this value constantly (might be changed in the future). Known problems: CSceneNodeAnimatorRotation currently overwrites this value constantly (might be changed in the future).
\param time Commonly you will use irr::ITimer::getTime().
\param resetPauseTime Reset internal pause time for enabling/diabling animators as well
*/ */
virtual void setStartTime(u32 time) virtual void setStartTime(u32 time, bool resetPauseTime=true)
{
StartTime = time;
if ( resetPauseTime )
{ {
PauseTimeStart = 0;
PauseTimeSum = 0;
}
} }
//! Get the starttime. //! Get the starttime.
/** This will return 0 for by animators which don't work with a starttime. */ /** This will return 0 for by animators which don't work with a starttime unless a starttime was manually set */
virtual irr::u32 getStartTime() const virtual irr::u32 getStartTime() const
{ {
return 0; return StartTime;
}
//! Sets the enabled state of this element.
/**
\param enabled When set to false ISceneNodes will not update the animator anymore.
Animators themself usually don't care. So manual calls to animateNode still work.
\param timeNow When set to values > 0 on enabling and disabling an internal timer will be increased by the time disabled time.
Animator decide themself how to handle that timer, but generally setting it will allow you to pause an animator, so it
will continue at the same position when you enable it again. To use that pass irr::ITimer::getTime() as value.
Animators with no timers will just ignore this.
*/
virtual void setEnabled(bool enabled, u32 timeNow=0)
{
if ( enabled == IsEnabled )
return;
IsEnabled = enabled;
if ( enabled )
{
if ( timeNow > 0 && PauseTimeStart > 0 )
PauseTimeSum += timeNow-PauseTimeStart;
}
else
{
PauseTimeStart = timeNow;
}
}
virtual bool isEnabled() const
{
return IsEnabled;
}
//! Writes attributes of the scene node animator.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const _IRR_OVERRIDE_
{
out->addBool("IsEnabled", IsEnabled);
// timers not serialized as they usually depend on system-time which is different on each application start.
}
//! Reads attributes of the scene node animator.
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_
{
IsEnabled = in->getAttributeAsBool("IsEnabled", IsEnabled);
PauseTimeSum = 0;
PauseTimeStart = 0;
}
protected:
/** This method can be used by clone() implementations of
derived classes
\param toCopyFrom The animator from which the values are copied */
void cloneMembers(const ISceneNodeAnimator* toCopyFrom)
{
IsEnabled = toCopyFrom->IsEnabled;
PauseTimeSum = toCopyFrom->IsEnabled;
PauseTimeStart = toCopyFrom->PauseTimeStart;
StartTime = toCopyFrom->StartTime;
} }
bool IsEnabled; //! Only enabled animators are updated
u32 PauseTimeSum; //! Sum up time which the animator was disabled
u32 PauseTimeStart; //! Last time setEnabled(false) was called with a timer > 0
u32 StartTime; //! Used by animators which are time-based, ignored otherwise.
}; };
......
...@@ -427,7 +427,7 @@ void CParticleSystemSceneNode::doParticleSystem(u32 time) ...@@ -427,7 +427,7 @@ void CParticleSystemSceneNode::doParticleSystem(u32 time)
if (newParticles && array) if (newParticles && array)
{ {
s32 j=Particles.size(); s32 j=Particles.size();
if (newParticles > 16250-j) if (newParticles > 16250-j) // avoid having more than 64k vertices in the scenenode
newParticles=16250-j; newParticles=16250-j;
Particles.set_used(j+newParticles); Particles.set_used(j+newParticles);
for (s32 i=j; i<j+newParticles; ++i) for (s32 i=j; i<j+newParticles; ++i)
......
...@@ -345,6 +345,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorCameraFPS::createClone(ISceneNode* node, I ...@@ -345,6 +345,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorCameraFPS::createClone(ISceneNode* node, I
CSceneNodeAnimatorCameraFPS * newAnimator = CSceneNodeAnimatorCameraFPS * newAnimator =
new CSceneNodeAnimatorCameraFPS(CursorControl, RotateSpeed, MoveSpeed, JumpSpeed, new CSceneNodeAnimatorCameraFPS(CursorControl, RotateSpeed, MoveSpeed, JumpSpeed,
0, 0, NoVerticalMovement); 0, 0, NoVerticalMovement);
newAnimator->cloneMembers(this);
newAnimator->setKeyMap(KeyMap); newAnimator->setKeyMap(KeyMap);
return newAnimator; return newAnimator;
} }
......
...@@ -314,6 +314,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorCameraMaya::createClone(ISceneNode* node, ...@@ -314,6 +314,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorCameraMaya::createClone(ISceneNode* node,
{ {
CSceneNodeAnimatorCameraMaya * newAnimator = CSceneNodeAnimatorCameraMaya * newAnimator =
new CSceneNodeAnimatorCameraMaya(CursorControl, RotateSpeed, ZoomSpeed, TranslateSpeed); new CSceneNodeAnimatorCameraMaya(CursorControl, RotateSpeed, ZoomSpeed, TranslateSpeed);
newAnimator->cloneMembers(this);
return newAnimator; return newAnimator;
} }
......
...@@ -243,6 +243,8 @@ void CSceneNodeAnimatorCollisionResponse::setNode(ISceneNode* node) ...@@ -243,6 +243,8 @@ void CSceneNodeAnimatorCollisionResponse::setNode(ISceneNode* node)
//! Writes attributes of the scene node animator. //! Writes attributes of the scene node animator.
void CSceneNodeAnimatorCollisionResponse::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const void CSceneNodeAnimatorCollisionResponse::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{ {
ISceneNodeAnimatorCollisionResponse::serializeAttributes(out, options);
out->addVector3d("Radius", Radius); out->addVector3d("Radius", Radius);
out->addVector3d("Gravity", Gravity); out->addVector3d("Gravity", Gravity);
out->addVector3d("Translation", Translation); out->addVector3d("Translation", Translation);
...@@ -253,10 +255,12 @@ void CSceneNodeAnimatorCollisionResponse::serializeAttributes(io::IAttributes* o ...@@ -253,10 +255,12 @@ void CSceneNodeAnimatorCollisionResponse::serializeAttributes(io::IAttributes* o
//! Reads attributes of the scene node animator. //! Reads attributes of the scene node animator.
void CSceneNodeAnimatorCollisionResponse::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) void CSceneNodeAnimatorCollisionResponse::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{ {
Radius = in->getAttributeAsVector3d("Radius"); ISceneNodeAnimatorCollisionResponse::deserializeAttributes(in, options);
Gravity = in->getAttributeAsVector3d("Gravity");
Translation = in->getAttributeAsVector3d("Translation"); Radius = in->getAttributeAsVector3d("Radius", Radius);
AnimateCameraTarget = in->getAttributeAsBool("AnimateCameraTarget"); Gravity = in->getAttributeAsVector3d("Gravity", Gravity);
Translation = in->getAttributeAsVector3d("Translation", Translation);
AnimateCameraTarget = in->getAttributeAsBool("AnimateCameraTarget", AnimateCameraTarget);
} }
...@@ -267,7 +271,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorCollisionResponse::createClone(ISceneNode* ...@@ -267,7 +271,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorCollisionResponse::createClone(ISceneNode*
CSceneNodeAnimatorCollisionResponse * newAnimator = CSceneNodeAnimatorCollisionResponse * newAnimator =
new CSceneNodeAnimatorCollisionResponse(newManager, World, Object, Radius, new CSceneNodeAnimatorCollisionResponse(newManager, World, Object, Radius,
(Gravity * 1000.0f), Translation, SlidingSpeed); (Gravity * 1000.0f), Translation, SlidingSpeed);
newAnimator->cloneMembers(this);
return newAnimator; return newAnimator;
} }
......
...@@ -24,7 +24,7 @@ CSceneNodeAnimatorDelete::CSceneNodeAnimatorDelete(ISceneManager* manager, u32 t ...@@ -24,7 +24,7 @@ CSceneNodeAnimatorDelete::CSceneNodeAnimatorDelete(ISceneManager* manager, u32 t
//! animates a scene node //! animates a scene node
void CSceneNodeAnimatorDelete::animateNode(ISceneNode* node, u32 timeMs) void CSceneNodeAnimatorDelete::animateNode(ISceneNode* node, u32 timeMs)
{ {
if (timeMs > FinishTime) if (timeMs > FinishTime+PauseTimeSum)
{ {
HasFinished = true; HasFinished = true;
if(node && SceneManager) if(node && SceneManager)
...@@ -44,6 +44,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorDelete::createClone(ISceneNode* node, ISce ...@@ -44,6 +44,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorDelete::createClone(ISceneNode* node, ISce
CSceneNodeAnimatorDelete* newAnimator = CSceneNodeAnimatorDelete* newAnimator =
new CSceneNodeAnimatorDelete(newManager, FinishTime); new CSceneNodeAnimatorDelete(newManager, FinishTime);
newAnimator->cloneMembers(this);
return newAnimator; return newAnimator;
} }
......
...@@ -15,11 +15,14 @@ CSceneNodeAnimatorFlyCircle::CSceneNodeAnimatorFlyCircle(u32 time, ...@@ -15,11 +15,14 @@ CSceneNodeAnimatorFlyCircle::CSceneNodeAnimatorFlyCircle(u32 time,
const core::vector3df& center, f32 radius, f32 speed, const core::vector3df& center, f32 radius, f32 speed,
const core::vector3df& direction, f32 radiusEllipsoid) const core::vector3df& direction, f32 radiusEllipsoid)
: Center(center), Direction(direction), Radius(radius), : Center(center), Direction(direction), Radius(radius),
RadiusEllipsoid(radiusEllipsoid), Speed(speed), StartTime(time) RadiusEllipsoid(radiusEllipsoid), Speed(speed)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CSceneNodeAnimatorFlyCircle"); setDebugName("CSceneNodeAnimatorFlyCircle");
#endif #endif
StartTime = time;
init(); init();
} }
...@@ -45,10 +48,10 @@ void CSceneNodeAnimatorFlyCircle::animateNode(ISceneNode* node, u32 timeMs) ...@@ -45,10 +48,10 @@ void CSceneNodeAnimatorFlyCircle::animateNode(ISceneNode* node, u32 timeMs)
f32 time; f32 time;
// Check for the condition where the StartTime is in the future. // Check for the condition where the StartTime is in the future.
if(StartTime > timeMs) if(StartTime+PauseTimeSum > timeMs)
time = ((s32)timeMs - (s32)StartTime) * Speed; time = ((s32)timeMs - (s32)(StartTime+PauseTimeSum)) * Speed;
else else
time = (timeMs-StartTime) * Speed; time = (timeMs-(StartTime+PauseTimeSum)) * Speed;
// node->setPosition(Center + Radius * ((VecU*cosf(time)) + (VecV*sinf(time)))); // node->setPosition(Center + Radius * ((VecU*cosf(time)) + (VecV*sinf(time))));
f32 r2 = RadiusEllipsoid == 0.f ? Radius : RadiusEllipsoid; f32 r2 = RadiusEllipsoid == 0.f ? Radius : RadiusEllipsoid;
...@@ -59,6 +62,8 @@ void CSceneNodeAnimatorFlyCircle::animateNode(ISceneNode* node, u32 timeMs) ...@@ -59,6 +62,8 @@ void CSceneNodeAnimatorFlyCircle::animateNode(ISceneNode* node, u32 timeMs)
//! Writes attributes of the scene node animator. //! Writes attributes of the scene node animator.
void CSceneNodeAnimatorFlyCircle::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const void CSceneNodeAnimatorFlyCircle::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{ {
ISceneNodeAnimator::serializeAttributes(out, options);
out->addVector3d("Center", Center); out->addVector3d("Center", Center);
out->addFloat("Radius", Radius); out->addFloat("Radius", Radius);
out->addFloat("Speed", Speed); out->addFloat("Speed", Speed);
...@@ -70,6 +75,8 @@ void CSceneNodeAnimatorFlyCircle::serializeAttributes(io::IAttributes* out, io:: ...@@ -70,6 +75,8 @@ void CSceneNodeAnimatorFlyCircle::serializeAttributes(io::IAttributes* out, io::
//! Reads attributes of the scene node animator. //! Reads attributes of the scene node animator.
void CSceneNodeAnimatorFlyCircle::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) void CSceneNodeAnimatorFlyCircle::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{ {
ISceneNodeAnimator::deserializeAttributes(in, options);
Center = in->getAttributeAsVector3d("Center"); Center = in->getAttributeAsVector3d("Center");
Radius = in->getAttributeAsFloat("Radius"); Radius = in->getAttributeAsFloat("Radius");
Speed = in->getAttributeAsFloat("Speed"); Speed = in->getAttributeAsFloat("Speed");
...@@ -89,6 +96,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorFlyCircle::createClone(ISceneNode* node, I ...@@ -89,6 +96,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorFlyCircle::createClone(ISceneNode* node, I
{ {
CSceneNodeAnimatorFlyCircle * newAnimator = CSceneNodeAnimatorFlyCircle * newAnimator =
new CSceneNodeAnimatorFlyCircle(StartTime, Center, Radius, Speed, Direction, RadiusEllipsoid); new CSceneNodeAnimatorFlyCircle(StartTime, Center, Radius, Speed, Direction, RadiusEllipsoid);
newAnimator->cloneMembers(this);
return newAnimator; return newAnimator;
} }
......
...@@ -39,18 +39,6 @@ namespace scene ...@@ -39,18 +39,6 @@ namespace scene
this. */ this. */
virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_; virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_;
//! Reset a time-based movement by changing the starttime.
virtual void setStartTime(u32 time) _IRR_OVERRIDE_
{
StartTime = time;
}
//! Get the starttime.
virtual irr::u32 getStartTime() const _IRR_OVERRIDE_
{
return StartTime;
}
private: private:
// do some initial calculations // do some initial calculations
void init(); void init();
...@@ -65,7 +53,6 @@ namespace scene ...@@ -65,7 +53,6 @@ namespace scene
f32 Radius; f32 Radius;
f32 RadiusEllipsoid; f32 RadiusEllipsoid;
f32 Speed; f32 Speed;
u32 StartTime;
}; };
......
...@@ -15,13 +15,15 @@ CSceneNodeAnimatorFlyStraight::CSceneNodeAnimatorFlyStraight(const core::vector3 ...@@ -15,13 +15,15 @@ CSceneNodeAnimatorFlyStraight::CSceneNodeAnimatorFlyStraight(const core::vector3
const core::vector3df& endPoint, u32 timeForWay, const core::vector3df& endPoint, u32 timeForWay,
bool loop, u32 now, bool pingpong) bool loop, u32 now, bool pingpong)
: ISceneNodeAnimatorFinishing(now + timeForWay), : ISceneNodeAnimatorFinishing(now + timeForWay),
Start(startPoint), End(endPoint), TimeFactor(0.0f), StartTime(now), Start(startPoint), End(endPoint), TimeFactor(0.0f),
TimeForWay(timeForWay), Loop(loop), PingPong(pingpong) TimeForWay(timeForWay), Loop(loop), PingPong(pingpong)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CSceneNodeAnimatorFlyStraight"); setDebugName("CSceneNodeAnimatorFlyStraight");
#endif #endif
StartTime = now;
recalculateIntermediateValues(); recalculateIntermediateValues();
} }
...@@ -40,7 +42,7 @@ void CSceneNodeAnimatorFlyStraight::animateNode(ISceneNode* node, u32 timeMs) ...@@ -40,7 +42,7 @@ void CSceneNodeAnimatorFlyStraight::animateNode(ISceneNode* node, u32 timeMs)
if (!node) if (!node)
return; return;
u32 t = (timeMs-StartTime); u32 t = (timeMs-(StartTime+PauseTimeSum));
core::vector3df pos; core::vector3df pos;
...@@ -77,6 +79,8 @@ void CSceneNodeAnimatorFlyStraight::animateNode(ISceneNode* node, u32 timeMs) ...@@ -77,6 +79,8 @@ void CSceneNodeAnimatorFlyStraight::animateNode(ISceneNode* node, u32 timeMs)
//! Writes attributes of the scene node animator. //! Writes attributes of the scene node animator.
void CSceneNodeAnimatorFlyStraight::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const void CSceneNodeAnimatorFlyStraight::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{ {
ISceneNodeAnimatorFinishing::serializeAttributes(out, options);
out->addVector3d("Start", Start); out->addVector3d("Start", Start);
out->addVector3d("End", End); out->addVector3d("End", End);
out->addInt("TimeForWay", TimeForWay); out->addInt("TimeForWay", TimeForWay);
...@@ -88,6 +92,8 @@ void CSceneNodeAnimatorFlyStraight::serializeAttributes(io::IAttributes* out, io ...@@ -88,6 +92,8 @@ void CSceneNodeAnimatorFlyStraight::serializeAttributes(io::IAttributes* out, io
//! Reads attributes of the scene node animator. //! Reads attributes of the scene node animator.
void CSceneNodeAnimatorFlyStraight::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) void CSceneNodeAnimatorFlyStraight::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{ {
ISceneNodeAnimatorFinishing::deserializeAttributes(in, options);
Start = in->getAttributeAsVector3d("Start"); Start = in->getAttributeAsVector3d("Start");
End = in->getAttributeAsVector3d("End"); End = in->getAttributeAsVector3d("End");
TimeForWay = in->getAttributeAsInt("TimeForWay"); TimeForWay = in->getAttributeAsInt("TimeForWay");
...@@ -102,6 +108,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorFlyStraight::createClone(ISceneNode* node, ...@@ -102,6 +108,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorFlyStraight::createClone(ISceneNode* node,
{ {
CSceneNodeAnimatorFlyStraight * newAnimator = CSceneNodeAnimatorFlyStraight * newAnimator =
new CSceneNodeAnimatorFlyStraight(Start, End, TimeForWay, Loop, StartTime, PingPong); new CSceneNodeAnimatorFlyStraight(Start, End, TimeForWay, Loop, StartTime, PingPong);
newAnimator->cloneMembers(this);
return newAnimator; return newAnimator;
} }
......
...@@ -38,19 +38,6 @@ namespace scene ...@@ -38,19 +38,6 @@ namespace scene
(IReferenceCounted::drop()) the returned pointer after calling this. */ (IReferenceCounted::drop()) the returned pointer after calling this. */
virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_; virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_;
//! Reset a time-based movement by changing the starttime.
virtual void setStartTime(u32 time) _IRR_OVERRIDE_
{
StartTime = time;
}
//! Get the starttime.
virtual irr::u32 getStartTime() const _IRR_OVERRIDE_
{
return StartTime;
}
private: private:
void recalculateIntermediateValues(); void recalculateIntermediateValues();
...@@ -59,7 +46,6 @@ namespace scene ...@@ -59,7 +46,6 @@ namespace scene
core::vector3df End; core::vector3df End;
core::vector3df Vector; core::vector3df Vector;
f32 TimeFactor; f32 TimeFactor;
u32 StartTime;
u32 TimeForWay; u32 TimeForWay;
bool Loop; bool Loop;
bool PingPong; bool PingPong;
......
...@@ -14,12 +14,14 @@ namespace scene ...@@ -14,12 +14,14 @@ namespace scene
CSceneNodeAnimatorFollowSpline::CSceneNodeAnimatorFollowSpline(u32 time, CSceneNodeAnimatorFollowSpline::CSceneNodeAnimatorFollowSpline(u32 time,
const core::array<core::vector3df>& points, f32 speed, const core::array<core::vector3df>& points, f32 speed,
f32 tightness, bool loop, bool pingpong) f32 tightness, bool loop, bool pingpong)
: ISceneNodeAnimatorFinishing(0), Points(points), Speed(speed), Tightness(tightness), StartTime(time) : ISceneNodeAnimatorFinishing(0), Points(points), Speed(speed), Tightness(tightness)
, Loop(loop), PingPong(pingpong) , Loop(loop), PingPong(pingpong)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CSceneNodeAnimatorFollowSpline"); setDebugName("CSceneNodeAnimatorFollowSpline");
#endif #endif
StartTime = time;
} }
...@@ -44,7 +46,7 @@ void CSceneNodeAnimatorFollowSpline::animateNode(ISceneNode* node, u32 timeMs) ...@@ -44,7 +46,7 @@ void CSceneNodeAnimatorFollowSpline::animateNode(ISceneNode* node, u32 timeMs)
} }
if (pSize==1) if (pSize==1)
{ {
if ( timeMs > StartTime ) if ( timeMs > (StartTime+PauseTimeSum) )
{ {
node->setPosition(Points[0]); node->setPosition(Points[0]);
if ( !Loop ) if ( !Loop )
...@@ -53,7 +55,7 @@ void CSceneNodeAnimatorFollowSpline::animateNode(ISceneNode* node, u32 timeMs) ...@@ -53,7 +55,7 @@ void CSceneNodeAnimatorFollowSpline::animateNode(ISceneNode* node, u32 timeMs)
return; return;
} }
const f32 dt = ( (timeMs-StartTime) * Speed * 0.001f ); const f32 dt = ( (timeMs-(StartTime+PauseTimeSum)) * Speed * 0.001f );
const s32 unwrappedIdx = core::floor32( dt ); const s32 unwrappedIdx = core::floor32( dt );
if ( !Loop && unwrappedIdx >= (s32)pSize-1 ) if ( !Loop && unwrappedIdx >= (s32)pSize-1 )
{ {
...@@ -91,6 +93,8 @@ void CSceneNodeAnimatorFollowSpline::animateNode(ISceneNode* node, u32 timeMs) ...@@ -91,6 +93,8 @@ void CSceneNodeAnimatorFollowSpline::animateNode(ISceneNode* node, u32 timeMs)
//! Writes attributes of the scene node animator. //! Writes attributes of the scene node animator.
void CSceneNodeAnimatorFollowSpline::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const void CSceneNodeAnimatorFollowSpline::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{ {
ISceneNodeAnimatorFinishing::serializeAttributes(out, options);
out->addFloat("Speed", Speed); out->addFloat("Speed", Speed);
out->addFloat("Tightness", Tightness); out->addFloat("Tightness", Tightness);
out->addBool("Loop", Loop); out->addBool("Loop", Loop);
...@@ -118,6 +122,8 @@ void CSceneNodeAnimatorFollowSpline::serializeAttributes(io::IAttributes* out, i ...@@ -118,6 +122,8 @@ void CSceneNodeAnimatorFollowSpline::serializeAttributes(io::IAttributes* out, i
//! Reads attributes of the scene node animator. //! Reads attributes of the scene node animator.
void CSceneNodeAnimatorFollowSpline::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) void CSceneNodeAnimatorFollowSpline::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{ {
ISceneNodeAnimatorFinishing::deserializeAttributes(in, options);
Speed = in->getAttributeAsFloat("Speed"); Speed = in->getAttributeAsFloat("Speed");
Tightness = in->getAttributeAsFloat("Tightness"); Tightness = in->getAttributeAsFloat("Tightness");
Loop = in->getAttributeAsBool("Loop"); Loop = in->getAttributeAsBool("Loop");
...@@ -151,6 +157,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorFollowSpline::createClone(ISceneNode* node ...@@ -151,6 +157,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorFollowSpline::createClone(ISceneNode* node
{ {
CSceneNodeAnimatorFollowSpline * newAnimator = CSceneNodeAnimatorFollowSpline * newAnimator =
new CSceneNodeAnimatorFollowSpline(StartTime, Points, Speed, Tightness); new CSceneNodeAnimatorFollowSpline(StartTime, Points, Speed, Tightness);
newAnimator->cloneMembers(this);
return newAnimator; return newAnimator;
} }
......
...@@ -42,18 +42,6 @@ namespace scene ...@@ -42,18 +42,6 @@ namespace scene
this. */ this. */
virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_; virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_;
//! Reset a time-based movement by changing the starttime.
virtual void setStartTime(u32 time) _IRR_OVERRIDE_
{
StartTime = time;
}
//! Get the starttime.
virtual irr::u32 getStartTime() const _IRR_OVERRIDE_
{
return StartTime;
}
protected: protected:
//! clamps a the value idx to fit into range 0..size-1 //! clamps a the value idx to fit into range 0..size-1
...@@ -62,7 +50,6 @@ namespace scene ...@@ -62,7 +50,6 @@ namespace scene
core::array< core::vector3df > Points; core::array< core::vector3df > Points;
f32 Speed; f32 Speed;
f32 Tightness; f32 Tightness;
u32 StartTime;
bool Loop; bool Loop;
bool PingPong; bool PingPong;
}; };
......
...@@ -12,11 +12,13 @@ namespace scene ...@@ -12,11 +12,13 @@ namespace scene
//! constructor //! constructor
CSceneNodeAnimatorRotation::CSceneNodeAnimatorRotation(u32 time, const core::vector3df& rotation) CSceneNodeAnimatorRotation::CSceneNodeAnimatorRotation(u32 time, const core::vector3df& rotation)
: Rotation(rotation), StartTime(time) : Rotation(rotation)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CSceneNodeAnimatorRotation"); setDebugName("CSceneNodeAnimatorRotation");
#endif #endif
StartTime = time;
} }
...@@ -48,6 +50,8 @@ void CSceneNodeAnimatorRotation::animateNode(ISceneNode* node, u32 timeMs) ...@@ -48,6 +50,8 @@ void CSceneNodeAnimatorRotation::animateNode(ISceneNode* node, u32 timeMs)
//! Writes attributes of the scene node animator. //! Writes attributes of the scene node animator.
void CSceneNodeAnimatorRotation::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const void CSceneNodeAnimatorRotation::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{ {
ISceneNodeAnimator::serializeAttributes(out, options);
out->addVector3d("Rotation", Rotation); out->addVector3d("Rotation", Rotation);
} }
...@@ -55,6 +59,8 @@ void CSceneNodeAnimatorRotation::serializeAttributes(io::IAttributes* out, io::S ...@@ -55,6 +59,8 @@ void CSceneNodeAnimatorRotation::serializeAttributes(io::IAttributes* out, io::S
//! Reads attributes of the scene node animator. //! Reads attributes of the scene node animator.
void CSceneNodeAnimatorRotation::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) void CSceneNodeAnimatorRotation::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{ {
ISceneNodeAnimator::deserializeAttributes(in, options);
Rotation = in->getAttributeAsVector3d("Rotation"); Rotation = in->getAttributeAsVector3d("Rotation");
} }
...@@ -63,6 +69,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorRotation::createClone(ISceneNode* node, IS ...@@ -63,6 +69,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorRotation::createClone(ISceneNode* node, IS
{ {
CSceneNodeAnimatorRotation * newAnimator = CSceneNodeAnimatorRotation * newAnimator =
new CSceneNodeAnimatorRotation(StartTime, Rotation); new CSceneNodeAnimatorRotation(StartTime, Rotation);
newAnimator->cloneMembers(this);
return newAnimator; return newAnimator;
} }
......
...@@ -35,22 +35,9 @@ namespace scene ...@@ -35,22 +35,9 @@ namespace scene
(IReferenceCounted::drop()) the returned pointer after calling this. */ (IReferenceCounted::drop()) the returned pointer after calling this. */
virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_; virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_;
//! Reset a time-based movement by changing the starttime.
virtual void setStartTime(u32 time) _IRR_OVERRIDE_
{
StartTime = time;
}
//! Get the starttime.
virtual irr::u32 getStartTime() const _IRR_OVERRIDE_
{
return StartTime;
}
private: private:
core::vector3df Rotation; core::vector3df Rotation;
u32 StartTime;
}; };
......
...@@ -15,7 +15,7 @@ namespace scene ...@@ -15,7 +15,7 @@ namespace scene
CSceneNodeAnimatorTexture::CSceneNodeAnimatorTexture(const core::array<video::ITexture*>& textures, CSceneNodeAnimatorTexture::CSceneNodeAnimatorTexture(const core::array<video::ITexture*>& textures,
s32 timePerFrame, bool loop, u32 now) s32 timePerFrame, bool loop, u32 now)
: ISceneNodeAnimatorFinishing(0), : ISceneNodeAnimatorFinishing(0),
TimePerFrame(timePerFrame), StartTime(now), Loop(loop) TimePerFrame(timePerFrame), Loop(loop)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CSceneNodeAnimatorTexture"); setDebugName("CSceneNodeAnimatorTexture");
...@@ -29,6 +29,7 @@ CSceneNodeAnimatorTexture::CSceneNodeAnimatorTexture(const core::array<video::IT ...@@ -29,6 +29,7 @@ CSceneNodeAnimatorTexture::CSceneNodeAnimatorTexture(const core::array<video::IT
Textures.push_back(textures[i]); Textures.push_back(textures[i]);
} }
StartTime = now;
FinishTime = now + (timePerFrame * Textures.size()); FinishTime = now + (timePerFrame * Textures.size());
} }
...@@ -56,10 +57,10 @@ void CSceneNodeAnimatorTexture::animateNode(ISceneNode* node, u32 timeMs) ...@@ -56,10 +57,10 @@ void CSceneNodeAnimatorTexture::animateNode(ISceneNode* node, u32 timeMs)
if (Textures.size()) if (Textures.size())
{ {
const u32 t = (timeMs-StartTime); const u32 t = (timeMs-(StartTime+PauseTimeSum));
u32 idx = 0; u32 idx = 0;
if (!Loop && timeMs >= FinishTime) if (!Loop && timeMs >= FinishTime+PauseTimeSum)
{ {
idx = Textures.size() - 1; idx = Textures.size() - 1;
HasFinished = true; HasFinished = true;
...@@ -78,6 +79,8 @@ void CSceneNodeAnimatorTexture::animateNode(ISceneNode* node, u32 timeMs) ...@@ -78,6 +79,8 @@ void CSceneNodeAnimatorTexture::animateNode(ISceneNode* node, u32 timeMs)
//! Writes attributes of the scene node animator. //! Writes attributes of the scene node animator.
void CSceneNodeAnimatorTexture::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const void CSceneNodeAnimatorTexture::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{ {
ISceneNodeAnimatorFinishing::serializeAttributes(out, options);
out->addInt("TimePerFrame", TimePerFrame); out->addInt("TimePerFrame", TimePerFrame);
out->addBool("Loop", Loop); out->addBool("Loop", Loop);
...@@ -101,6 +104,8 @@ void CSceneNodeAnimatorTexture::serializeAttributes(io::IAttributes* out, io::SA ...@@ -101,6 +104,8 @@ void CSceneNodeAnimatorTexture::serializeAttributes(io::IAttributes* out, io::SA
//! Reads attributes of the scene node animator. //! Reads attributes of the scene node animator.
void CSceneNodeAnimatorTexture::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) void CSceneNodeAnimatorTexture::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{ {
ISceneNodeAnimatorFinishing::deserializeAttributes(in, options);
TimePerFrame = in->getAttributeAsInt("TimePerFrame"); TimePerFrame = in->getAttributeAsInt("TimePerFrame");
Loop = in->getAttributeAsBool("Loop"); Loop = in->getAttributeAsBool("Loop");
...@@ -130,6 +135,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorTexture::createClone(ISceneNode* node, ISc ...@@ -130,6 +135,7 @@ ISceneNodeAnimator* CSceneNodeAnimatorTexture::createClone(ISceneNode* node, ISc
{ {
CSceneNodeAnimatorTexture * newAnimator = CSceneNodeAnimatorTexture * newAnimator =
new CSceneNodeAnimatorTexture(Textures, TimePerFrame, Loop, StartTime); new CSceneNodeAnimatorTexture(Textures, TimePerFrame, Loop, StartTime);
newAnimator->cloneMembers(this);
return newAnimator; return newAnimator;
} }
......
...@@ -41,17 +41,6 @@ namespace scene ...@@ -41,17 +41,6 @@ namespace scene
this. */ this. */
virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_; virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) _IRR_OVERRIDE_;
//! Reset a time-based movement by changing the starttime.
virtual void setStartTime(u32 time) _IRR_OVERRIDE_
{
StartTime = time;
}
//! Get the starttime.
virtual irr::u32 getStartTime() const _IRR_OVERRIDE_
{
return StartTime;
}
private: private:
...@@ -59,7 +48,6 @@ namespace scene ...@@ -59,7 +48,6 @@ namespace scene
core::array<video::ITexture*> Textures; core::array<video::ITexture*> Textures;
u32 TimePerFrame; u32 TimePerFrame;
u32 StartTime;
bool Loop; bool Loop;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment