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]);
}