Class BodyInterface

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

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

    • activateBodiesInAaBox

      public void activateBodiesInAaBox(ConstAaBox box, BroadPhaseLayerFilter bplFilter, ObjectLayerFilter olFilter)
      Active all bodies within the specified bounds that satisfy the specified filters.
      Parameters:
      box - the bounds to use (not null, unaffected)
      bplFilter - the broadphase layer filter to apply (not null, unaffected)
      olFilter - the object-layer filter to apply (not null, unaffected)
    • activateBody

      public void activateBody(int bodyId)
      Activate the specified body.
      Parameters:
      bodyId - the ID of the body to activate
    • activateConstraint

      public void activateConstraint(ConstTwoBodyConstraint constraint)
      Activate all non-static bodies attached to the specified constraint.
      Parameters:
      constraint - the constraint to activate (not null)
    • addAngularImpulse

      public void addAngularImpulse(int bodyId, Vec3Arg angularImpulse)
      Apply the specified angular impulse to the specified body.
      Parameters:
      bodyId - the ID of the body
      angularImpulse - the impulse vector (not null, unaffected)
    • addBodiesAbort

      public void addBodiesAbort(BodyIdArray bodyIds, int numBodies, long addState)
      Abort adding bodies to the physics system.
      Parameters:
      bodyIds - the IDs of the bodies to be added (not null, unmodified since the handle was created)
      numBodies - the number of bodies to be added (≥0)
      addState - the handle returned by addBodiesPrepare()
    • addBodiesFinalize

      public void addBodiesFinalize(BodyIdArray bodyIds, int numBodies, long addState, EActivation activation)
      Finish adding bodies to the physics system.
      Parameters:
      bodyIds - the IDs of the bodies to be added (not null, unmodified since the handle was created)
      numBodies - the number of bodies to be added (≥0)
      addState - the handle returned by addBodiesPrepare()
      activation - whether to activate the bodies (not null)
    • addBodiesPrepare

      public long addBodiesPrepare(BodyIdArray bodyIds, int numBodies)
      Prepare to add a batch of bodies to the physics system.
      Parameters:
      bodyIds - the IDs of the bodies to be added (not null, possibly shuffled)
      numBodies - the number of bodies to be added (≥0)
      Returns:
      a handle to be passed to addBodiesFinalize() or addBodiesAbort()
    • addBody

      public void addBody(ConstBody body, EActivation activation)
      Add the specified body to the physics system.

      To add many bodies at once, use addBodiesPrepare() followed by addBodiesFinalize().

      Parameters:
      body - the body to add (not null)
      activation - whether to activate the body (not null)
    • addBody

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

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

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

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

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

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

      public int createAndAddBody(ConstBodyCreationSettings settings, EActivation activationMode)
      Create a rigid 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
    • createAndAddSoftBody

      public int createAndAddSoftBody(ConstSoftBodyCreationSettings settings, EActivation activationMode)
      Create a soft 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 rigid body using the specified settings.
      Parameters:
      settings - the settings to use (not null, unaffected)
      Returns:
      the new body
    • createConstraint

      public TwoBodyConstraint createConstraint(TwoBodyConstraintSettings settings, int body1Id, int 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
      body2Id - the ID of the 2nd body
      Returns:
      the new constraint
    • createSoftBody

      public Body createSoftBody(ConstSoftBodyCreationSettings settings)
      Create a soft body using the specified settings.
      Parameters:
      settings - the settings to use (not null, unaffected)
      Returns:
      the new body
    • deactivateBody

      public void deactivateBody(int bodyId)
      Deactivate the specified body.
      Parameters:
      bodyId - the ID of the body to deactivate
    • destroyBody

      public void destroyBody(int bodyId)
      Destroy the specified body. Don't use this on a body that has been added but not removed yet!
      Parameters:
      bodyId - the ID of the body to destroy
    • getAngularVelocity

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

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

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

      public RMat44 getCenterOfMassTransform(int bodyId)
      Return the center-of-mass transform of the specified body.
      Parameters:
      bodyId - the ID of the body to locate
      Returns:
      a new transform matrix (relative to system coordinates)
    • getFriction

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

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

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

      public EMotionQuality getMotionQuality(int bodyId)
      Return the motion quality.
      Parameters:
      bodyId - the ID of the body to query
      Returns:
      an enum value (not null)
    • getMotionType

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

      public int getObjectLayer(int bodyId)
      Return the object layer of the specified body.
      Parameters:
      bodyId - the ID of the body to query
      Returns:
      an object-layer index
    • getPosition

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

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

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

      public Quat getRotation(int bodyId)
      Copy the orientation of the specified body.
      Parameters:
      bodyId - the ID of the body
      Returns:
      a new rotation quaternion
    • getShape

      public ShapeRefC getShape(int bodyId)
      Access the body's shape. TODO return ConstShape?
      Parameters:
      bodyId - the ID of the body
      Returns:
      a new reference
    • getSystem

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

      public long getUserData(int bodyId)
      Return the user data of the specified body.
      Parameters:
      bodyId - the ID of the body
      Returns:
      the value
    • isActive

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

      public boolean isAdded(int bodyId)
      Test whether the specified body is added to the system.
      Parameters:
      bodyId - the ID of the body to search for
      Returns:
      true if added, otherwise false
    • moveKinematic

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

      public void notifyShapeChanged(int 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
      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(int bodyId)
      Remove the specified body from the physics system, but don't destroy it.
      Parameters:
      bodyId - the ID of the body to remove
    • setAngularVelocity

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

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

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

      public void setLinearAndAngularVelocity(int bodyId, Vec3Arg linearVelocity, Vec3Arg angularVelocity)
      Alter the linear and angular velocities of the specified body.
      Parameters:
      bodyId - the ID of the body to modify
      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(int bodyId, Vec3Arg velocity)
      Alter the linear velocity of the specified body.
      Parameters:
      bodyId - the ID of the body to modify
      velocity - the desired velocity (not null, unaffected)
    • setMotionQuality

      public void setMotionQuality(int bodyId, EMotionQuality quality)
      Alter the motion quality of the specified body.
      Parameters:
      bodyId - the ID of the body to modify
      quality - the desired level of quality (not null)
    • setMotionType

      public void setMotionType(int bodyId, EMotionType motionType, EActivation activationMode)
      Alter the motion type of the specified body.
      Parameters:
      bodyId - the ID of the body to modify
      motionType - the desired motion type (not null)
      activationMode - whether to activate the body (not null)
    • setObjectLayer

      public void setObjectLayer(int bodyId, int layer)
      Alter the object layer of the specified body.
      Parameters:
      bodyId - the ID of the body to modify
      layer - the index of the desired object layer (≥0, <numObjectLayers, <65536, default=0)
    • setPosition

      public void setPosition(int bodyId, RVec3Arg location, EActivation activationMode)
      Relocate the specified body.
      Parameters:
      bodyId - the ID of the body to relocate
      location - the desired location (not null, unaffected)
      activationMode - whether to activate the body (not null)
    • setPositionAndRotation

      public void setPositionAndRotation(int bodyId, RVec3Arg location, QuatArg orientation, EActivation activationMode)
      Reposition the specified body.
      Parameters:
      bodyId - the ID of the body to modify
      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(int bodyId, float restitution)
      Alter the restitution ratio of the specified body.
      Parameters:
      bodyId - the ID of the body to modify
      restitution - the desired ratio (typically ≥0 and ≤1, default=0)
    • setShape

      public void setShape(int bodyId, ConstShape shape, boolean updateMassProperties, EActivation activation)
      Replace the shape of the specified body.
      Parameters:
      bodyId - the ID of the body to reshape
      shape - the desired shape to apply (not null)
      updateMassProperties - if true, recalculate the body's mass and inertia, otherwise don't recalculate
      activation - whether to activate the body (not null)
    • setUserData

      public void setUserData(int bodyId, long value)
      Alter the user data of the specified body.
      Parameters:
      bodyId - the ID of the body to modify
      value - the desired value