- constructor TCharacterController.Create;
- const
- UpDir : array[0..2] of Single = (0, 1, 0);
- var
- BaseCollider : PNewtonCollision;
- UpVector : PNewtonJoint;
- Collider : PNewtonCollision;
- StartMatrix : TMatrix4f;
- begin
- // Create a sphere as base for the collider
- BaseCollider := NewtonCreateSphere(NewtonWorld, 5, 8, 5, nil);
- // Convert the sphere into a convex hull modifier
- Collider := NewtonCreateConvexHullModifier(NewtonWorld, BaseCollider);
- NewtonReleaseCollision(NewtonWorld, BaseCollider);
- // Create rigid body
- Body := NewtonCreateBody(NewtonWorld, Collider);
- // Disable auto freezing
- NewtonBodySetAutoFreeze(Body, 0);
- // Activate him
- NewtonWorldUnfreezeBody(NewtonWorld, Body);
- //
- NewtonBodySetForceAndTorqueCallBack(Body, ApplyForceAndTorque);
- NewtonBodySetTransformCallBack(Body, PhysicsSetTransform);
- //
- NewtonBodySetMassMatrix(Body, 5, 5, 5, 5);
- //
- Matrix_SetIdentity(StartMatrix);
- Matrix_SetTransform(StartMatrix, V3(0, 20, 0));
- NewtonBodySetMatrix(Body, @StartMatrix[0,0]);
- // Add an up vector contraint to help in keepin the body upright
- UpVector := NewtonConstraintCreateUpVector(NewtonWorld, @UpDir[0], Body);
- // Release the collision geometry when not need it
- NewtonReleaseCollision(NewtonWorld, Collider);
- end;