Package jsim.dynamics
Class RigidBody
java.lang.Object
jsim.dynamics.RigidBody
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
FieldsModifier and TypeFieldDescriptionfinal double[]Cached world-frame AABB for broadphase.Collision shape attached to this body, ornullfor no collision.intBitmask ofRigidBodyFlags.doubleNet force X component accumulated this tick (N).doubleNet force Y component accumulated this tick (N).doubleNet force Z component accumulated this tick (N).doubleBody-frame diagonal inertia tensor components (kg·m²).doubleBody-frame diagonal inertia tensor components (kg·m²).doubleBody-frame diagonal inertia tensor components (kg·m²).intWorld-assigned unique ID, set by PhysicsWorld on registration.final double[]World-frame inverse inertia tensor (3x3 row-major).double1/mass.Surface material used for collision response.final StringHuman-readable label for debugging.doubleAngular velocity X component in world frame (rad/s).doubleAngular velocity Y component in world frame (rad/s).doubleAngular velocity Z component in world frame (rad/s).doublePosition X coordinate in world frame (metres).doublePosition Y coordinate in world frame (metres).doublePosition Z coordinate in world frame (metres).doubleOrientation quaternion W component.doubleOrientation quaternion X component.doubleOrientation quaternion Y component.doubleOrientation quaternion Z component.doubleNet torque X component accumulated this tick (N·m).doubleNet torque Y component accumulated this tick (N·m).doubleNet torque Z component accumulated this tick (N·m).doubleLinear velocity X component in world frame (m/s).doubleLinear velocity Y component in world frame (m/s).doubleLinear velocity Z component in world frame (m/s). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyForce(double fx, double fy, double fz) Apply a force at the centre of mass (world frame).voidapplyForceAtPoint(double fx, double fy, double fz, double px, double py, double pz) Apply a world-frame force at a world-frame point.voidapplyTorque(double tx, double ty, double tz) Apply a torque directly (world frame).voidZero out force and torque accumulators.edu.wpi.first.math.geometry.Translation3dintgetId()edu.wpi.first.math.geometry.Translation3dedu.wpi.first.math.geometry.Pose3dgetPose()booleanisStatic()Whether this body participates as an infinite-mass static wall.voidRe-normalize the orientation quaternion (guards against drift).voidRecompute invIWorld from current orientation and body-frame inertia.voidsetAngularVelocity(edu.wpi.first.math.geometry.Translation3d omega) Set the angular velocity directly.voidsetLinearVelocity(edu.wpi.first.math.geometry.Translation3d v) Set the linear velocity directly.voidsetMassProperties(double mass, double ixx, double iyy, double izz) Set mass and diagonal body-frame inertia tensor.voidsetPose(edu.wpi.first.math.geometry.Pose3d pose) Teleport this body to the given pose and refresh derived state.voidMake this body infinitely massive (static boundary).
-
Field Details
-
id
public int idWorld-assigned unique ID, set by PhysicsWorld on registration. -
name
Human-readable label for debugging. -
flags
public int flagsBitmask ofRigidBodyFlags. -
posX
public double posXPosition X coordinate in world frame (metres). -
posY
public double posYPosition Y coordinate in world frame (metres). -
posZ
public double posZPosition Z coordinate in world frame (metres). -
qW
public double qWOrientation quaternion W component. Unit quaternion (w + xi + yj + zk). -
qX
public double qXOrientation quaternion X component. -
qY
public double qYOrientation quaternion Y component. -
qZ
public double qZOrientation quaternion Z component. -
velX
public double velXLinear velocity X component in world frame (m/s). -
velY
public double velYLinear velocity Y component in world frame (m/s). -
velZ
public double velZLinear velocity Z component in world frame (m/s). -
omX
public double omXAngular velocity X component in world frame (rad/s). -
omY
public double omYAngular velocity Y component in world frame (rad/s). -
omZ
public double omZAngular velocity Z component in world frame (rad/s). -
forceX
public double forceXNet force X component accumulated this tick (N). -
forceY
public double forceYNet force Y component accumulated this tick (N). -
forceZ
public double forceZNet force Z component accumulated this tick (N). -
torqueX
public double torqueXNet torque X component accumulated this tick (N·m). -
torqueY
public double torqueYNet torque Y component accumulated this tick (N·m). -
torqueZ
public double torqueZNet torque Z component accumulated this tick (N·m). -
invMass
public double invMass1/mass. 0 for static bodies (infinite mass). -
iBodyXX
public double iBodyXXBody-frame diagonal inertia tensor components (kg·m²). -
iBodyYY
public double iBodyYYBody-frame diagonal inertia tensor components (kg·m²). -
iBodyZZ
public double iBodyZZBody-frame diagonal inertia tensor components (kg·m²). -
invIWorld
public final double[] invIWorldWorld-frame inverse inertia tensor (3x3 row-major). Recomputed each tick. -
material
Surface material used for collision response. -
collider
Collision shape attached to this body, ornullfor no collision. -
aabb
public final double[] aabbCached world-frame AABB for broadphase. Stored as [minX,minY,minZ,maxX,maxY,maxZ].
-
-
Constructor Details
-
RigidBody
Create a rigid body with the given name, flags, and surface material.- Parameters:
name- human-readable label for debuggingflags- bitmask ofRigidBodyFlagsconstantsmaterial- 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
-