Problem in ContactCallback [solved]

nikhil

04-12-2006 13:45:43

I've my ContactCallback class defined for two materialID's.


OgreNewt::MaterialID* motorBallMatID = new OgreNewt::MaterialID(newtWorld);
OgreNewt::MaterialID* trackMatId= new OgreNewt::MaterialID(newtWorld);

trackBody->setMaterialGroupID(trackMatId);
motorBallBody->setMaterialGroupID(motorBallMatID );

ballTrackMatPair = new OgreNewt::MaterialPair(newtWorld, motorBallMatID, trackMatId);
ballTrackMatPair->setContactCallback(_ballTrackCollideCallback);


class BallTrackCollideCallback: public OgreNewt::ContactCallback
{
bool isTouchingTrack;

public:
BallTrackCollideCallback () : isTouchingTrack(false)
{}

int userBegin()
{
Ball* ball = (Ball *) m_body1->getUserData();

//check only if it's actually touching the track.. we check for whether it got off the ground or not..
if (isTouchingTrack)
isTouchingTrack = ball->checkBallTouchTrack();

return 1;
}
};


The problem is when the userBegin is first called m_body1 is the Ball body and when it is called the second time it's the track body!!!!! :shock:

I don't understand this behaviour..First of all isn't the body0 / body1 suppposedly dependent on the order in which we pass the MaterialID's.

I can, by checking for which OgreNode is the body attached to, deal with this problem. But according to me this shouldn't be happening in the first place. Unless ofcourse my assumption of m_body0 being the first body passed in the MaterialPair is wrong..

regards

Nikhil

nathanwilliams6

05-12-2006 09:41:52

the order isnt fixed, the best advice i can give, iis to make both your ball and track children of a parent class such as PhysicsObject.

and make a function in your physics object that you can use to return the type.

so you can then do.

if ( ((PhysicsObject*) m_body1->getUserData())->getType() == "Ball" )
{
Ball* ball = (Ball*) m_body1->getUserData();
Track* track = (Track*) m_body2->getUserData();
}
else
{
Ball* ball = (Ball*) m_body2->getUserData();
Track* track = (Track*) m_body1->getUserData();
}

nikhil

06-12-2006 01:48:23

the order isnt fixed, the best advice i can give, iis to make both your ball and track children of a parent class such as PhysicsObject.

and make a function in your physics object that you can use to return the type.

so you can then do.

if ( ((PhysicsObject*) m_body1->getUserData())->getType() == "Ball" )
{
Ball* ball = (Ball*) m_body1->getUserData();
Track* track = (Track*) m_body2->getUserData();
}
else
{
Ball* ball = (Ball*) m_body2->getUserData();
Track* track = (Track*) m_body1->getUserData();
}


LOL.. I posted the problem on Newton forums and got a similiar reply.. and I did went ahead implementing it like -

Ball* ball;
if (m_body1->getType() == BALL)
{
ball = (Ball *) m_body1->getUserData();
}
else
{
ball = (Ball *) m_body0->getUserData();
}


Whn I lukd at your suggestions, I was like, did he just magically copy my code and put it there.. LOL..

Thanks nonetheless.. I appreciate it.. you were really on the right track with this..

regards
nik