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

public class Body extends NonCopyable implements ConstBody
An object with mass, position, and shape that can be added to a PhysicsSystem. Bodies may be dynamic, kinematic, or static.
  • Constructor Details

    • Body

      public Body(long bodyVa)
      Instantiate a body with the specified native object assigned but not owned.

      For use in custom contact listeners.

      Parameters:
      bodyVa - the virtual address of the native object to assign (not zero)
  • Method Details

    • addAngularImpulse

      public void addAngularImpulse(Vec3Arg impulse)
      Apply the specified angular impulse to the body.
      Parameters:
      impulse - the impulse vector (Newton.meter.seconds in system coordinates, not null, unaffected)
    • addForce

      public void addForce(Vec3Arg force)
      Apply the specified force to the body's center of mass.
      Parameters:
      force - the force vector (Newtons in system coordinates, not null, unaffected)
    • addForce

      public void addForce(Vec3Arg force, RVec3Arg location)
      Apply the specified force at the specified location.
      Parameters:
      force - the force vector (not null, unaffected)
      location - where to apply the force (Newtons in system coordinates not null, unaffected)
    • addImpulse

      public void addImpulse(float jx, float jy, float jz)
      Apply the specified impulse to the body's center of mass.
      Parameters:
      jx - the X component of the impulse (kilogram.meters per second in system coordinates)
      jy - the Y component of the impulse (kilogram.meters per second in system coordinates)
      jz - the Z component of the impulse (kilogram.meters per second in system coordinates)
    • addImpulse

      public void addImpulse(Vec3Arg impulse)
      Apply the specified impulse to the body's center of mass.
      Parameters:
      impulse - the impulse vector (kilogram.meters per second in system coordinates, not null, unaffected)
    • addImpulse

      public void addImpulse(Vec3Arg impulse, RVec3Arg location)
      Apply the specified impulse at the specified location.
      Parameters:
      impulse - the impulse vector (kilogram.meters per second in system coordinates, not null, unaffected)
      location - where to apply the impulse (not null, unaffected)
    • addTorque

      public void addTorque(Vec3Arg torque)
      Apply the specified torque to the body.
      Parameters:
      torque - the torque vector (Newton.meters in system coordinates, not null, unaffected)
    • applyBuoyancyImpulse

      public boolean applyBuoyancyImpulse(RVec3Arg surfacePosition, Vec3Arg surfaceNormal, float buoyancy, float linearDrag, float angularDrag, Vec3Arg fluidVelocity, Vec3Arg gravity, float deltaTime)
      Apply an impulse that simulates buoyancy and drag.
      Parameters:
      surfacePosition - the location of the fluid's surface (in system coordinates, not null, unaffected)
      surfaceNormal - the upward normal direction of the fluid's surface (in system coordinates, not null, unaffected)
      buoyancy - the mass of the displaced fluid divided by the body's mass (1→neutral buoyancy)
      linearDrag - the drag factor for linear motion
      angularDrag - the drag factor for angular motion
      fluidVelocity - the velocity of the fluid (meters per second in system coordinates, not null, unaffected)
      gravity - the gravity vector (in system coordinates, not null, unaffected)
      deltaTime - the duration of the simulation step (in seconds)
      Returns:
      true if an impulse was applied, false if not in the fluid
    • moveKinematic

      public void moveKinematic(RVec3Arg location, QuatArg orientation, float deltaTime)
      Reposition the body, assuming it's kinematic.
      Parameters:
      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)
    • resetSleepTimer

      public void resetSleepTimer()
      Reset the body's sleep timer. This does not activate the body, but allows resetting the system that detects sleeping bodies.
    • setAllowSleeping

      public void setAllowSleeping(boolean allow)
      Alter whether the body is allowed to fall asleep.
      Parameters:
      allow - true to allow, false to inhibit
    • setAngularVelocity

      public void setAngularVelocity(Vec3Arg omega)
      Directly alter the body's angular velocity.
      Parameters:
      omega - the desired angular velocity (not null, unaffected, default=(0,0,0))
    • setAngularVelocityClamped

      public void setAngularVelocityClamped(Vec3Arg omega)
      Alter the body's angular velocity within limits.
      Parameters:
      omega - the desired angular velocity (not null, unaffected, default=(0,0,0))
    • setCollisionGroup

      public void setCollisionGroup(ConstCollisionGroup group)
      Assign the body to the specified collision group.
      Parameters:
      group - the group to assign (not null, unaffected)
    • setEnhancedInternalEdgeRemoval

      public void setEnhancedInternalEdgeRemoval(boolean enhance)
      Alter whether extra effort should be made to remove ghost contacts.
      Parameters:
      enhance - true for extra effort, false for ordinary effort (default=false)
    • setFriction

      public void setFriction(float friction)
      Alter the body's friction ratio.
      Parameters:
      friction - the desired ratio (typically ≥0 and ≤1, default=0.2)
    • setIsSensor

      public void setIsSensor(boolean setting)
      Alter whether the body is a sensor.
      Parameters:
      setting - true to make it a sensor, false for a regular body (default=false)
    • setLinearVelocity

      public void setLinearVelocity(Vec3Arg velocity)
      Directly alter the body's linear velocity.
      Parameters:
      velocity - the desired linear velocity (in meters per second, not null, unaffected, default=(0,0,0))
    • setLinearVelocityClamped

      public void setLinearVelocityClamped(Vec3Arg velocity)
      Alter the body's linear velocity within limits.
      Parameters:
      velocity - the desired linear velocity (in meters per second, not null, unaffected, default=(0,0,0))
    • setMotionType

      public void setMotionType(EMotionType motionType)
      Alter the body's motion type.
      Parameters:
      motionType - the desired value (not null)
    • setPositionAndRotationInternal

      public void setPositionAndRotationInternal(RVec3Arg location, QuatArg orientation)
      Reposition the body and reset its sleep timer.
      Parameters:
      location - the desired location (in system coordinates, not null, unaffected)
      orientation - the desired orientation (relative to the system axes, not null, unaffected)
    • setPositionAndRotationInternal

      public void setPositionAndRotationInternal(RVec3Arg location, QuatArg orientation, boolean resetSleepTimer)
      Reposition the body.
      Parameters:
      location - the desired location (in system coordinates, not null, unaffected)
      orientation - the desired orientation (relative to the system axes, not null, unaffected)
      resetSleepTimer - true to reset the body's sleep timer, false to leave the timer unchanged
    • setRestitution

      public void setRestitution(float restitution)
      Alter the body's restitution ratio.
      Parameters:
      restitution - the desired ratio (typically ≥0 and ≤1, default=0)
    • setUserData

      public void setUserData(long value)
      Alter the body's user data.
      Parameters:
      value - the desired value (default=0)
    • sFixedToWorld

      public static Body sFixedToWorld()
      Create a dummy body that can be used to attach a constraint to the world.
      Returns:
      a new JVM object with the pre-existing native object assigned
    • canBeKinematicOrDynamic

      public boolean canBeKinematicOrDynamic()
      Test whether the body could be made kinematic or dynamic. The body is unaffected.
      Specified by:
      canBeKinematicOrDynamic in interface ConstBody
      Returns:
      true if possible, otherwise false
    • getAccumulatedForce

      public Vec3 getAccumulatedForce()
      Copy the net force acting on the body. The body is unaffected.
      Specified by:
      getAccumulatedForce in interface ConstBody
      Returns:
      a new force vector (Newtons in system coordinates)
    • getAccumulatedTorque

      public Vec3 getAccumulatedTorque()
      Copy the net torque acting on the body. The body is unaffected.
      Specified by:
      getAccumulatedTorque in interface ConstBody
      Returns:
      a new torque vector (Newton.meters in system coordinates)
    • getAllowSleeping

      public boolean getAllowSleeping()
      Test whether the body is allowed to fall asleep. The body is unaffected.
      Specified by:
      getAllowSleeping in interface ConstBody
      Returns:
      true if allowed, otherwise false
    • getAngularVelocity

      public Vec3 getAngularVelocity()
      Copy the body's angular velocity. The body is unaffected.
      Specified by:
      getAngularVelocity in interface ConstBody
      Returns:
      a new velocity vector (radians per second in system coordinates)
    • getBodyCreationSettings

      public BodyCreationSettings getBodyCreationSettings()
      Convert the body to a BodyCreationSettings object. The body is unaffected.
      Specified by:
      getBodyCreationSettings in interface ConstBody
      Returns:
      a new object
    • getBodyType

      public EBodyType getBodyType()
      Return the body type (rigid or soft). The body is unaffected.
      Specified by:
      getBodyType in interface ConstBody
      Returns:
      an enum value (not null)
    • getBroadPhaseLayer

      public int getBroadPhaseLayer()
      Return the broadphase layer. The body is unaffected.
      Specified by:
      getBroadPhaseLayer in interface ConstBody
      Returns:
      the layer ID
    • getCenterOfMassPosition

      public RVec3 getCenterOfMassPosition()
      Copy the location of the body's center of mass (which might not coincide with its origin). The body is unaffected.
      Specified by:
      getCenterOfMassPosition in interface ConstBody
      Returns:
      a new location vector (in system coordinates, all components finite)
    • getCenterOfMassPosition

      public void getCenterOfMassPosition(RVec3 storeLocation)
      Copy the location of the body's center of mass (which might not coincide with its origin). The body is unaffected.
      Specified by:
      getCenterOfMassPosition in interface ConstBody
      Parameters:
      storeLocation - storage for the location (in system coordinates, not null, modified)
    • getCenterOfMassTransform

      public RMat44 getCenterOfMassTransform()
      Copy the coordinate transform of the body's center of mass. The body is unaffected.
      Specified by:
      getCenterOfMassTransform in interface ConstBody
      Returns:
      a new transform matrix (relative to system coordinates)
    • getCollisionGroup

      public CollisionGroup getCollisionGroup()
      Access the body's collision group.
      Specified by:
      getCollisionGroup in interface ConstBody
      Returns:
      a new JVM object with the pre-existing native object assigned
    • getEnhancedInternalEdgeRemoval

      public boolean getEnhancedInternalEdgeRemoval()
      Test whether extra effort should be made to remove ghost contacts. The body is unaffected.
      Specified by:
      getEnhancedInternalEdgeRemoval in interface ConstBody
      Returns:
      true for extra effort, otherwise false
    • getFriction

      public float getFriction()
      Return the body's friction ratio. The body is unaffected.
      Specified by:
      getFriction in interface ConstBody
      Returns:
      the ratio
    • getId

      public int getId()
      Return the body's ID for use with BodyInterface. The body is unaffected. (native method: GetID)
      Specified by:
      getId in interface ConstBody
      Returns:
      the BodyID value
    • getInverseCenterOfMassTransform

      public RMat44 getInverseCenterOfMassTransform()
      Copy the inverse coordinate transform of the body's center of mass. The body is unaffected.
      Specified by:
      getInverseCenterOfMassTransform in interface ConstBody
      Returns:
      a new transform matrix (relative to local coordinates)
    • getLinearVelocity

      public Vec3 getLinearVelocity()
      Copy the body's linear velocity. The body is unaffected.
      Specified by:
      getLinearVelocity in interface ConstBody
      Returns:
      a new velocity vector (meters per second in system coordinates)
    • getMotionProperties

      public MotionProperties getMotionProperties()
      Access the body's motion properties.
      Specified by:
      getMotionProperties in interface ConstBody
      Returns:
      a new JVM object with the pre-existing native object assigned, or null if none
    • getMotionType

      public EMotionType getMotionType()
      Return the body's motion type. The body is unaffected.
      Specified by:
      getMotionType in interface ConstBody
      Returns:
      an enum value (not null)
    • getObjectLayer

      public int getObjectLayer()
      Return the body's object layer. The body is unaffected.
      Specified by:
      getObjectLayer in interface ConstBody
      Returns:
      a layer index (≥0)
    • getPosition

      public RVec3 getPosition()
      Copy the location of the body's origin (which might not coincide with its center of mass). The body is unaffected.
      Specified by:
      getPosition in interface ConstBody
      Returns:
      a new location vector (in system coordinates, all components finite)
    • getPositionAndRotation

      public void getPositionAndRotation(RVec3 storeLocation, Quat storeOrientation)
      Copy the position of the body. The body is unaffected.
      Specified by:
      getPositionAndRotation in interface ConstBody
      Parameters:
      storeLocation - storage for the location (in system coordinates, not null, modified)
      storeOrientation - storage for the orientation (in system coordinates, not null, modified)
    • getRestitution

      public float getRestitution()
      Return the body's restitution ratio. The body is unaffected.
      Specified by:
      getRestitution in interface ConstBody
      Returns:
      the value (typically ≥0 and ≤1)
    • getRotation

      public Quat getRotation()
      Copy the body's orientation. The body is unaffected.
      Specified by:
      getRotation in interface ConstBody
      Returns:
      a new rotation quaternion (relative to the system axes)
    • getShape

      public ConstShape getShape()
      Access the body's shape.
      Specified by:
      getShape in interface ConstBody
      Returns:
      a new immutable JVM object with the pre-existing native object assigned, or null if none
    • getSoftBodyCreationSettings

      public SoftBodyCreationSettings getSoftBodyCreationSettings()
      Convert the body to a SoftBodyCreationSettings object. The body is unaffected.
      Specified by:
      getSoftBodyCreationSettings in interface ConstBody
      Returns:
      a new object
    • getTransformedShape

      public TransformedShape getTransformedShape()
      Convert the body to a TransformedShape object. The body is unaffected.
      Specified by:
      getTransformedShape in interface ConstBody
      Returns:
      a new object
    • getUserData

      public long getUserData()
      Return the body's user data: can be used for anything. The body is unaffected.
      Specified by:
      getUserData in interface ConstBody
      Returns:
      the value
    • getWorldSpaceBounds

      public ConstAaBox getWorldSpaceBounds()
      Access the body's bounding box. The body is unaffected.
      Specified by:
      getWorldSpaceBounds in interface ConstBody
      Returns:
      a new immutable JVM object with the pre-existing native object assigned
    • getWorldSpaceSurfaceNormal

      public Vec3 getWorldSpaceSurfaceNormal(int subShapeId, RVec3Arg location)
      Copy the surface normal of a particular sub shape at the specified location.
      Specified by:
      getWorldSpaceSurfaceNormal in interface ConstBody
      Parameters:
      subShapeId - the ID of the sub-shape to use
      location - the location to use (not null, unaffected)
      Returns:
      a new direction vector
    • getWorldTransform

      public RMat44 getWorldTransform()
      Copy the world transform. The body is unaffected.
      Specified by:
      getWorldTransform in interface ConstBody
      Returns:
      a new matrix relative to system coordinates
    • isActive

      public boolean isActive()
      Test whether the body is deactivated. The body is unaffected.
      Specified by:
      isActive in interface ConstBody
      Returns:
      false if deactivated, otherwise true
    • isDynamic

      public boolean isDynamic()
      Test whether the body is dynamic. The body is unaffected.
      Specified by:
      isDynamic in interface ConstBody
      Returns:
      true if dynamic, otherwise false
    • isInBroadPhase

      public boolean isInBroadPhase()
      Test whether the body has been added to its PhysicsSystem. The body is unaffected.
      Specified by:
      isInBroadPhase in interface ConstBody
      Returns:
      true if added, otherwise false
    • isKinematic

      public boolean isKinematic()
      Test whether the body is kinematic. It is unaffected.
      Specified by:
      isKinematic in interface ConstBody
      Returns:
      true if kinematic, otherwise false
    • isRigidBody

      public boolean isRigidBody()
      Test whether the body is a rigid body. It is unaffected.
      Specified by:
      isRigidBody in interface ConstBody
      Returns:
      true if rigid body, otherwise false
    • isSensor

      public boolean isSensor()
      Test whether the body is a sensor. It is unaffected.
      Specified by:
      isSensor in interface ConstBody
      Returns:
      true if a sensor, otherwise false
    • isSoftBody

      public boolean isSoftBody()
      Test whether the body is soft. It is unaffected.
      Specified by:
      isSoftBody in interface ConstBody
      Returns:
      true if soft, otherwise false
    • isStatic

      public boolean isStatic()
      Test whether the body is static (non-moving). It is unaffected.
      Specified by:
      isStatic in interface ConstBody
      Returns:
      true if static, otherwise false