collision callback

Artic_Ice83

24-02-2008 13:33:30

i have created 6 bodies: 3 cubes and 3 spheres that belongs respectively to mCubeGroup and mSphereGroup.
If i set a collision callback with the class->method pointer, all works well except for the onEndTouch, that should restore the default material of the body.
these are the callback class and the code that sets the callback:



class myCallback {

public:

void onStartTouch(Actor* a , Actor* b) {
Body* bd = static_cast<Body*>(b);
bd->getEntity()->setMaterialName("nx.capsule");

Body* ad = static_cast<Body*>(a);
ad->getEntity()->setMaterialName("nx.sphere");
}

void onEndTouch(Actor* a, Actor* b) {
Body* bd = static_cast<Body*>(b);
bd->getEntity()->setMaterialName("nx.sphere");

Body* ad = static_cast<Body*>(a);
ad->getEntity()->setMaterialName("nx.cube");
}

void Jiggle(Actor* a, Actor* b) {
b->addForce(Vector3(NxMath::rand(-10,10), NxMath::rand(-10,10), NxMath::rand(-10,10)) * b->getMass());
}
};



setting the callback...



mCubeGroup->setCallback<myCallback>(mCallback,&myCallback::onStartTouch,&myCallback::onEndTouch, &myCallback::Jiggle);
mCubeGroup->setCollisionCallback(mSphereGroup,NX_NOTIFY_ALL, true);



i have also another question: if i have three groups and set the collision callback between the first and second, and between the second and third group, why do the first and third group collide?should the body of the first group pass through the body that belongs to third group(like in the physX tutorial collision groups)?

NickM

25-02-2008 06:17:42

See this thread for the answer to your first question
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=6082

Artic_Ice83

25-02-2008 09:10:56

ok. so it is a problem in the physX and not in the code...i will try to update the physX to the latest version (2.8.0) and see if all works well...

Artic_Ice83

01-03-2008 13:11:26

ok. i was passed to ageia physX 2.8.0 and now the onEndTouch event works well.
NickM thanks for the reply! :o

jonnys

17-08-2008 03:51:30

Sorry to bring up a relatively old topic but... in the following code

mCubeGroup->setCallback<myCallback>(mCallback,&myCallback::onStartTouch,&myCallback::onEndTouch, &myCallback::Jiggle);
mCubeGroup->setCollisionCallback(mSphereGroup,NX_NOTIFY_ALL, true);


Where the does the variable "mCallback" come from? What is it?

mcaden

28-08-2008 18:34:25

Artic_Ice83 would probably have to be the one to answer the question exactly, but I would think it would be an instance of the myCallBack class.




I have a question of my own though.


void onStartTouch(Actor* a , Actor* b) {
//...


which actor is a and which actor is b?

For example I have this code for my own player class:

class Player : public Character, public GroupCallback::InheritedCallback
{
//...
void onStartTouch(Actor*, Actor*, ContactStream*);
void onEndTouch(Actor*, Actor*, ContactStream*);
void onTouch(Actor*, Actor*, ContactStream*);
//...
}

and later...in the Player constructor...

mBody->getGroup()->setCallback(this);
mBody->getGroup()->setCollisionCallback( mScene->getActorGroup( "terrain" ), NX_NOTIFY_ALL, true);


Would 'a' always be the player, and 'b' always be the actor it's colliding with? or is it just whatever NxOgre feels like at the time?

Right now my player only needs to have callbacks for colliding with the terrain (my method for implementing jumping), but later it'll need to collide with enemies, so how will I be able to put enemy callbacks to the player, and terrain callbacks to the player in the same function?

If I use something like:

String groupName = b->getGroup()->getName();
if( groupName == "terrain" )
//...
else if( groupName == "enemies" )
//...
else if( groupName == "lava" )
//...
else if( groupName == "beautiful women" )
//...


Can I expect b to never be my player and to work as written above? Or will it sometimes be switched?

mcaden

31-08-2008 12:36:34

To answer my own question if anybody else is still learning this stuff.

In:

void onStartTouch(Actor* actorA , Actor* actorB) { ...


actorA will be the one that you did


mBody->getGroup()->setCallback(this);


to (mBody in this case).

and actorB will be the actor group used in the following function:


mBody->getGroup()->setCollisionCallback( mScene->getActorGroup( "terrain" ), NX_NOTIFY_ALL, true);


So in the case of my post above I was correct. actorA will always be my player, and actorB will be whatever actor from the other group it is colliding with.




Or at least that's what it's like with my current setup. If there's an exception or if I'm mistaken, please let me know.