[SOLVED]How to set a call back function for colliding bodies

hevi

19-08-2009 02:12:20

Hi,
All I want is being able to know if two bodies collide.

I remember doing that in early version of NxOgre by;
actorGroup->setCallback<ContactReport>(myContactReport, &ContactReport::onStartTouch, &ContactReport::onEndTouch, &ContactReport::onTouch);
or something like that.

My problem is quite simple but i couldn't find a solution within NxOgre Bloody Mess v. 1.5.4,
I would really appriciate if someone could help me as I have been digging bloody mess for hours and couldn't find it :(

nargil

19-08-2009 07:56:03

I'll post you a callback example on 1.0'22T5 (bleeding). Not sure if it's the same in 1.5.4, because i've never used it


class Equipment_PhysXActorCallback : public NxOgre::ActorContactCallback
{
public:
Equipment_PhysXActorCallback()
{
mContactFunctions[NxOgre::ActorContactCallback::_onBeginContact] = NxOgre::ActorContactCallbackFunction(&Equipment_PhysXActorCallback::onBeginTouch);
mContactFunctions[NxOgre::ActorContactCallback::_onEndContact] = NxOgre::ActorContactCallbackFunction(&Equipment_PhysXActorCallback::onEndTouch);
mContactFunctions[NxOgre::ActorContactCallback::_onContact] = NxOgre::ActorContactCallbackFunction(&Equipment_PhysXActorCallback::onTouch);
}
protected:
void onBeginTouch(NxOgre::Actor* a,NxOgre::Actor* b, NxContactPair& c);
void onEndTouch(NxOgre::Actor*a ,NxOgre::Actor*b, NxContactPair& c);;
void onTouch(NxOgre::Actor* a,NxOgre::Actor* b, NxContactPair& c);;
};

class Equipment_PhysXActor : public MyActor
{
public:
Equipment_PhysXActor(NxOgre::NxString name, const NxOgre::Pose& pose, NxOgre::Shape* shape, NxOgre::Scene* scene,const NxOgre::ActorParams& params)
:MyActor(name,scene,shape,pose,params)
{
mCallback= new Equipment_PhysXActorCallback();
this->getScene()->createActorContactPair(this,NxOgre::Scene::AT_AllActors, true, NX_NOTIFY_ON_START_TOUCH, mCallback, NxOgre::GC_Never_Delete);
}
~Equipment_PhysXActor()
{
this->getScene()->removeContactCallback(mCallback);
this->mCallback = 0;
}
Equipment_PhysXActorCallback* getCallback() {return mCallback;}
void setCallback(void* val) { mCallback = (Equipment_PhysXActorCallback*)val;}
private:
Equipment_PhysXActorCallback* mCallback;
};


You need to change NX_NOTIFY_ON_START_TOUCH flag if you need other callbacks, for example
NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_TOUCH

hevi

19-08-2009 17:19:48

thanks for the answer but unfortunatelly there is no such NxOgre::ActorContactCallback class in 1.5.4
I am really stuck:(

betajaen

19-08-2009 18:54:04

It would be under the "Callback" class in BloodyMess.

However; colliding actor callbacks are not implemented in it yet, but if you like, I can have a stab at implementing it over the week and posting my efforts in the Git repo.

hevi

20-08-2009 13:17:41

would be wonderful
thanks!

hevi

08-09-2009 15:04:46

any progress so far?

betajaen

08-09-2009 15:19:03

It's been in the git repo for a few weeks now.

see setContactCallback in RigidBody.

hevi

08-09-2009 16:06:53

thnx a lot!