Use NewtonMaterialSetContactTangentAcceleration problem.

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Use NewtonMaterialSetContactTangentAcceleration problem.

Postby Neo » Sat May 11, 2013 3:39 pm

Sorry post this for a old quistion several monthes ago..
Basically, to simulate a simple tank belt, NewtonMaterialSetContactTangentAcceleration in material callback would be a good choice.
Here is my code (materal contact callback):
Code: Select all
void tank::TrackContactcallback(const NewtonJoint* contactJoint,float timestep, int threadIndex)
{
   NewtonBody*belt=NewtonJointGetBody0(contactJoint);
   tank::movementInfo*mvInfo=static_cast<tank::movementInfo*>(NewtonBodyGetUserData(belt));
   
   vector3df dir=mvInfo->ForwardDirection;//tank forward direction
   f32 speed=mvInfo->Mspeed;//desired speed
   vector3df velocity;
   NewtonBodyGetVelocity(belt,&velocity.X);//get current velocity
   matrix4 mat;
   NewtonBodyGetMatrix(belt,&mat.pointer()[0]);
   mat.rotateVect(dir);// rotate the forward direction vector to current tranformation
   f32 currentVelocity=velocity.dotProduct(dir.normalize());
   f32 accel=speed-currentVelocity;
   
   NewtonMaterial*material;
   NewtonJoint*thisContact=(NewtonJoint*)NewtonContactJointGetFirstContact(contactJoint);
   while(thisContact!=NULL)
   {
      material=NewtonContactGetMaterial(thisContact);
      NewtonMaterialContactRotateTangentDirections(material,&dir.X);
      NewtonMaterialSetContactElasticity(material,0.0001f);
      NewtonMaterialSetContactSoftness(material,0.0f);

      NewtonMaterialSetContactFrictionCoef(material,0.9f,0.9f,0);
      NewtonMaterialSetContactFrictionCoef(material,0.4f,0.4f,1);
      NewtonMaterialSetContactTangentAcceleration(material,accel/timestep,0);
      thisContact=(NewtonJoint*)NewtonContactJointGetNextContact(contactJoint,thisContact);
   }
}

these codes are the callback for belt object. I'v made two convex hull as tracks and third one as body.
But the problem is, the velocty of tank seems to have a max velocity limit.
Because, for example, I set the disired speed to 55, it turns out that tank stop accelerating at 12, although the accel varable is still 13..seem like ignore the accel when
tank reachs the speed at 12 :(
And , no matter how I change the disired speed, the tank seems like tank can only reaches the speed at 12 as maximium.
Why do this happen?
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: Use NewtonMaterialSetContactTangentAcceleration problem.

Postby Julio Jerez » Sat May 11, 2013 3:54 pm

there are not speed limit on the joints, did you set the linear and angular drag for the body to zero?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Use NewtonMaterialSetContactTangentAcceleration problem.

Postby Neo » Sat May 11, 2013 3:59 pm

Err,i didn't. How can i do that?
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: Use NewtonMaterialSetContactTangentAcceleration problem.

Postby Julio Jerez » Sat May 11, 2013 5:30 pm

Code: Select all
   // set linear and angular drag to zero
   dVector drag(0.0f, 0.0f, 0.0f, 0.0f);
   NewtonBodySetLinearDamping(body, 0);
   NewtonBodySetAngularDamping(body, &drag[0]);
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest