Vehicles (again)

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Vehicles (again)

Postby adam450 » Tue Jan 20, 2009 9:11 pm

So I looked at all of the tutorial 9. It seems like all I need is:

NewtonBody (a box for a basic car shape)
NewtonJoint ( just groups the wheels and car as 1 object) ?

AddTire Function ( probably just makes newton cylinders)
SetSteeringAngle ( turn car)
SetTorque ( spin wheels)

RayCast ( to make sure the car is on the ground to move)

Is there anything else that I am missing from this? Without a tutorial of saying what is the bare minimum, thats all I could get out of it.
adam450
 
Posts: 21
Joined: Fri Jan 16, 2009 11:11 pm

Re: Vehicles (again)

Postby agi_shi » Tue Jan 20, 2009 9:50 pm

Download the (now public) 2.0 beta and look at the ray cast car demo.
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Vehicles (again)

Postby adam450 » Tue Jan 20, 2009 11:52 pm

That was pretty much the same code as tutorial 9. :(
adam450
 
Posts: 21
Joined: Fri Jan 16, 2009 11:11 pm

Re: Vehicles (again)

Postby adam450 » Wed Jan 21, 2009 12:05 am

Sorry for posting this code, and if anyone even looks at it. I just dont know where to go from here. And for an actual question, why is tirePin = 0,0,1 instead of 1,0,0 (x-axis is the axis of spin)?

Code: Select all

defaultBox = NewtonCreateBox (nWorld, 2, 2, 2, NULL);
car->body = NewtonCreateBody (nWorld, defaultBox);

float matrix[4][4] = {1,0,0,0,
                 0,1,0,0,
                 0,0,1,0,
                 0,3,5,1};

NewtonBodySetForceAndTorqueCallback(car->body, CharacterCallBack);
      NewtonBodySetMatrix (car->body, &(matrix)[0][0]);
      NewtonBodySetMassMatrix(car->body, 1000, 1, 1, 1);

NewtonReleaseCollision (nWorld, defaultBox);

//Joint
float upDirection[] = {0.0f, 1.0f, 0.0f};
Vehicle_Joint = NewtonConstraintCreateVehicle (nWorld, &upDirection[0], Box1->body);
//Tires
NewtonVehicleSetTireCallback(Vehicle_Joint, TireUpdate);

//Add Tires
float offset_matrix_Front_Left[16] = {1,0,0,0,
                     0,1,0,0,
                     0,0,1,0,
                     -5,-3,-5,1};
float offset_matrix_Front_Right[16] = {1,0,0,0,
                     0,1,0,0,
                     0,0,1,0,
                     5,-3,-5,1};
float offset_matrix_Back_Left[16] = {1,0,0,0,
                     0,1,0,0,
                     0,0,1,0,
                     -5,-3,5,1};
float offset_matrix_Back_Right[16] = {1,0,0,0,
                     0,1,0,0,
                     0,0,1,0,
                     5,-3,5,1};

float tirePin[] =  {0.0, 0.0, 1.0f};

NewtonVehicleAddTire(Vehicle_Joint, &offset_matrix_Front_Left[0], &tirePin[0], 5.0, .25f, .32,
                81.0, 6666.0, .3, NULL, 666);

NewtonVehicleAddTire(Vehicle_Joint, &offset_matrix_Front_Right[0], &tirePin[0], 5.0, .25f, .32,
               81.0, 6666.0, .3, NULL, 666);

NewtonVehicleAddTire(Vehicle_Joint, &offset_matrix_Back_Left[0], &tirePin[0], 5.0, .25f, .32,
                81.0, 6666.0, .3, NULL, 666);

NewtonVehicleAddTire(Vehicle_Joint, &offset_matrix_Back_Right[0], &tirePin[0], 5.0, .25f, .32,
               81.0, 6666.0, .3, NULL, 666);




And here are my basic callbacks....

void TireUpdate (const NewtonJoint* vehicle)
{
void* tyreId;

// iterate trough each tire applying the tire dynamics
for (tyreId = NewtonVehicleGetFirstTireID (vehicle); tyreId; tyreId = NewtonVehicleGetNextTireID (vehicle, tyreId))
{
//apply forces to this tire
NewtonVehicleSetTireTorque( Vehicle_Joint, tyreId, -5.0);

}
}

void CharacterCallBack(const NewtonBody* body)
{
float velocity[3];
float gravity[3] = {0,-9.8*1000,0};

NewtonBodySetForce( body, &gravity[0]);
}
adam450
 
Posts: 21
Joined: Fri Jan 16, 2009 11:11 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 13 guests