Class AbstractPhysicsControl

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

public abstract class AbstractPhysicsControl extends Object implements PhysicsControl, com.jme3.util.clone.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.

Author:
normenhansen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    true→body is added to the physics space, false→not added
    protected boolean
    true → physics coordinates match local transform, false → physics coordinates match world transform
    protected boolean
    true→control is enabled, false→control is disabled
    protected PhysicsSpace
    space to which the physics object is (or would be) added
    protected com.jme3.scene.Spatial
    spatial to which this control is added, or null if none
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    Add all managed physics objects to the specified space.
    protected void
    applyPhysicsTransform(com.jme3.math.Vector3f worldLocation, com.jme3.math.Quaternion worldRotation)
    Apply a physics transform to the spatial.
    void
    cloneFields(com.jme3.util.clone.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.
    com.jme3.scene.control.Control
    cloneForSpatial(com.jme3.scene.Spatial spatial)
    Deprecated.
    protected abstract void
    createSpatialData(com.jme3.scene.Spatial spat)
    Create spatial-dependent data.
    Access the physics space to which the object is (or would be) added.
    com.jme3.scene.Spatial
     
    protected com.jme3.math.Quaternion
    Access whichever spatial rotation corresponds to the physics rotation.
    protected com.jme3.math.Vector3f
    Access whichever spatial translation corresponds to the physics location.
    boolean
    Test whether physics-space coordinates should match the spatial's local coordinates.
    boolean
    Test whether this control is enabled.
    void
    read(com.jme3.export.JmeImporter im)
    De-serialize this control from the specified importer, for example when loading from a J3O file.
    protected abstract void
    Remove all managed physics objects from the specified space.
    protected abstract void
    removeSpatialData(com.jme3.scene.Spatial spat)
    Destroy spatial-dependent data.
    void
    render(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp)
     
    void
    setApplyPhysicsLocal(boolean applyPhysicsLocal)
    Alter whether physics-space coordinates should match the spatial's local coordinates.
    void
    setEnabled(boolean enabled)
    Enable or disable this control.
    protected abstract void
    setPhysicsLocation(com.jme3.math.Vector3f vec)
    Translate the physics object to the specified location.
    protected abstract void
    setPhysicsRotation(com.jme3.math.Quaternion quat)
    Rotate the physics object to the specified orientation.
    void
    If enabled, add this control's physics object to the specified physics space.
    void
    setSpatial(com.jme3.scene.Spatial spatial)
    Alter which spatial is controlled.
    void
    update(float tpf)
     
    void
    write(com.jme3.export.JmeExporter ex)
    Serialize this object, for example when saving to a J3O file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.jme3.util.clone.JmeCloneable

    jmeClone
  • Field Details

    • spatial

      protected com.jme3.scene.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(com.jme3.scene.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(com.jme3.scene.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(com.jme3.math.Vector3f vec)
      Translate the physics object to the specified location.
      Parameters:
      vec - desired location (not null, unaffected)
    • setPhysicsRotation

      protected abstract void setPhysicsRotation(com.jme3.math.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 com.jme3.math.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 com.jme3.math.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(com.jme3.math.Vector3f worldLocation, com.jme3.math.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 com.jme3.scene.control.Control cloneForSpatial(com.jme3.scene.Spatial spatial)
      Deprecated.
      Specified by:
      cloneForSpatial in interface com.jme3.scene.control.Control
    • cloneFields

      public void cloneFields(com.jme3.util.clone.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 com.jme3.util.clone.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(com.jme3.scene.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 com.jme3.scene.control.Control
      Parameters:
      spatial - the spatial to control (or null)
    • getSpatial

      public com.jme3.scene.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)
      Specified by:
      update in interface com.jme3.scene.control.Control
    • render

      public void render(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp)
      Specified by:
      render in interface com.jme3.scene.control.Control
    • 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(com.jme3.export.JmeExporter ex) throws IOException
      Serialize this object, for example when saving to a J3O file.
      Specified by:
      write in interface com.jme3.export.Savable
      Parameters:
      ex - exporter (not null)
      Throws:
      IOException - from exporter
    • read

      public void read(com.jme3.export.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 com.jme3.export.Savable
      Parameters:
      im - importer (not null)
      Throws:
      IOException - from importer