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?