ok..no reply....But i've got sth new:
my vechicle(tank) only work when I set the kinetic fraction at very high value(such as 0.8, see my code),and apply gravity on the tracks.
but the new problem is, it cannot rotate, I change its speed by setting the acceleration(the value 'speed' in my code, i'v set it as the user data for each track)
So tank should change direction when the acceleration value of one side been set to zero, but what I see actually is that my tank start moving very slowly and never turn left or right, it only run quickly when I set both sides' acceleration value to the same number(make it run straight forward).
here is my material callback(using irrlicht types, but it works well):
- Code: Select all
void tank::TrackContactcallback(const NewtonJoint* contactJoint,float timestep, int threadIndex)
{
vector3df dir=vector3df(0,0,-1);
NewtonBody*belt=NewtonJointGetBody0(contactJoint);
f32 speed=*(static_cast<f32*>(NewtonBodyGetUserData(belt)));//get the acceration value
matrix4 mat;
NewtonBodyGetMatrix(belt,&mat.pointer()[0]);
mat.rotateVect(dir);//rotate the acceration direction
NewtonMaterial*material;
NewtonJoint*thisContact=(NewtonJoint*)NewtonContactJointGetFirstContact(contactJoint);
while(thisContact!=NULL)
{
material=NewtonContactGetMaterial(thisContact);
NewtonMaterialContactRotateTangentDirections(material,&dir.X);
NewtonMaterialSetContactElasticity(material,0);
NewtonMaterialSetContactFrictionCoef(material,0.9f,0.8f,0);
NewtonMaterialSetContactFrictionCoef(material,0.9f,0.8f,1);
NewtonMaterialSetContactTangentAcceleration(material,speed,0);
thisContact=(NewtonJoint*)NewtonContactJointGetNextContact(contactJoint,thisContact);
}
}
and I added tracks for each side like this:
- Code: Select all
////some codes to set the newtonbody of tank's main body(body_newt)
//////
vector3df intria,origin;
vector3df pinDir=vector3df(1,0,0);
vector3df pivotPoint;
NewtonCollision*colli;
colli=NewtonBodyGetCollision(body_newt);
NewtonConvexCollisionCalculateInertialMatrix(colli,&intria.X,&origin.X);
pivotPoint=origin;//set the hinge pivot point at body's center of mass
matrix4 mat;
NewtonBodyGetMatrix(body_newt,&mat.pointer()[0]);
mat.transformVect(pivotPoint);
//some codes to set the newtonBody of left track(lTrack_newt)
……
//////
NewtonBodySetLinearDamping(lTrack_newt,0.8f);
NewtonConstraintCreateHinge(nWorld,&pivotPoint.X,&pinDir.X,lTrack_newt,body_newt);
//some codes to set the newtonBody of right track(rTrack_newt)
……
//////
NewtonBodySetLinearDamping(rTrack_newt,0.8f);
NewtonConstraintCreateHinge(nWorld,&pivotPoint.X,&pinDir.X,rTrack_newt,body_newt);
BTW:
My tank initially move on Z-axis direction.
Can somebody tell where I did wrong?