However calling DGRaycastVehicleCreate makes Newton crash next time NewtonUpdate is called.
I'm using Delphi, the error that appears when crashing is not much informative, seems to be a read from adress 0000000 on the newton DLL.
Here is my code, I've compared it with the tutorials and it seems ok.
Note that even if I comment the DGRaycastVehicleSetTireTransformCallback and DGRaycastVehicleAddTire it still crashes.
If I comment DGRaycastVehicleCreate it runs fine (but of course, there is no car physics, just a normal box)
What could it be?
- Code: Select all
Procedure Kart.InitPhysics;
Var
P:Vector3D;
origin, inertia:Vector3D;
chassisMatrix, M:Matrix;
I:Integer;
Collision :PNewtonCollision;
Begin
_Size := VectorCreate(7, 4, 12);
Collision := NewtonCreateBox(_World, _Size.x, _Size.y, _Size.z, 0, nil);
// Create the rigid body
_Body := NewtonCreateBody(_World, Collision, @MatrixIdentity);
// Now we calculate the moment of intertia for this box. Note that a correct
// moment of inertia is CRUCIAL for the CORRECT PHYSICAL BEHAVIOUR of a body,
// so we use an special equation for calculating it
P.x := CarMass * (_Size.y * _Size.y + _Size.z * _Size.z) / 12;
P.y := CarMass * (_Size.x * _Size.x + _Size.z * _Size.z) / 12;
P.z := CarMass * (_Size.x * _Size.x + _Size.y * _Size.y) / 12;
// Set the bodies mass and moment of inertia
NewtonBodySetMassMatrix(_Body, CarMass, P.x, P.y, P.z);
// the first thing we need to do is to place the vehicle center of Mass on a stable position for a car
NewtonConvexCollisionCalculateInertialMatrix(Collision, @inertia, @origin);
//displace the center of mass by some value
origin.Y := origin.Y - 0.5 * _Size.Y * LOW_CENTER_OF_MASS_FACTOR;
// now we Set a new center of mass for this car
NewtonBodySetCentreOfMass(_body, @origin);
// Next we need to set the internal coordinate system of the car geometry
// this particular demo the car direction of motion is axis (1, 0, 0)
// the car up direction (0, 1, 0);
// the car lateral direction is the cross product of the front and vertical axis
chassisMatrix := MatrixIdentity;
// create a vehicle joint with 4 tires
_Joint := DGRaycastVehicleCreate(4, @chassisMatrix, _Body);
// now we will add four tires to this vehicle,
For I:=0 To 3 Do
DGRaycastVehicleAddTire(_Joint, @_Wheels[I], @(_Wheels[I].Center), TIRE_MASS, _Wheels[I].Radius, _Wheels[I].Width, 2.5, 0.25, 150.0, 5.0, 1);
// Now set the position of the body's matrix
NewtonBodyGetMatrix(_Body, @M);
M.V[12] := _Position.x;
M.V[13] := _Position.y;
M.V[14] := _Position.z;
NewtonBodySetMatrix(_Body, @M);
// Finally set the callback in which the forces on this body will be applied
NewtonBodySetForceAndTorqueCallBack(_Body, ForceAndTorqueCallBack);
// we need to set a transform call back to render the tire entities
DGRaycastVehicleSetTireTransformCallback(_Joint, TireTransformCallback);
// Remove the collider, we don't need it anymore
NewtonReleaseCollision(_World, Collision);
NewtonBodySetUserData(_Body, Self);
End;