Coiote
05-07-2008 22:55:30
Hey,
I had a problem with callbacks.
Code:
in my GameManager class- RenderScene method
and my Callback class:
The problem is mCallBack2 is the one that affects all cubes that have powerups. When I put only one call to the callback it works perfectly, but I want to have different kinds of powerup's working in my scene. What I understant is that the last callback declaration will affect all the objects in groups.
Thankx
P.S: I read http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=7530 but I don't think that will work for me.
I had a problem with callbacks.
Code:
in my GameManager class- RenderScene method
CallbackManager *mCallback = new CallbackManager();
CallbackManager *mCallback2 = new CallbackManager();
mCarroGroup = mScene->createActorGroup("Carro");
mPowerUpGroup= mScene->createActorGroup("PowerUp");
mPowerUp2Group=mScene->createActorGroup("PowerUp2");
/*Objectos a colocar*/
mScene->createBody("cube.1m.mesh", new CubeShape(1,1,1), Vector3(-5,25,-25), "mass: 100, group: Carro");
mScene->createBody("cube.1m.mesh", new CubeShape(1,1,1), Vector3(5,25,-25), "mass: 100, group: PowerUp");
/*novo cubo pa experiencia das callback*/
mScene->createBody("cube.1m.mesh", new CubeShape(2,2,2), Vector3(-5,25,-20), "mass: 100, group: PowerUp2");
carro = new Carro();
mCarroGroup->setCallback(mCallback);
mCarroGroup->setCollisionCallback(mPowerUpGroup, NX_NOTIFY_ALL, true);
mCarroGroup->setCallback<CallbackManager>(mCallback, &CallbackManager::aLive, &CallbackManager::TurnRed, &CallbackManager::Kill);
mCarroGroup->setCallback(mCallback2);
mCarroGroup->setCollisionCallback(mPowerUp2Group, NX_NOTIFY_ALL, true);
mCarroGroup->setCallback<CallbackManager>(mCallback2, &CallbackManager::Invisible, &CallbackManager::TurnXPTO, &CallbackManager::Kill);
and my Callback class:
CallbackManager::CallbackManager(){}
void CallbackManager::onStartTouch( NxOgre::Actor*, NxOgre::Actor*) {
}
void CallbackManager::onEndTouch( NxOgre::Actor*, NxOgre::Actor*) {
}
void CallbackManager::onTouch(NxOgre::Actor*, NxOgre::Actor*) {
}
void CallbackManager::TurnRed(NxOgre::Actor* a , NxOgre::Actor* b) {
NxOgre::Body* bd = static_cast<NxOgre::Body*>(b);
bd->getEntity()->setMaterialName("nx.capsule");
}
void CallbackManager::TurnYellow(NxOgre::Actor* a, NxOgre::Actor* b) {
NxOgre::Body* bd = static_cast<NxOgre::Body*>(b);
bd->getEntity()->setMaterialName("nx.cube");
}
void CallbackManager::TurnXPTO(NxOgre::Actor* a, NxOgre::Actor* b) {
NxOgre::Body* bd = static_cast<NxOgre::Body*>(b);
bd->getEntity()->setMaterialName("nx.lava");
}
void CallbackManager::Kill(NxOgre::Actor* a, NxOgre::Actor* b) {
NxOgre::Body* bd = static_cast<NxOgre::Body*>(b);
bd->getEntity()->setMaterialName("nx.flag");
bd->disable();
}
void CallbackManager::aLive(NxOgre::Actor* a, NxOgre::Actor* b) {
NxOgre::Body* bd = static_cast<NxOgre::Body*>(a);
bd->getEntity()->setMaterialName("nx.flag");
}
void CallbackManager::Jiggle(NxOgre::Actor* a, NxOgre::Actor* b) {
b->addForce(Ogre::Vector3(NxMath::rand(-500,500), NxMath::rand(-500,500), NxMath::rand(-500,500)) * b->getMass());
}
void CallbackManager::Invisible(NxOgre::Actor* a, NxOgre::Actor* b) {
NxOgre::Body* bd = static_cast<NxOgre::Body*>(a);
bd->disableVisualisation();
}
CallbackManager::~CallbackManager(){}
The problem is mCallBack2 is the one that affects all cubes that have powerups. When I put only one call to the callback it works perfectly, but I want to have different kinds of powerup's working in my scene. What I understant is that the last callback declaration will affect all the objects in groups.
Thankx
P.S: I read http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=7530 but I don't think that will work for me.