//Render Loop
- Code: Select all
DGRaycastVehicleSetCustomTireTorque(Car.DGCar,0,500);
DGRaycastVehicleSetCustomTireTorque(Car.DGCar,1,500);
UpdateWorld(SystemTimer.FrameTime);
//Actual Car
- Code: Select all
constructor TRayCastCar.Create(Size : TVec3f; World : PNewtonWorld);
var
Collision : PNewtonCollision;
Body : PNewtonBody;
origin,
inertia : TVec4f;
Mass,
Ixx,
Iyy,
Izz : Single;
begin
FMatrix := IdentityMatrix;
Collision := NewtonCreateBox(World,Size[0],Size[1],Size[2],0,Nil);
Body := NewtonCreateBody(World, Collision);
// save the pointer to the graphic object with the body.
NewtonBodySetUserData (Body, Self);
// set the material group id for vehicle
NewtonBodySetMaterialGroupID (Body, 0);
// set a destructor for this rigid body
// NewtonBodySetDestructorCallback (rigidBody, PhysicsBodyDestructor);
// set the force and torque call back function
NewtonBodySetForceAndTorqueCallback (Body, @PhysicsApplyForceAndTorque);
// set the transform call back function
NewtonBodySetTransformCallback (Body, @PhysicsSetTransform);
// set the matrix for both the rigid body and the graphic body
NewtonBodySetMatrix (Body, @FMatrix[0][0]);
origin := SetVec4(0, 0, 0, 1);
inertia := SetVec4(0, 0, 0, 1);
// calculate the moment of inertia and the relative center of mass of the solid
NewtonConvexCollisionCalculateInertialMatrix (Collision, @inertia[0], @origin[0]);
mass := 800;
Ixx := mass * inertia[0];
Iyy := mass * inertia[1];
Izz := mass * inertia[2];
NewtonBodySetCentreOfMass (Body, @origin[0]);
// set the mass matrix
NewtonBodySetMassMatrix (Body, mass, Ixx, Iyy, Izz);
// release the collision
NewtonReleaseCollision (World, Collision);
FMatrix := IdentityMatrix;
FDGCar := DGRaycastVehicleCreate(4,@FMatrix[0,0],Body);
AddTire(SetVec3(5,0,-5));
AddTire(SetVec3(5,0,5));
AddTire(SetVec3(-5,0,5));
AddTire(SetVec3(-5,0,-5));
Matrix4fTransform(FMatrix,SetVec3(0,70,0));
NewtonBodySetMatrix (Body, @FMatrix[0][0]);
end;
procedure TRayCastCar.AddTire(P : TVec3f);
begin
DGRaycastVehicleAddTire(FDGCar,Nil,@P[0], 25, 5, 1, 2.5, 0.2, 200.0, 6.0, 1);
end;