Package jsim.core

Class PhysicsWorld

java.lang.Object
jsim.core.PhysicsWorld

public final class PhysicsWorld extends Object
The central simulation world.

Advances through a strict deterministic pipeline on each call to step(double):

  1. Clear force/torque accumulators on all bodies.
  2. Apply all registered force generators (gravity, drag, magnus, actuators).
  3. Broadphase — AABB overlap test, produces candidate pairs.
  4. Narrowphase — geometry-accurate contact generation.
  5. Solve — iterative impulse projection (normal + friction).
  6. Integrate — semi-implicit Euler: v += a·dt, x += v·dt; quaternion update.
  7. Positional correction — Baumgarte (baked into solver bias).
  8. Update derived state — AABB refresh, quaternion normalisation, inertia refresh.

The API layer (SimWorld) owns this object and delegates to it. External code should not reference this class directly.

  • Constructor Details

    • PhysicsWorld

      public PhysicsWorld()
      Creates a world with default solver iteration count.
    • PhysicsWorld

      public PhysicsWorld(int solverIterations)
      Creates a world with the given solver iteration count.
      Parameters:
      solverIterations - number of impulse-solver iterations per tick
  • Method Details

    • addBody

      public void addBody(RigidBody body)
      Add a body to the world and assign it a unique ID.
      Parameters:
      body - the body to register
    • removeBody

      public void removeBody(RigidBody body)
      Remove a body from the world.
      Parameters:
      body - the body to remove
    • addForceGenerator

      public void addForceGenerator(ForceGenerator fg)
      Register an additional force generator (e.g. actuator, drag, magnus).
      Parameters:
      fg - the force generator to add
    • removeForceGenerator

      public void removeForceGenerator(ForceGenerator fg)
      Unregister a previously added force generator.
      Parameters:
      fg - the force generator to remove
    • getBodies

      public List<RigidBody> getBodies()
      Read-only view of all bodies for sensors/tracking.
      Returns:
      unmodifiable list of all registered bodies
    • step

      public void step(double dt)
      Advance the simulation by exactly dt seconds. Always use a fixed timestep for determinism.
      Parameters:
      dt - timestep in seconds