I try to convert my little game to newton 2.0 but i have some problem with the car.
The grip (friction) seems different.
If no torque is applied, just gravity, all is ok. The car fall until the groud and stabilise.
If I set max torque to 1500, all is ok but the car speed is limited to 18 (CustomMultiBodyVehicleGetSpeed), a bit slow for a race game no ?
If I set the max torque more than 1500 (3000 with nexton 1.56) the car turn/slide around it's Y axis.
the car mass is 1000,
the tires position:
tireFR->setPosition(D3DXVECTOR3(1.2f, -0.1f, -0.8f));
tireFL->setPosition(D3DXVECTOR3(1.2f, -0.1f, 0.8f));
tireRR->setPosition(D3DXVECTOR3(-1.1f, -0.1f, -0.8f));
tireRL->setPosition(D3DXVECTOR3(-1.1f, -0.1f, 0.8f));
Here is code to create the car :
- Code: Select all
// Create body
NewtonCollision* collision = NULL;
//collision = NewtonCreateBox (nWorld, 20.0f, 20.0f, 20.0f, NULL);
DWORD nbPts = m_pMesh->GetNumVertices();
dVector *tabh = (dVector*)calloc(nbPts, sizeof(dVector));
for (DWORD i=0; i < nbPts; i++) {
D3DXVECTOR3 v0 = m_pVertices[i].p;
tabh[i] = dVector (v0.x, v0.y, v0.z);
}
collision = NewtonCreateConvexHull (nWorld, nbPts, &tabh[0].m_x, sizeof (dVector), 0.01f, NULL);
// create the level rigid body
m_objectBody = NewtonCreateBody(nWorld, collision);
// calculate the moment of inertia and the relative center of mass of the solid
dVector inertie;
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
NewtonConvexCollisionCalculateInertialMatrix (collision, &inertie.m_x, &m_origine.m_x);
m_origine.m_y = -0.5;
Ixx = masse * inertie.m_x;
Iyy = masse * inertie.m_y;
Izz = masse * inertie.m_z;
NewtonBodySetCentreOfMass (m_objectBody, &m_origine.m_x);
NewtonBodySetMassMatrix (m_objectBody, masse, Ixx, Iyy, Izz);
// release the collision tree (this way the application does not have to do book keeping of Newton objects
NewtonReleaseCollision (nWorld, collision);
// save the pointer to the graphic object with the body.
NewtonBodySetUserData (m_objectBody, this);
// set the material group id for vehicle
NewtonBodySetMaterialGroupID (m_objectBody, materialId);
// set the transform call back function
NewtonBodySetTransformCallback (m_objectBody, vehiclePhysicsSetTransform);
// set the force and torque call back function
NewtonBodySetForceAndTorqueCallback (m_objectBody, objVehicleApplyGravityForce);
// set the transformation for this rigid body
dMatrix m_matrix (GetIdentityMatrix());
m_matrix.m_posit.m_x = getPosition()->x;
m_matrix.m_posit.m_y = getPosition()->y;
m_matrix.m_posit.m_z = getPosition()->z;
NewtonBodySetMatrix (m_objectBody, &m_matrix[0][0]);
dVector updir (m_matrix.m_up);
dVector frontdir (m_matrix.m_front);
m_objectJoint = CreateCustomMultiBodyVehicle (&frontdir[0], &updir[0], m_objectBody);
// add 4 wheels
dVector tireposFL( this->tireFL->getPosition()->x, this->tireFL->getPosition()->y, this->tireFL->getPosition()->z );
dVector tireposFR( this->tireFR->getPosition()->x, this->tireFR->getPosition()->y, this->tireFR->getPosition()->z );
dVector tireposRL( this->tireRL->getPosition()->x, this->tireRL->getPosition()->y, this->tireRL->getPosition()->z );
dVector tireposRR( this->tireRR->getPosition()->x, this->tireRR->getPosition()->y, this->tireRR->getPosition()->z );
dFloat m_width = 0.4f;
dFloat m_radius = 0.4f;
dFloat tireMass = 35;
dFloat suspensionLength = 0.4f;
dFloat suspesionSpringConst = 120.0f;
dFloat suspesionSpringDamper = 10.0f;
CustomMultiBodyVehicleAddTire( m_objectJoint, NULL, &tireposFL.m_x, tireMass, m_radius, m_width, suspensionLength, suspesionSpringConst, suspesionSpringDamper );
CustomMultiBodyVehicleAddTire( m_objectJoint, NULL, &tireposFR.m_x, tireMass, m_radius, m_width, suspensionLength, suspesionSpringConst, suspesionSpringDamper );
CustomMultiBodyVehicleAddTire( m_objectJoint, NULL, &tireposRL.m_x, tireMass, m_radius, m_width, suspensionLength, suspesionSpringConst, suspesionSpringDamper );
CustomMultiBodyVehicleAddTire( m_objectJoint, NULL, &tireposRR.m_x, tireMass, m_radius, m_width, suspensionLength, suspesionSpringConst, suspesionSpringDamper );
int nb_tire = CustomMultiBodyVehicleGetTiresCount(m_objectJoint);
for(int i=0; i < nb_tire; i++)
{
const NewtonBody * tire = CustomMultiBodyVehicleGetTireBody( m_objectJoint, i );
NewtonBodySetTransformCallback( tire, tireTransformCallback );
NewtonBodySetMaterialGroupID (tire, materialId);
}
- Code: Select all
void objVehicleApplyGravityForce (const NewtonBody* body, dFloat timestep, int threadIndex)
{
//Vehicle* car;
//car = (Vehicle*) NewtonBodyGetUserData(body);
// Gravity
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
dFloat mass;
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
dVector force (0.0f, mass * GRAVITY, 0.0f);
NewtonBodyAddForce (body, &force.m_x);
}
- Code: Select all
void Vehicle::setTireTorque(dFloat value)
{
dFloat speed;
speed = dAbs (CustomMultiBodyVehicleGetSpeed(this->m_objectJoint));
if (value > 0.0f) {
value = -MAX_TORQUE * (1.0f - (speed / 200.0f));
} else if (value < 0.0f) {
value = MAX_TORQUE * 0.5f * (1.0f - (speed / 200.0f));
} else {
value = 0.0f;
}
CustomMultiBodyVehicleApplyTorque (this->m_objectJoint, 2, value);
CustomMultiBodyVehicleApplyTorque (this->m_objectJoint, 3, value);
}
Here the code for the material:
- Code: Select all
levelID = NewtonMaterialCreateGroupID(nWorld);
vehicleID = NewtonMaterialCreateGroupID(nWorld);
...
NewtonMaterialSetDefaultCollidable (nWorld, levelID, vehicleID, 1);
NewtonMaterialSetDefaultFriction (nWorld, levelID, vehicleID, 1.6f, 1.6f);
NewtonMaterialSetDefaultFriction (nWorld, vehicleID, levelID, 1.6f, 1.6f);
I tried diferent value for material but the effect is limited.
All was fine in 1.53 (except some collision pb)
Can someone help ? please this make me mad !!!