CustomMultiBodyVehicle and Friction

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

CustomMultiBodyVehicle and Friction

Postby Tazack » Mon Aug 11, 2008 4:38 am

Hi,

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 ? :mrgreen:
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 !!! :twisted:
Last edited by Tazack on Fri Aug 22, 2008 8:59 am, edited 1 time in total.
Tazack
 
Posts: 8
Joined: Tue Oct 23, 2007 4:52 am

Re: CustomMultiBodyVehicle and Friction

Postby Tazack » Thu Aug 14, 2008 4:51 am

No idea :?:
Tazack
 
Posts: 8
Joined: Tue Oct 23, 2007 4:52 am

Re: CustomMultiBodyVehicle and Friction

Postby Tazack » Fri Aug 22, 2008 4:04 am

I tried to change the value for tire tire configuration (mass, suspensionLength, suspesionSpringConst, suspesionSpringDamper). I don't really understand what is suspesionSpringConst and suspesionSpringDamper, here the value I use:

Code: Select all
  dFloat tireMass = 35;
    dFloat suspensionLength = 0.4f;
    dFloat suspesionSpringConst = 160.0f;
    dFloat suspesionSpringDamper = 10.0f;


I can see the change, depending to the value my car jump into the air or is sticky to the ground, but the friction don't change. The maximum car speed is 18.
Can somebody tell me if they seem correct ?

Changing these value can solve my problem ?

Thank.
Tazack.
Tazack
 
Posts: 8
Joined: Tue Oct 23, 2007 4:52 am

Re: CustomMultiBodyVehicle and Friction

Postby Aphex » Fri Aug 22, 2008 7:53 am

Is the problem just that your tyres are losing grip and the car is skidding?
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: CustomMultiBodyVehicle and Friction

Postby Tazack » Fri Aug 22, 2008 8:58 am

My problem is that my car can't go faster than 18 (km/h ? got from CustomMultiBodyVehicleGetSpeed).
If I set a higher torque my car loose the grip and slide/turn.
Tazack
 
Posts: 8
Joined: Tue Oct 23, 2007 4:52 am

Re: CustomMultiBodyVehicle and Friction

Postby Sweenie » Fri Aug 22, 2008 10:08 am

Hmm, are you using fixed timesteps and how much linear damping is applied each update?
Sweenie
 
Posts: 492
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: CustomMultiBodyVehicle and Friction

Postby Tazack » Fri Aug 22, 2008 11:30 am

Hi,

By timestep you mean the value used to call NewtonUpdate ? If true I use call it like this: NewtonUpdate (g_nWorld, 0.1);
After you remark I try to use different value and the result is strange, with:
- 0.1: the car max car speed is 18..
- 0.01 the speed go up to 31 !
- 0.0166 the speed fall again to 18...

I don't understand why this parameter change the car max speed and why the change is not "linear"

And what did you mean by "linear damping" ?

Thank for your help now my car is no more a snail but a turtle :P
Tazack
 
Posts: 8
Joined: Tue Oct 23, 2007 4:52 am

Re: CustomMultiBodyVehicle and Friction

Postby Sweenie » Mon Aug 25, 2008 3:53 am

Linear damping is applied to the body each update. This is to keep the simulation more stable.
If the simulation is updated 300 times per second, the damping will be applied 300 times per second.
If you update 100 times per second then it's damped 100 times per second.
Now since the damping value is a fixed number the body will slow down faster the more updates you do per second.
Don't remember what the default value is, but I suppose it would be better to set it to zero(or close to zero) and apply a custom drag force instead.
Sweenie
 
Posts: 492
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: CustomMultiBodyVehicle and Friction

Postby Tazack » Mon Aug 25, 2008 4:50 am

Thanks for your reposne.

I have added this code to the function that build my car.

Code: Select all
   // set the linear drag to the minimum
   // set friction force
   dFloat damp[3];
   damp[0] = 0.0f;
   damp[1] = 0.0f;
   damp[2] = 0.0f;
   NewtonBodySetLinearDamping (m_objectBody, 0.0f);
   NewtonBodySetAngularDamping (m_objectBody, damp);


but I see no difference.
In your previous reponse you ask me "how much linear damping is applied each update", should I set the linear damping in the callback function ? or only when building the car ? I'va tried to call it in the callback function but no difference.

thank.
Tazack
 
Posts: 8
Joined: Tue Oct 23, 2007 4:52 am

Re: CustomMultiBodyVehicle and Friction

Postby Dave Gravel » Mon Aug 25, 2008 12:25 pm

Maybe you can try to use a higher newton frame rate value.
With a higher frame rate value like 100 your suposed to can gain more speed by newton update pass.
The newton frame rate is set to 60 by default normally 100 give a good resulta with a higher speed accumulation.

Good luck.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 725
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: CustomMultiBodyVehicle and Friction

Postby Tazack » Wed Aug 27, 2008 7:49 am

Thanks for your reposne K00m.

Now it's better :D
If I set the frame rate to 100 as you said there no change, but if I set it to 200 the speed "seems" to be unlimited.
In fact I can't reach the maximum speed because the more frame rate I set the less my car accelerates and at the end my track is to short (my track is around 2 ou 3 kilometers long :mrgreen: ). I need around 25 secondes to reach the speed of 65 but after this limit my car is not stable it tremble/shake and sometime take off in the air, spin and crash...

no it is not the batman's car :mrgreen:

I don't understand the relation between frame rate, the value pass to newtonUpdate and the max car speed :?:
Tazack
 
Posts: 8
Joined: Tue Oct 23, 2007 4:52 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 7 guests

cron