Class VehicleControl

All Implemented Interfaces:
PhysicsControl, Savable, Control, JmeCloneable, Cloneable

public class VehicleControl extends PhysicsVehicle implements PhysicsControl, JmeCloneable
A physics control to link a PhysicsVehicle to a spatial.

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
    • space

      protected PhysicsSpace space
      space to which the vehicle is (or would be) added
    • added

      protected boolean added
      true→vehicle is added to the physics space, false→not added
  • Constructor Details

    • VehicleControl

      protected VehicleControl()
      No-argument constructor needed by SavableClassUtil. Do not invoke directly!
    • VehicleControl

      public VehicleControl(CollisionShape shape)
      Instantiate an enabled control with mass=1 and the specified collision shape.
      Parameters:
      shape - the desired shape (not null, alias created)
    • VehicleControl

      public VehicleControl(CollisionShape shape, float mass)
      Instantiate an enabled with the specified collision shape and mass.
      Parameters:
      shape - the desired shape (not null, alias created)
      mass - (>0)
  • Method Details

    • 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)
    • cloneForSpatial

      public Control cloneForSpatial(Spatial spatial)
      Clone this control for a different spatial. No longer used as of JME 3.1.
      Specified by:
      cloneForSpatial in interface Control
      Parameters:
      spatial - the spatial for the clone to control (or null)
      Returns:
      a new control (not null)
    • jmeClone

      public Object jmeClone()
      Create a shallow clone for the JME cloner.
      Specified by:
      jmeClone in interface JmeCloneable
      Returns:
      a new control (not null)
    • 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.
      Specified by:
      setSpatial in interface Control
      Parameters:
      spatial - spatial to control (or null)
    • setEnabled

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

      When the control is disabled, the vehicle 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)
      Update this control. Invoked once per frame, during the logical-state update, provided the control is added to a scene.
      Specified by:
      update in interface Control
      Parameters:
      tpf - the time interval between frames (in seconds, ≥0)
    • render

      public void render(RenderManager rm, ViewPort vp)
      Render this control. Invoked once per view port per frame, provided the control is added to a scene. Should be invoked only by a subclass or by the RenderManager.
      Specified by:
      render in interface Control
      Parameters:
      rm - the render manager (not null)
      vp - the view port to render (not null)
    • setPhysicsSpace

      public void setPhysicsSpace(PhysicsSpace newSpace)
      If enabled, add this control's physics object to the specified physics space. In not enabled, alter where the object would be added. The object is removed from any other space it's currently 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 vehicle 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 control, for example when saving to a J3O file.
      Specified by:
      write in interface Savable
      Overrides:
      write in class PhysicsVehicle
      Parameters:
      ex - exporter (not null)
      Throws:
      IOException - from exporter
    • read

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