Back to main page

Physics

The physics interface handle everything with physics that does not belong to a collection.

void Physics_Step(float TimeStep);

This is the main method for simulating physics. You must call it with a fixed timestep to keep the simulation stable.

After simulating a variable number of fixed steps it is recomended to call Physics_LetInstancesFollowRigidBodies_Interpolated with the remaining time before rendering.

TimeStep is the time in seconds that is simulated in one step. 1/60 = low quality, 1/120 = medium quality, 1/240 = high quality

If the timestep is too short, the result might get worse from 32 bit rounding errors.

TimeStep > 0 and TimeStep is the same value each step.

Simulate TimeStep seconds

void Physics_SetGravity(float X,float Y,float Z);

Sets the world's gravity force to (X,Y,Z).

void Physics_GetGravity_OutV3(void);

Writes the world's gravity force to (X1,Y1,Z1) in the matrix buffer.

void Physics_SetDebugDrawRadius(float NewValue);

The debug draw radius is used for some types of debug drawing that would take too much performance if everything was seen at the same time.

It defines how far from the camera things must be visible in the debug drawing. The default value is 10 length units.

See Camera_SetDebugViewVisibility for information about which debug views are using this.

Sets the debug draw radius to NewValue.

float Physics_GetDebugDrawRadius(void);

Returns the debug draw radius.

void Physics_LetInstancesFollowRigidBodies(void);

For this to work, you must call Instance_FollowRigidBody to connect instances to rigid bodies.

Since this method only update for active dynamic bodies, you must call it often enough so that a body can't get activated and go back to sleep between 2 calls since that would cause the visual instance to not follow it's rigid body.

All active and dynamic rigid bodies that have any visual instance assigned using Instance_FollowRigidBody will be synchronized as if you called Instance_PlaceAtRigidBody for each following instance.

void Physics_LetInstancesFollowRigidBodies_Interpolated(float TimeOffset);

This method is like Physics_LetInstancesFollowRigidBodies but with interpolation. It is like calling Instance_PlaceAtRigidBody_Interpolated instead of Instance_PlaceAtRigidBody for every pair.

For this to work, you must call Instance_FollowRigidBody to connect instances to rigid bodies in a "follow" relation.

Since this method only update for active dynamic bodies, you must call it often enough so that a body can't get activated and go back to sleep between 2 calls since that would cause the visual instance to not follow it's rigid body.

All active and dynamic rigid bodies that have any visual instance assigned using Instance_FollowRigidBody will be synchronized as if you called Instance_PlaceAtRigidBody_Interpolated for each following instance.

int Physics_GetAllContactsFromLastStep_OutCB(bool IncludeContactsFromSleepingBodies);

This method can be used to generate particles.

Writes all the contacts from the last simulation step into the contact buffer.

Returns the number of contacts in the contact buffer. All methods with the "_OutCB" postfix have this postcondition.

int Physics_GetAllPairSumContactsFromLastStep_OutCB(bool IncludeContactsFromSleepingBodies);

This method can be used to generate sound effects because it does not create multiple contact points for one pair of bodies.

Writes the sum of impulses at the average position and normal for each colliding pair of bodies from the last simulation step into the contact buffer.

Returns the number of contacts in the contact buffer. All methods with the "_OutCB" postfix have this postcondition.