I have a problem with collision response.
I implemented a simple velocity inversion when collision is checked .
Problem is that game controls get switched ( left is right and so ).
It looks like the condition of collision resolution is permanent .
Any idea how to make it temporary for the time of contact ?
( if (cres.NumPairs() > 0) in the code refers to the collision resolution condition ).
class MyCallback : public osg::NodeCallback {
public:
MyCallback::MyCallback(tankInputDeviceStateType* tankIDevState
//, float dt, osg::Timer_t start_tick
)
{
tankInputDeviceState = tankIDevState;
}
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
lastGameTime +=1;
clock_t current = clock();
difference = (current - lastGameTime)/lastGameTime*1000.0f ;
std::cout<<difference<<"elapsed_time"<< std::endl;
PQP_Collide(&cres,R1,T1,&ball1,
R2,T2,&ball2,
PQP_FIRST_CONTACT);
if (cres.NumPairs() > 0)
{
posiz = -posiz;
}
if (tankInputDeviceState->moveFwdRequest)
{
T1[0] += posiz;
}
if (tankInputDeviceState->moveBwdRequest)
{
T1[0] -= posiz;
}
//osg matrix related to pqp matrix//
osg::Matrix ex( R1[0][0], R1[0][1], R1[0][2], 0,
R1[1][0], R1[1][1], R1[1][2], 0,
R1[2][0], R1[2][1], R1[2][2], 0,
T1[0], T1[1], T1[2], 1.0 );
osg::MatrixTransform *tx = dynamic_cast<osg::MatrixTransform *>(node);
tx->setMatrix( ex );
traverse( node, nv );
}
tankInputDeviceStateType* tankInputDeviceState;
private:
};
Thanks,
Gab-











