Package jsim.dynamics

Class RigidBody

java.lang.Object
jsim.dynamics.RigidBody

public final class RigidBody extends Object
A single rigid body in the simulation.

All physics state is stored as raw doubles for determinism and performance. WPILib types are used only at the read/write surface (getPose, setPose, etc.).

Bodies are created and owned by PhysicsWorld; use SimBodyBuilder to configure them before adding.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final double[]
    Cached world-frame AABB for broadphase.
    Collision shape attached to this body, or null for no collision.
    int
    Bitmask of RigidBodyFlags.
    double
    Net force X component accumulated this tick (N).
    double
    Net force Y component accumulated this tick (N).
    double
    Net force Z component accumulated this tick (N).
    double
    Body-frame diagonal inertia tensor components (kg·m²).
    double
    Body-frame diagonal inertia tensor components (kg·m²).
    double
    Body-frame diagonal inertia tensor components (kg·m²).
    int
    World-assigned unique ID, set by PhysicsWorld on registration.
    final double[]
    World-frame inverse inertia tensor (3x3 row-major).
    double
    1/mass.
    Surface material used for collision response.
    final String
    Human-readable label for debugging.
    double
    Angular velocity X component in world frame (rad/s).
    double
    Angular velocity Y component in world frame (rad/s).
    double
    Angular velocity Z component in world frame (rad/s).
    double
    Position X coordinate in world frame (metres).
    double
    Position Y coordinate in world frame (metres).
    double
    Position Z coordinate in world frame (metres).
    double
    Orientation quaternion W component.
    double
    Orientation quaternion X component.
    double
    Orientation quaternion Y component.
    double
    Orientation quaternion Z component.
    double
    Net torque X component accumulated this tick (N·m).
    double
    Net torque Y component accumulated this tick (N·m).
    double
    Net torque Z component accumulated this tick (N·m).
    double
    Linear velocity X component in world frame (m/s).
    double
    Linear velocity Y component in world frame (m/s).
    double
    Linear velocity Z component in world frame (m/s).
  • Constructor Summary

    Constructors
    Constructor
    Description
    RigidBody(String name, int flags, Material material)
    Create a rigid body with the given name, flags, and surface material.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyForce(double fx, double fy, double fz)
    Apply a force at the centre of mass (world frame).
    void
    applyForceAtPoint(double fx, double fy, double fz, double px, double py, double pz)
    Apply a world-frame force at a world-frame point.
    void
    applyTorque(double tx, double ty, double tz)
    Apply a torque directly (world frame).
    void
    Zero out force and torque accumulators.
    edu.wpi.first.math.geometry.Translation3d
     
    int
     
    edu.wpi.first.math.geometry.Translation3d
     
    edu.wpi.first.math.geometry.Pose3d
     
    boolean
    Whether this body participates as an infinite-mass static wall.
    void
    Re-normalize the orientation quaternion (guards against drift).
    void
    Recompute invIWorld from current orientation and body-frame inertia.
    void
    setAngularVelocity(edu.wpi.first.math.geometry.Translation3d omega)
    Set the angular velocity directly.
    void
    setLinearVelocity(edu.wpi.first.math.geometry.Translation3d v)
    Set the linear velocity directly.
    void
    setMassProperties(double mass, double ixx, double iyy, double izz)
    Set mass and diagonal body-frame inertia tensor.
    void
    setPose(edu.wpi.first.math.geometry.Pose3d pose)
    Teleport this body to the given pose and refresh derived state.
    void
    Make this body infinitely massive (static boundary).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • id

      public int id
      World-assigned unique ID, set by PhysicsWorld on registration.
    • name

      public final String name
      Human-readable label for debugging.
    • flags

      public int flags
      Bitmask of RigidBodyFlags.
    • posX

      public double posX
      Position X coordinate in world frame (metres).
    • posY

      public double posY
      Position Y coordinate in world frame (metres).
    • posZ

      public double posZ
      Position Z coordinate in world frame (metres).
    • qW

      public double qW
      Orientation quaternion W component. Unit quaternion (w + xi + yj + zk).
    • qX

      public double qX
      Orientation quaternion X component.
    • qY

      public double qY
      Orientation quaternion Y component.
    • qZ

      public double qZ
      Orientation quaternion Z component.
    • velX

      public double velX
      Linear velocity X component in world frame (m/s).
    • velY

      public double velY
      Linear velocity Y component in world frame (m/s).
    • velZ

      public double velZ
      Linear velocity Z component in world frame (m/s).
    • omX

      public double omX
      Angular velocity X component in world frame (rad/s).
    • omY

      public double omY
      Angular velocity Y component in world frame (rad/s).
    • omZ

      public double omZ
      Angular velocity Z component in world frame (rad/s).
    • forceX

      public double forceX
      Net force X component accumulated this tick (N).
    • forceY

      public double forceY
      Net force Y component accumulated this tick (N).
    • forceZ

      public double forceZ
      Net force Z component accumulated this tick (N).
    • torqueX

      public double torqueX
      Net torque X component accumulated this tick (N·m).
    • torqueY

      public double torqueY
      Net torque Y component accumulated this tick (N·m).
    • torqueZ

      public double torqueZ
      Net torque Z component accumulated this tick (N·m).
    • invMass

      public double invMass
      1/mass. 0 for static bodies (infinite mass).
    • iBodyXX

      public double iBodyXX
      Body-frame diagonal inertia tensor components (kg·m²).
    • iBodyYY

      public double iBodyYY
      Body-frame diagonal inertia tensor components (kg·m²).
    • iBodyZZ

      public double iBodyZZ
      Body-frame diagonal inertia tensor components (kg·m²).
    • invIWorld

      public final double[] invIWorld
      World-frame inverse inertia tensor (3x3 row-major). Recomputed each tick.
    • material

      public Material material
      Surface material used for collision response.
    • collider

      public ColliderShape collider
      Collision shape attached to this body, or null for no collision.
    • aabb

      public final double[] aabb
      Cached world-frame AABB for broadphase. Stored as [minX,minY,minZ,maxX,maxY,maxZ].
  • Constructor Details

    • RigidBody

      public RigidBody(String name, int flags, Material material)
      Create a rigid body with the given name, flags, and surface material.
      Parameters:
      name - human-readable label for debugging
      flags - bitmask of RigidBodyFlags constants
      material - initial surface material
  • Method Details

    • getPose

      public edu.wpi.first.math.geometry.Pose3d getPose()
      Returns:
      current pose in world frame
    • setPose

      public void setPose(edu.wpi.first.math.geometry.Pose3d pose)
      Teleport this body to the given pose and refresh derived state.
      Parameters:
      pose - new world-frame pose
    • getLinearVelocity

      public edu.wpi.first.math.geometry.Translation3d getLinearVelocity()
      Returns:
      linear velocity in world frame (m/s)
    • setLinearVelocity

      public void setLinearVelocity(edu.wpi.first.math.geometry.Translation3d v)
      Set the linear velocity directly.
      Parameters:
      v - new linear velocity in world frame (m/s)
    • getAngularVelocity

      public edu.wpi.first.math.geometry.Translation3d getAngularVelocity()
      Returns:
      angular velocity in world frame (rad/s)
    • setAngularVelocity

      public void setAngularVelocity(edu.wpi.first.math.geometry.Translation3d omega)
      Set the angular velocity directly.
      Parameters:
      omega - new angular velocity in world frame (rad/s)
    • applyForce

      public void applyForce(double fx, double fy, double fz)
      Apply a force at the centre of mass (world frame).
      Parameters:
      fx - X component (N)
      fy - Y component (N)
      fz - Z component (N)
    • applyTorque

      public void applyTorque(double tx, double ty, double tz)
      Apply a torque directly (world frame).
      Parameters:
      tx - X component (N·m)
      ty - Y component (N·m)
      tz - Z component (N·m)
    • applyForceAtPoint

      public void applyForceAtPoint(double fx, double fy, double fz, double px, double py, double pz)
      Apply a world-frame force at a world-frame point. Generates both a linear force and a torque about the centre of mass.
      Parameters:
      fx - force X component (N)
      fy - force Y component (N)
      fz - force Z component (N)
      px - application point X (metres)
      py - application point Y (metres)
      pz - application point Z (metres)
    • clearAccumulators

      public void clearAccumulators()
      Zero out force and torque accumulators. Called at the start of every tick.
    • setMassProperties

      public void setMassProperties(double mass, double ixx, double iyy, double izz)
      Set mass and diagonal body-frame inertia tensor.
      Parameters:
      mass - total mass (kg)
      ixx - body-frame inertia about X axis (kg·m²)
      iyy - body-frame inertia about Y axis (kg·m²)
      izz - body-frame inertia about Z axis (kg·m²)
    • setStatic

      public void setStatic()
      Make this body infinitely massive (static boundary).
    • refreshWorldInertia

      public void refreshWorldInertia()
      Recompute invIWorld from current orientation and body-frame inertia.
    • normalizeQuaternion

      public void normalizeQuaternion()
      Re-normalize the orientation quaternion (guards against drift).
    • isStatic

      public boolean isStatic()
      Whether this body participates as an infinite-mass static wall.
      Returns:
      true if the STATIC flag is set
    • getId

      public int getId()
      Returns:
      world-assigned unique body ID