Class BodyInterface

All Implemented Interfaces:
ConstJoltPhysicsObject, AutoCloseable, Comparable<ConstJoltPhysicsObject>

public class BodyInterface extends NonCopyable
An interface to a PhysicsSystem that's used to create, add, modify, query, remove, and delete bodies.
  • Method Details

    • activateBody

      public void activateBody(ConstBodyId bodyId)
      Activate the specified body.
      Parameters:
      bodyId - the ID of the body to activate (not null, unaffected)
    • addBody

      public void addBody(ConstBodyId bodyId, EActivation activation)
      Add the specified body to the physics system.
      Parameters:
      bodyId - the ID of the body to add (not null, unaffected)
      activation - whether to activate the body (not null)
    • addForce

      public void addForce(ConstBodyId bodyId, Vec3Arg force)
      Apply the specified force to the specified body's center of mass.
      Parameters:
      bodyId - the ID of the body (not null, unaffected)
      force - the force vector (not null, unaffected)
    • addForce

      public void addForce(ConstBodyId bodyId, Vec3Arg force, RVec3Arg location)
      Apply the specified force to the specified body at the specified location.
      Parameters:
      bodyId - the ID of the body (not null, unaffected)
      force - the force vector (not null, unaffected)
      location - where to apply the force (not null, unaffected)
    • addImpulse

      public void addImpulse(ConstBodyId bodyId, Vec3Arg impulse)
      Apply the specified impulse to the specified body's center of mass.
      Parameters:
      bodyId - the ID of the body (not null, unaffected)
      impulse - the impulse vector (not null, unaffected)
    • addImpulse

      public void addImpulse(ConstBodyId bodyId, Vec3Arg impulse, RVec3Arg location)
      Apply the specified impulse to the specified body at the specified location.
      Parameters:
      bodyId - the ID of the body (not null, unaffected)
      impulse - the impulse vector (not null, unaffected)
      location - where to apply the impulse (not null, unaffected)
    • addTorque

      public void addTorque(ConstBodyId bodyId, Vec3Arg torque)
      Apply the specified torque to the specified body.
      Parameters:
      bodyId - the ID of the body (not null, unaffected)
      torque - the torque vector (not null, unaffected)
    • createAndAddBody

      public BodyId createAndAddBody(BodyCreationSettings settings, EActivation activationMode)
      Create a body and add it to the physics system.
      Parameters:
      settings - the settings to use (not null, unaffected)
      activationMode - whether to activate the body (not null)
      Returns:
      the ID of the created body, or an invalid ID when out of bodies
    • createBody

      public Body createBody(ConstBodyCreationSettings settings)
      Create a body using the specified settings.
      Parameters:
      settings - the settings to use (not null, unaffected)
      Returns:
      the new body
    • createConstraint

      public TwoBodyConstraint createConstraint(TwoBodyConstraintSettings settings, ConstBodyId body1Id, ConstBodyId body2Id)
      Create a two-body constraint using the specified settings.
      Parameters:
      settings - the settings to use (not null, unaffected)
      body1Id - the ID of the first body (not null, unaffected)
      body2Id - the ID of the 2nd body (not null, unaffected)
      Returns:
      the new constraint
    • deactivateBody

      public void deactivateBody(ConstBodyId bodyId)
      Deactivate the specified body.
      Parameters:
      bodyId - the ID of the body to deactivate (not null, unaffected)
    • destroyBody

      public void destroyBody(ConstBodyId bodyId)
      Destroy the specified body.
      Parameters:
      bodyId - the ID of the body to destroy (not null)
    • getAngularVelocity

      public Vec3 getAngularVelocity(ConstBodyId bodyId)
      Return the angular velocity of the specified body.
      Parameters:
      bodyId - the ID of the body (not null)
      Returns:
      a new velocity vector (radians per second in physics-system coordinates)
    • getBodyType

      public EBodyType getBodyType(ConstBodyId bodyId)
      Return the type of the specified body.
      Parameters:
      bodyId - the ID of the body to query (not null)
      Returns:
      an enum value (not null)
    • getCenterOfMassPosition

      public RVec3 getCenterOfMassPosition(ConstBodyId bodyId)
      Locate the center of mass of the specified body.
      Parameters:
      bodyId - the ID of the body to locate (not null)
      Returns:
      a new location vector (in physics-system coordinates)
    • getFriction

      public float getFriction(ConstBodyId bodyId)
      Return the friction ratio of the specified body.
      Parameters:
      bodyId - the ID of the body (not null)
      Returns:
      the ratio
    • getGravityFactor

      public float getGravityFactor(ConstBodyId bodyId)
      Return the gravity factor of the specified body.
      Parameters:
      bodyId - the ID of the body (not null)
      Returns:
      the factor
    • getLinearVelocity

      public Vec3 getLinearVelocity(ConstBodyId bodyId)
      Return the linear velocity of the specified body.
      Parameters:
      bodyId - the ID of the body (not null)
      Returns:
      a new velocity vector (meters per second in physics-system coordinates)
    • getMotionType

      public EMotionType getMotionType(ConstBodyId bodyId)
      Return the motion type of the specified body.
      Parameters:
      bodyId - the ID of the body to query (not null, unaffected)
      Returns:
      an enum value (not null)
    • getPosition

      public RVec3 getPosition(ConstBodyId bodyId)
      Locate the specified body.
      Parameters:
      bodyId - the ID of the body to locate (not null, unaffected)
      Returns:
      a new location vector (in physics-system coordinates)
    • getPositionAndRotation

      public void getPositionAndRotation(ConstBodyId bodyId, RVec3 storeLocation, Quat storeOrientation)
      Copy the location and orientation of the specified body.
      Parameters:
      bodyId - the ID of the body to locate (not null, unaffected)
      storeLocation - storage for the location (not null, modified)
      storeOrientation - storage for the orientation (not null, modified)
    • getRestitution

      public float getRestitution(ConstBodyId bodyId)
      Return the restitution ratio of the specified body.
      Parameters:
      bodyId - the ID of the body to query (not null)
      Returns:
      the value (typically ≥0 and ≤1)
    • getRotation

      public Quat getRotation(ConstBodyId bodyId)
      Return the orientation of the specified body.
      Parameters:
      bodyId - the ID of the body (not null, unaffected)
      Returns:
      a new rotation quaternion
    • getShape

      public ShapeRefC getShape(ConstBodyId bodyId)
      Access the body's shape.
      Parameters:
      bodyId - the ID of the body (not null, unaffected)
      Returns:
      a new reference
    • getSystem

      public PhysicsSystem getSystem()
      Access the underlying PhysicsSystem.
      Returns:
      the pre-existing instance
    • isActive

      public boolean isActive(ConstBodyId bodyId)
      Test whether the specified body is active.
      Parameters:
      bodyId - the ID of the body to test (not null, unaffected)
      Returns:
      true if active, otherwise false
    • isAdded

      public boolean isAdded(ConstBodyId bodyId)
      Test whether the specified body is added to the system.
      Parameters:
      bodyId - the ID of the body to test (not null, unaffected)
      Returns:
      true if added, otherwise false
    • moveKinematic

      public void moveKinematic(ConstBodyId bodyId, RVec3Arg location, QuatArg orientation, float deltaTime)
      Reposition the specified body, assuming it's kinematic.
      Parameters:
      bodyId - the ID of the body to reposition (not null, unaffected)
      location - the desired location (in physics-system coordinates, not null, unaffected)
      orientation - the desired orientation (relative to the physics-system axes, not null, unaffected)
      deltaTime - time until the desired position is reached (in seconds, >0)
    • notifyShapeChanged

      public void notifyShapeChanged(ConstBodyId bodyId, Vec3Arg prevCom, boolean updateMassProperties, EActivation activation)
      Notify all systems that the shape of the specified body has changed.
      Parameters:
      bodyId - the ID of the affected body (not null, unaffected)
      prevCom - center of mass prior to the change (not null, unaffected)
      updateMassProperties - true to recalculate mass and inertia
      activation - whether to activate the body (not null)
    • removeBody

      public void removeBody(ConstBodyId bodyId)
      Remove the specified body from the physics system.
      Parameters:
      bodyId - the ID of the body to remove (not null, unaffected)
    • setAngularVelocity

      public void setAngularVelocity(ConstBodyId bodyId, Vec3Arg omega)
      Alter the linear velocity of the specified body.
      Parameters:
      bodyId - the ID of the body to modify (not null, unaffected)
      omega - the desired rates (not null, unaffected)
    • setFriction

      public void setFriction(ConstBodyId bodyId, float friction)
      Alter the friction ratio of the specified body.
      Parameters:
      bodyId - the ID of the body to modify (not null, unaffected)
      friction - the desired ratio (typically ≥0 and ≤1, default=0.2)
    • setGravityFactor

      public void setGravityFactor(ConstBodyId bodyId, float factor)
      Alter the gravity factor of the specified body.
      Parameters:
      bodyId - the ID of the body to modify (not null, unaffected)
      factor - the desired factor (default=1)
    • setLinearAndAngularVelocity

      public void setLinearAndAngularVelocity(ConstBodyId bodyId, Vec3Arg linearVelocity, Vec3Arg angularVelocity)
      Alter the linear and angular velocities of the specified body.
      Parameters:
      bodyId - the ID of the body to modify (not null, unaffected)
      linearVelocity - the desired linear velocity of body's the center of mass (not null, unaffected)
      angularVelocity - the desired angular velocity (not null, unaffected)
    • setLinearVelocity

      public void setLinearVelocity(ConstBodyId bodyId, Vec3Arg velocity)
      Alter the linear velocity of the specified body.
      Parameters:
      bodyId - the ID of the body to modify (not null, unaffected)
      velocity - the desired velocity (not null, unaffected)
    • setPositionAndRotation

      public void setPositionAndRotation(ConstBodyId bodyId, RVec3Arg location, QuatArg orientation, EActivation activationMode)
      Alter the location and orientation of the specified body.
      Parameters:
      bodyId - the ID of the body to modify (not null, unaffected)
      location - the desired location (not null, unaffected)
      orientation - the desired orientation (not null, unaffected)
      activationMode - whether to activate the body (not null)
    • setRestitution

      public void setRestitution(ConstBodyId bodyId, float restitution)
      Alter the restitution ratio of the specified body.
      Parameters:
      bodyId - the ID of the body to modify (not null, unaffected)
      restitution - the desired ratio (typically ≥0 and ≤1, default=0)