Creating a Custom Animator

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Cairon
Posts: 40
Joined: Sun Apr 11, 2004 12:52 am
Contact:

Creating a Custom Animator

Post 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 ;
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

Post by schick »

Have a look at the irrlicht source of the deleteanimator.
Please send me an e-mail instead of a private message.
Cairon
Posts: 40
Joined: Sun Apr 11, 2004 12:52 am
Contact:

Post by Cairon »

the delete animator has not many interesting lines, you must mean
SceneManager->addToDeletionQueue(node);

and how could that help me?
Coolkat
Posts: 25
Joined: Sun Mar 28, 2004 1:44 am
Location: U.S.A.

Post 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.
IcePump Gaming
under construction
rincewind
Posts: 35
Joined: Thu Mar 25, 2004 5:28 pm
Location: Germany --> Bonn

Post by rincewind »

If you want to delete the animator, you can try to call

Code: Select all

if( passedTime > mTimeToScale ) MySceneNode->deleteAnimator(this);
Cairon
Posts: 40
Joined: Sun Apr 11, 2004 12:52 am
Contact:

Post 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?
rincewind
Posts: 35
Joined: Thu Mar 25, 2004 5:28 pm
Location: Germany --> Bonn

Post by rincewind »

Maybe you should inherit public from ISceneNodeAnimator:

Code: Select all

class MyAnimator : public ISceneAnimator {
...
};
Cairon
Posts: 40
Joined: Sun Apr 11, 2004 12:52 am
Contact:

Post by Cairon »

yeah, that was the problem, thanks :-)
Post Reply