ForceSimulation

class ForceSimulation(val bodies: MutableList<Body> = mutableListOf())(source)

Represents a physics simulation of interacting bodies.

The ForceSimulation class provides the infrastructure to simulate the dynamics of a system of bodies under the influence of forces and constraints. It supports customizable interbody forces, collision detection, and resolution, allowing for a wide variety of physical interactions.

Constructors

Link copied to clipboard
constructor(bodies: MutableList<Body> = mutableListOf())

Properties

Link copied to clipboard
Link copied to clipboard

The list of Body objects participating in the simulation. Each body has its own properties, forces, and constraints that determine its behavior.

Link copied to clipboard

The collision detection algorithm used to identify potential overlapping pairs of bodies during the simulation. It operates in the broad-phase stage of collision resolution.

Link copied to clipboard

The collision resolution handler responsible for determining the outcome of detected collisions between bodies.

Link copied to clipboard

The coroutine context in which the simulation runs, allowing for asynchronous computations. By default, it uses Dispatchers.Default.

Link copied to clipboard

A list of interbody forces that affect pairs of bodies in the simulation. These forces are computed per pair of bodies and influence their dynamics.

Functions

Link copied to clipboard

Configures the force simulation to use the naive broad-phase collision detection algorithm.

Link copied to clipboard

Adds a NodeRepulseInterbodyForce to the list of interbody forces in the simulation.

Link copied to clipboard

Adds a repulsive interbody force using a bounding volume hierarchy (BVH) to the simulation.

Link copied to clipboard

Sets the collision resolution handler to a sweep-and-prune (SAP) based collision constraint.

Link copied to clipboard
suspend fun simulate(dt: Double, substeps: Int = 10)