Problem with setAnimationEndCallback

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
hkolli
Posts: 42
Joined: Thu Jul 13, 2006 8:29 pm

Problem with setAnimationEndCallback

Post by hkolli »

hi all ,

in my code i use setAnimationEndCallback to call a function in which there are rules that control the movement of the static mesh bird . below is my code
-----------------------------------------------------------------------------

irr::scene::ISceneManager* smgr = device->getSceneManager();
scene::IAnimatedMesh* mesh = smgr->getMesh(
"../../media/bird.x");
scene::IAnimatedMeshSceneNode* anode = 0;
anode = smgr->addAnimatedMeshSceneNode(mesh);
anode->setLoopMode(true);
anode->setAnimationEndCallback(callBack);

-----------------------------------------------------------------------
------------------------------------------------------------------------------
void BoidsFlyer::callBack()
{
// Use the provided pointer argument to -
// - call a specific flyer's member functions.
BoidsFlyer *boidsFlyer = static_cast< BoidsFlyer * >( arg );

boidsFlyer -> directToBoid( );
boidsFlyer -> velocityMatching( );
boidsFlyer -> collisionAvoidance( );
boidsFlyer -> moveObject( );
boidsFlyer -> individual();
boidsFlyer ->foraging();
boidsFlyer ->subflocking();

}
-------------------------------------------------------------------

what do u think the problem is i m getting this error

------------------------------------------------
c:\documents and settings\haritha kolli\desktop\changing code\boidsflyer.cpp(53) : error C2664: 'setAnimationEndCallback' : cannot convert parameter 1 from 'void (void *)' to 'class irr::scene::IAnimationEndCallBack *'
There is no context in which this conversion is possible
------------------------------------------------------------------------------

please help :(
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You cannot pass any void method as callback, but you have to instantiate an object of type IAnimationEndCallback and use the method OnEndCallback to do what you want.
hkolli
Posts: 42
Joined: Thu Jul 13, 2006 8:29 pm

Post by hkolli »

i didnt understand what u are talking abt OnEndCallback can you please elaborate .
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You must pass a pointer to an instance of a class that derives from IAnimationEndCallback th the function setAnimationEndCallback...

Code: Select all

class BoidsFlyer : public IAnimationEndCallBack
{
//...
public:

  BoidsFlyer(scene::ISceneManager* smgr)
  {
    scene::IAnimatedMesh* mesh = smgr->getMesh("../../media/bird.x"); 
    Node
      = smgr->addAnimatedMeshSceneNode(mesh); 
    Node->setLoopMode(true); 
    Node->setAnimationEndCallback(this);
  }

  virtual void OnAnimationEnd(IAnimatedMeshSceneNode* node)
  {
    this->directToBoid( ); 
    this->velocityMatching( ); 
    this->collisionAvoidance( ); 
    this->moveObject( ); 
    this->individual(); 
    this->foraging(); 
    this->subflocking(); 
  }
};
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Pasing functions with a specific interface is the usual C way of doin callbacks. With OOP you often use object interfaces. In this case there's an interface class named IAnimationEndCallBack. You have to implement this abstract class with your own derived class. This class ha a method named OnAnimationEnd. put the code of your method into this method, pass the arguments to the constructor and pass the instantiated objects to the IAnimatedMeshSceneNode method.
this is indeed a slightly advanced programming style so you might need some more experience before you can achieve this. Or maybe someone will code this for you (I won't as this wouldn't help you to really learn this stuff - you have to do it onyour own to really learn this :wink: Hmm, too late :wink: )
hkolli
Posts: 42
Joined: Thu Jul 13, 2006 8:29 pm

Post by hkolli »

hi all ,

thanks for your help .......

bye
haritha
Post Reply