Page 1 of 1

Problem with setAnimationEndCallback

Posted: Tue Aug 01, 2006 6:00 pm
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 :(

Posted: Tue Aug 01, 2006 6:14 pm
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.

Posted: Tue Aug 01, 2006 6:57 pm
by hkolli
i didnt understand what u are talking abt OnEndCallback can you please elaborate .

Posted: Tue Aug 01, 2006 7:42 pm
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(); 
  }
};

Posted: Tue Aug 01, 2006 7:44 pm
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: )

Posted: Wed Aug 02, 2006 4:08 pm
by hkolli
hi all ,

thanks for your help .......

bye
haritha