Class AbstractPhysicsControl

java.lang.Object
com.jme3.bullet.control.AbstractPhysicsControl
All Implemented Interfaces:
PhysicsControl, Savable, Control, JmeCloneable, Cloneable
Direct Known Subclasses:
BetterCharacterControl, DacConfiguration, KinematicRagdollControl

public abstract class AbstractPhysicsControl extends Object implements PhysicsControl, JmeCloneable
Manage the life cycle of a physics object linked to a spatial in a scene graph.

This class is shared between JBullet and Native Bullet.

  • Field Details

    • spatial

      protected Spatial spatial
      spatial to which this control is added, or null if none
    • enabled

      protected boolean enabled
      true→control is enabled, false→control is disabled
    • added

      protected boolean added
      true→body is added to the physics space, false→not added
    • space

      protected PhysicsSpace space
      space to which the physics object is (or would be) added
    • applyLocal

      protected boolean applyLocal
      true → physics coordinates match local transform, false → physics coordinates match world transform
  • Constructor Details

    • AbstractPhysicsControl

      public AbstractPhysicsControl()
  • Method Details

    • createSpatialData

      protected abstract void createSpatialData(Spatial spat)
      Create spatial-dependent data. Invoked when this control is added to a spatial.
      Parameters:
      spat - the controlled spatial (not null)
    • removeSpatialData

      protected abstract void removeSpatialData(Spatial spat)
      Destroy spatial-dependent data. Invoked when this control is removed from a spatial.
      Parameters:
      spat - the previously controlled spatial (not null)
    • setPhysicsLocation

      protected abstract void setPhysicsLocation(Vector3f vec)
      Translate the physics object to the specified location.
      Parameters:
      vec - desired location (not null, unaffected)
    • setPhysicsRotation

      protected abstract void setPhysicsRotation(Quaternion quat)
      Rotate the physics object to the specified orientation.
      Parameters:
      quat - desired orientation (not null, unaffected)
    • addPhysics

      protected abstract void addPhysics(PhysicsSpace space)
      Add all managed physics objects to the specified space.
      Parameters:
      space - which physics space to add to (not null)
    • removePhysics

      protected abstract void removePhysics(PhysicsSpace space)
      Remove all managed physics objects from the specified space.
      Parameters:
      space - which physics space to remove from (not null)
    • isApplyPhysicsLocal

      public boolean isApplyPhysicsLocal()
      Test whether physics-space coordinates should match the spatial's local coordinates.
      Returns:
      true if matching local coordinates, false if matching world coordinates
    • setApplyPhysicsLocal

      public void setApplyPhysicsLocal(boolean applyPhysicsLocal)
      Alter whether physics-space coordinates should match the spatial's local coordinates.
      Parameters:
      applyPhysicsLocal - true→match local coordinates, false→match world coordinates (default=false)
    • getSpatialTranslation

      protected Vector3f getSpatialTranslation()
      Access whichever spatial translation corresponds to the physics location.
      Returns:
      the pre-existing location vector (in physics-space coordinates, not null)
    • getSpatialRotation

      protected Quaternion getSpatialRotation()
      Access whichever spatial rotation corresponds to the physics rotation.
      Returns:
      the pre-existing quaternion (in physics-space coordinates, not null)
    • applyPhysicsTransform

      protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation)
      Apply a physics transform to the spatial.
      Parameters:
      worldLocation - location vector (in physics-space coordinates, not null, unaffected)
      worldRotation - orientation (in physics-space coordinates, not null, unaffected)
    • cloneForSpatial

      @Deprecated public Control cloneForSpatial(Spatial spatial)
      Deprecated.
      Description copied from interface: Control
      Creates a clone of the Control, the given Spatial is the cloned version of the spatial to which this control is attached to.
      Specified by:
      cloneForSpatial in interface Control
      Parameters:
      spatial - the Spatial to be controlled by the clone
      Returns:
      A clone of this control for the spatial
    • cloneFields

      public void cloneFields(Cloner cloner, Object original)
      Callback from Cloner to convert this shallow-cloned control into a deep-cloned one, using the specified cloner and original to resolve copied fields.
      Specified by:
      cloneFields in interface JmeCloneable
      Parameters:
      cloner - the cloner that's cloning this control (not null)
      original - the control from which this control was shallow-cloned (unused)
    • setSpatial

      public void setSpatial(Spatial spatial)
      Alter which spatial is controlled. Invoked when the control is added to or removed from a spatial. Should be invoked only by a subclass or from Spatial. Do not invoke directly from user code.
      Specified by:
      setSpatial in interface Control
      Parameters:
      spatial - the spatial to control (or null)
    • getSpatial

      public Spatial getSpatial()
      Returns:
      returns the spatial the control is added to, or null if the control is not attached to a spatial yet.
    • setEnabled

      public void setEnabled(boolean enabled)
      Enable or disable this control.

      When the control is disabled, the physics object is removed from physics space. When the control is enabled again, the physics object is moved to the spatial's location and then added to the physics space.

      Specified by:
      setEnabled in interface PhysicsControl
      Parameters:
      enabled - true→enable the control, false→disable it
    • isEnabled

      public boolean isEnabled()
      Test whether this control is enabled.
      Specified by:
      isEnabled in interface PhysicsControl
      Returns:
      true if enabled, otherwise false
    • update

      public void update(float tpf)
      Description copied from interface: Control
      Updates the control. This should not be called from user code.
      Specified by:
      update in interface Control
      Parameters:
      tpf - Time per frame.
    • render

      public void render(RenderManager rm, ViewPort vp)
      Description copied from interface: Control
      Should be called prior to queuing the spatial by the RenderManager. This should not be called from user code.
      Specified by:
      render in interface Control
      Parameters:
      rm - the caller (not null)
      vp - the relevant ViewPort (not null)
    • setPhysicsSpace

      public void setPhysicsSpace(PhysicsSpace newSpace)
      If enabled, add this control's physics object to the specified physics space. If not enabled, alter where the object would be added. The object is removed from any other space it's in.
      Specified by:
      setPhysicsSpace in interface PhysicsControl
      Parameters:
      newSpace - where to add, or null to simply remove
    • getPhysicsSpace

      public PhysicsSpace getPhysicsSpace()
      Access the physics space to which the object is (or would be) added.
      Specified by:
      getPhysicsSpace in interface PhysicsControl
      Returns:
      the pre-existing space, or null for none
    • write

      public void write(JmeExporter ex) throws IOException
      Serialize this object, for example when saving to a J3O file.
      Specified by:
      write in interface Savable
      Parameters:
      ex - exporter (not null)
      Throws:
      IOException - from exporter
    • read

      public void read(JmeImporter im) throws IOException
      De-serialize this control from the specified importer, for example when loading from a J3O file.
      Specified by:
      read in interface Savable
      Parameters:
      im - importer (not null)
      Throws:
      IOException - from importer