I'm trying to implement my own SceneNode Animator. Here is the class:
Code: Select all
class IScaleAnimator : scene::ISceneNodeAnimator
{
public:
IScaleAnimator(u32 TimeToScale, core::vector3df StartScale, core::vector3df EndScale );
virtual ~IScaleAnimator ();
virtual void animateNode (scene::ISceneNode *node, u32 timeMs);
private:
u32 mStartTime;
u32 mTimeToScale;
core::vector3df mStartScale;
core::vector3df mEndScale;
};
IScaleAnimator::IScaleAnimator(u32 TimeToScale, core::vector3df StartScale, core::vector3df EndScale )
{
mStartTime = 0;
mTimeToScale = TimeToScale;
mStartScale = StartScale;
mEndScale = EndScale;
}
IScaleAnimator::~IScaleAnimator ()
{
}
void IScaleAnimator::animateNode (scene::ISceneNode *node, u32 timeMs)
{
if ( mStartTime == 0 )
{
mStartTime = timeMs;
}
u32 passedTime = timeMs - mStartTime;
if ( passedTime > mTimeToScale )
return ;
float progress = float(passedTime) / float(mTimeToScale);
core::vector3df scale = mStartScale + (mEndScale-mStartScale) * progress;
node->setScale(scale);
}
Code: Select all
IScaleAnimator* anim = new IScaleAnimator(700,core::vector3df(1.0f,1.0f,1.0f),core::vector3df(10.0f,10.0f,10.0f));
node->addAnimator((scene::ISceneNodeAnimator*)anim);
My question is: how can i destroy the animator, after the time has passed? In my function, i only return (do no more scaling):
Code: Select all
if ( passedTime > mTimeToScale )
return ;