I'am writing a simple simulation of cannon using irrlicht and newton dynamics. The problem is, i can't rotate it (lift up or down) I can make the gun to move with the cat:
Code: Select all
void _cdecl PhysicsCarSetTransform(const NewtonBody *body, const dFloat *matrix)
{
matrix4 mat;
memcpy(mat.pointer(), matrix, sizeof(float)*16);
CPhysicsCar *car = (CPhysicsCar *)NewtonBodyGetUserData(body);
car->node->setPosition(mat.getTranslation());
car->node->setRotation(mat.getRotationDegrees());
////////////////////////////////////////////////////////////////////////////
if(cannonnode){
vector3df RelativeToCar(-41.7,24.5,0);
((ISceneNode*)carnode)->getAbsoluteTransformation().transformVect(RelativeToCar);
cannonnode->setPosition(RelativeToCar);
// !! this is the place where i set gun rotation
cannonnode->setRotation(mat.getRotationDegrees());
}
if(attachCamera){
vector3df RelativeToCar(200,100,0);
((ISceneNode*)carnode)->getAbsoluteTransformation().transformVect(RelativeToCar);
actualCamera->setPosition(RelativeToCar);
actualCamera->setTarget(carnode->getAbsolutePosition());
}
////////////////////////////////////////////////////////////////////////////
// also need to set transform for the tyres
void* wheelid = 0;
for(wheelid = NewtonVehicleGetFirstTireID(car->vehicle); wheelid; wheelid = NewtonVehicleGetNextTireID(car->vehicle, wheelid))
{
CPhysicsCarWheel *wheel = (CPhysicsCarWheel *)NewtonVehicleGetTireUserData(car->vehicle, wheelid);
NewtonVehicleGetTireMatrix(car->vehicle, wheelid, &mat.pointer()[0]);
wheel->node->setPosition(mat.getTranslation());
wheel->node->setRotation(mat.getRotationDegrees());
}
if (reset)
{
NewtonVehicleReset(car->vehicle);
dMatrix matrix (GetIdentityMatrix());
vector3df terrPos= terrain->getTerrainCenter();
matrix.m_posit.m_x = terrPos.X;
matrix.m_posit.m_y = terrPos.Y+900;
matrix.m_posit.m_z = terrPos.Z;
NewtonBodySetMatrixRecursive(car->carbody,&matrix[0][0]);
}
}
Code: Select all
vector3df RelativeToCar(0,30,0);
((ISceneNode*)carnode)->getAbsoluteTransformation().rotateVect (RelativeToCar);
cannonnode->setRotation(RelativeToCar);
Thanks for advices. And sory for my english:D