Class PhysicsBody

All Implemented Interfaces:
com.jme3.export.Savable, com.jme3.util.clone.JmeCloneable, Cloneable, Comparable<NativePhysicsObject>
Direct Known Subclasses:
PhysicsRigidBody, PhysicsSoftBody

public abstract class PhysicsBody extends PhysicsCollisionObject
The abstract base class for rigid bodies and soft bodies.
  • Field Details

    • massForStatic

      public static final float massForStatic
      magic mass value used to specify a static rigid body or soft-body node
      See Also:
  • Constructor Details

    • PhysicsBody

      protected PhysicsBody()
      Instantiate a PhysicsBody.

      This no-arg constructor was made explicit to avoid javadoc warnings from JDK 18+.

  • Method Details

    • addJoint

      public void addJoint(PhysicsJoint joint)
      Do not invoke directly! Joints are added automatically when created.
      Parameters:
      joint - the joint to add (not null, alias created)
    • cloneJoints

      protected void cloneJoints(com.jme3.util.clone.Cloner cloner, PhysicsBody old)
      Clone this body's joints.
      Parameters:
      cloner - the Cloner that's cloning this body (not null, modified)
      old - the instance from which this body was shallow-cloned (not null, unaffected)
    • countJoints

      public int countJoints()
      Count how many joints connect to this body. (The semantics have changed since Minie v2.)
      Returns:
      the count (≥0)
    • getDeactivationDeadline

      public static float getDeactivationDeadline()
      Return the global deactivation deadline.
      Returns:
      the deadline (in simulated seconds, >0)
    • getGravity

      public abstract com.jme3.math.Vector3f getGravity(com.jme3.math.Vector3f storeResult)
      Copy this body's gravitational acceleration.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      an acceleration vector (in physics-space coordinates, either storeResult or a new vector, not null)
    • getMass

      public abstract float getMass()
      Determine the total mass of this body.
      Returns:
      the total mass (≥0)
    • isDeactivationEnabled

      public static boolean isDeactivationEnabled()
      Test the global deactivation enabled flag.
      Returns:
      true if deactivation is enabled, otherwise false
    • listJoints

      public PhysicsJoint[] listJoints()
      Enumerate the joints connected to this body. (The semantics have changed since Minie v2.)
      Returns:
      a new array of pre-existing joints
    • readJoints

      protected void readJoints(com.jme3.export.InputCapsule capsule) throws IOException
      De-serialize joints from the specified InputCapsule, for example when loading from a J3O file.
      Parameters:
      capsule - (not null, modified)
      Throws:
      IOException - from the capsule
    • removeJoint

      public void removeJoint(PhysicsJoint joint)
      Do not invoke directly! Joints are removed automatically when destroyed.
      Parameters:
      joint - the joint to remove (not null, unaffected)
      See Also:
    • setDeactivationDeadline

      public static void setDeactivationDeadline(float newDeadline)
      Alter the global deactivation deadline.
      Parameters:
      newDeadline - the desired deadline (in simulated seconds, >0, default=2)
    • setDeactivationEnabled

      public static void setDeactivationEnabled(boolean newSetting)
      Alter the global deactivation enabled flag.
      Parameters:
      newSetting - true to enable deactivation, false to disable it (default=true)
    • setGravity

      public abstract void setGravity(com.jme3.math.Vector3f acceleration)
      Alter this body's gravitational acceleration.

      Invoke this method after adding the body to a PhysicsSpace. Adding a body to a PhysicsSpace overrides its gravity.

      Parameters:
      acceleration - the desired acceleration vector (in physics-space coordinates, not null, unaffected)
    • setMass

      public abstract void setMass(float mass)
      Alter this body's total mass.
      Parameters:
      mass - the desired total mass (≥0)
    • setPhysicsLocation

      public abstract void setPhysicsLocation(com.jme3.math.Vector3f location)
      Directly relocate this body's center.
      Parameters:
      location - the desired location (in physics-space coordinates, not null, unaffected)
    • writeJoints

      protected void writeJoints(com.jme3.export.OutputCapsule capsule) throws IOException
      Serialize joints to the specified OutputCapsule, for example when saving to a J3O file.
      Parameters:
      capsule - (not null, modified)
      Throws:
      IOException - from the capsule
    • cloneFields

      public void cloneFields(com.jme3.util.clone.Cloner cloner, Object original)
      Callback from Cloner to convert this shallow-cloned body into a deep-cloned one, using the specified Cloner and original to resolve copied fields.
      Specified by:
      cloneFields in interface com.jme3.util.clone.JmeCloneable
      Overrides:
      cloneFields in class PhysicsCollisionObject
      Parameters:
      cloner - the Cloner that's cloning this body (not null)
      original - the instance from which this body was shallow-cloned (not null, unaffected)