Page 1 of 1

Creating a Custom Animator

Posted: Fri Apr 16, 2004 10:19 am
by Cairon
Hey ;)

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);
}
I'm adding this Animator to my node by using:

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);
But i'm getting always a warning by the compiler, that the cast from IScaleAnimator* to scene::ISceneNodeAnimator* exists, but that it is not avaiable. Any one an idea why?

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 ;

Posted: Fri Apr 16, 2004 12:20 pm
by schick
Have a look at the irrlicht source of the deleteanimator.

Posted: Fri Apr 16, 2004 3:30 pm
by Cairon
the delete animator has not many interesting lines, you must mean
SceneManager->addToDeletionQueue(node);

and how could that help me?

Posted: Fri Apr 16, 2004 7:10 pm
by Coolkat
to destory a class instance i believe it's

Code: Select all

delete this;
something like that..

try

Code: Select all

IScaleAnimator *anim =  IScaleAnimator(700,core::vector3df(1.0f,1.0f,1.0f),core::vector3df(10.0f,10.0f,10.0f)); 
   node->addAnimator((scene::ISceneNodeAnimator*) anim);


that may work.

Posted: Fri Apr 16, 2004 8:33 pm
by rincewind
If you want to delete the animator, you can try to call

Code: Select all

if( passedTime > mTimeToScale ) MySceneNode->deleteAnimator(this);

Posted: Fri Apr 16, 2004 11:14 pm
by Cairon
Coolkat: well, how could removing the new operator help solving something? it just produces compiler errors ^^

rincewind: looks like i missed that function

thanks for the help, maybe somebody has any idea of what my warning is comming from. the warning (sorry, german vc6) is:

warning C4243: type cast-Konvertierung von 'class IScaleAnimator *' in 'class irr::scene::ISceneNodeAnimator *' existiert, ist aber nicht verfuegbar

do i have to change the deklaration of my class? it looks the same way as the classes in the irrlicht source, the only difference i see is that i don't use an interface class, is that the problem?

Posted: Sat Apr 17, 2004 10:07 am
by rincewind
Maybe you should inherit public from ISceneNodeAnimator:

Code: Select all

class MyAnimator : public ISceneAnimator {
...
};

Posted: Sat Apr 17, 2004 12:36 pm
by Cairon
yeah, that was the problem, thanks :-)