apply material without make it rigid?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

apply material without make it rigid?

Postby Neo » Sat Jun 16, 2012 3:50 am

I tried to build a vehicle like thishttp://newtondynamics.com/forum/viewtopic.php?f=14&t=4279&p=30032&hilit=conveyor+belt#p30032
But it didin't work even the material callback is successfully called by application...Then i notice that
Hint : Don't make the tracks rigid. That's what I did in the beginning (and the old demo)
,I just woder how can i apply material without make it rigid?
Currently, I just set the speed of the track for eachh side as user data , then call NewtonJointGetBody0 and NewtonBodyGetUserData to extract the speed then call NewtonMaterialContactRotateTangentDirections and NewtonMaterialSetContactTangentAcceleration to apply them to each track. But without make tracks rigid, how can i do it? i got confused... :?
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: apply material without make it rigid?

Postby Neo » Sat Jun 16, 2012 11:10 am

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?
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron