Class Body

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

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(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)
    • getCollisionGroup

      public CollisionGroup getCollisionGroup()
      Access the body's collision group.
      Returns:
      the pre-existing group, or null if none
    • getMotionProperties

      public MotionProperties getMotionProperties()
      Access the body's motion properties.
      Returns:
      a new JVM object with the pre-existing native object assigned, or null if none
    • 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(CollisionGroup group)
      Assign the body to the specified collision group.
      Parameters:
      group - the group to assign (not null, alias created)
    • 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/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/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)
      Re-position 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)
      Re-position 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 ConstBody 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()
      Return 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()
      Return 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()
      Return 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.
      Specified by:
      getBodyCreationSettings in interface ConstBody
      Returns:
      a new object
    • getCenterOfMassPosition

      public RVec3 getCenterOfMassPosition()
      Return 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)
    • 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 BodyId getId()
      Copy the body's ID for use with BodyInterface. The body is unaffected.
      Specified by:
      getId in interface ConstBody
      Returns:
      a new object
    • getLinearVelocity

      public Vec3 getLinearVelocity()
      Return 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)
    • 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()
      Return 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)
    • 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()
      Return 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
    • 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
    • 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
    • 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
    • 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
    • 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. The body is unaffected.
      Specified by:
      isSensor in interface ConstBody
      Returns:
      true if a sensor, 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