Package com.jme3.bullet.control
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
,CharacterControl
,DacConfiguration
,JoinedBodyControl
,SoftBodyControl
public abstract class AbstractPhysicsControl
extends Object
implements com.jme3.util.clone.JmeCloneable, PhysicsControl
Manage the lifecycle of a physics object linked to a Spatial in a scene
graph.
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Instantiate an enabled control that isn't added to any space or spatial. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
Add all managed physics objects to the PhysicsSpace.protected void
applyPhysicsTransform
(com.jme3.math.Vector3f physicsLocation, com.jme3.math.Quaternion physicsOrientation) Apply a physics transform to the controlled Spatial.void
cloneFields
(com.jme3.util.clone.Cloner cloner, Object original) Callback fromCloner
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) Clone this Control for a different Spatial.protected abstract void
createSpatialData
(com.jme3.scene.Spatial spatial) Create spatial-dependent data.Access the PhysicsSpace to which the object is (or would be) added.com.jme3.scene.Spatial
Access the Spatial to which this Control is added.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.jmeClone()
Create a shallow clone for the JME cloner.void
read
(com.jme3.export.JmeImporter importer) 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 PhysicsSpace.protected abstract void
removeSpatialData
(com.jme3.scene.Spatial spatial) Destroy spatial-dependent data.void
render
(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) Render this Control.void
setApplyPhysicsLocal
(boolean applyPhysicsLocal) Alter whether physics-space coordinates should match the Spatial's local coordinates.void
setEnabled
(boolean enable) Enable or disable this Control.protected abstract void
setPhysicsLocation
(com.jme3.math.Vector3f location) Translate the physics object to the specified location.protected abstract void
setPhysicsRotation
(com.jme3.math.Quaternion orientation) Rotate the physics object to the specified orientation.void
setPhysicsSpace
(PhysicsSpace newSpace) If enabled, add this control's physics objects to the specified PhysicsSpace.void
setSpatial
(com.jme3.scene.Spatial newSpatial) Alter which Spatial is controlled.void
write
(com.jme3.export.JmeExporter exporter) Serialize this Control to the specified exporter, 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.scene.control.Control
update
-
Field Details
-
logger
message logger for this class -
added
protected boolean addedtrue→body is added to the PhysicsSpace, false→not added
-
-
Constructor Details
-
AbstractPhysicsControl
protected AbstractPhysicsControl()Instantiate an enabled control that isn't added to any space or spatial.This no-arg constructor was made explicit to avoid javadoc warnings from JDK 18+.
-
-
Method Details
-
getSpatial
public com.jme3.scene.Spatial getSpatial()Access the Spatial to which this Control is added.- Returns:
- the Spatial, or null if none
-
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)
-
addPhysics
protected abstract void addPhysics()Add all managed physics objects to the PhysicsSpace. -
applyPhysicsTransform
protected void applyPhysicsTransform(com.jme3.math.Vector3f physicsLocation, com.jme3.math.Quaternion physicsOrientation) Apply a physics transform to the controlled Spatial. TODO use MySpatial- Parameters:
physicsLocation
- the desired location (in physics-space coordinates, not null, unaffected)physicsOrientation
- the desired orientation (in physics-space coordinates, not null, unaffected)
-
createSpatialData
protected abstract void createSpatialData(com.jme3.scene.Spatial spatial) Create spatial-dependent data. Invoked when this Control is added to a Spatial.- Parameters:
spatial
- the controlled Spatial (not null)
-
getSpatialRotation
protected com.jme3.math.Quaternion getSpatialRotation()Access whichever (spatial) rotation corresponds to the physics rotation.- Returns:
- a pre-existing rotation Quaternion (in physics-space coordinates, not null)
-
getSpatialTranslation
protected com.jme3.math.Vector3f getSpatialTranslation()Access whichever (spatial) translation corresponds to the physics location.- Returns:
- a pre-existing location vector (in physics-space coordinates, not null)
-
removePhysics
protected abstract void removePhysics()Remove all managed physics objects from the PhysicsSpace. -
removeSpatialData
protected abstract void removeSpatialData(com.jme3.scene.Spatial spatial) Destroy spatial-dependent data. Invoked when this Control is removed from its Spatial.- Parameters:
spatial
- the previous controlled Spatial (not null)
-
setPhysicsLocation
protected abstract void setPhysicsLocation(com.jme3.math.Vector3f location) Translate the physics object to the specified location.- Parameters:
location
- the desired location (in physics-space coordinates, not null, unaffected)
-
setPhysicsRotation
protected abstract void setPhysicsRotation(com.jme3.math.Quaternion orientation) Rotate the physics object to the specified orientation.- Parameters:
orientation
- the desired orientation (in physics-space coordinates, not null, unaffected)
-
cloneFields
Callback fromCloner
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 interfacecom.jme3.util.clone.JmeCloneable
- Parameters:
cloner
- the Cloner that's cloning this Control (not null)original
- the instance from which this Control was shallow-cloned (unused)
-
jmeClone
Create a shallow clone for the JME cloner.- Specified by:
jmeClone
in interfacecom.jme3.util.clone.JmeCloneable
- Returns:
- a new Control (not null)
-
cloneForSpatial
public com.jme3.scene.control.Control cloneForSpatial(com.jme3.scene.Spatial spatial) Clone this Control for a different Spatial. No longer used as of JME 3.1.- Specified by:
cloneForSpatial
in interfacecom.jme3.scene.control.Control
- Parameters:
spatial
- (unused)- Returns:
- never
- Throws:
UnsupportedOperationException
- always
-
getPhysicsSpace
Access the PhysicsSpace to which the object is (or would be) added.- Specified by:
getPhysicsSpace
in interfacePhysicsControl
- Returns:
- the pre-existing space, or null for none
-
isEnabled
public boolean isEnabled()Test whether this Control is enabled.- Specified by:
isEnabled
in interfacePhysicsControl
- Returns:
- true if enabled, otherwise false
-
read
De-serialize this Control from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfacecom.jme3.export.Savable
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
render
public void render(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) Render this Control. Invoked once per ViewPort 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 interfacecom.jme3.scene.control.Control
- Parameters:
rm
- the RenderManager (unused)vp
- the ViewPort to render (unused)
-
setEnabled
public void setEnabled(boolean enable) Enable or disable this Control.When the Control is disabled, the physics object is removed from any PhysicsSpace. When the Control is enabled again, the physics object is moved to the location of the Spatial and then added to the PhysicsSpace.
- Specified by:
setEnabled
in interfacePhysicsControl
- Parameters:
enable
- true→enable the Control, false→disable it
-
setPhysicsSpace
If enabled, add this control's physics objects to the specified PhysicsSpace. If not enabled, alter where the objects would be added. The objects are removed from any other space they're in.- Specified by:
setPhysicsSpace
in interfacePhysicsControl
- Parameters:
newSpace
- where to add, or null to simply remove
-
setSpatial
public void setSpatial(com.jme3.scene.Spatial newSpatial) 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. The correct way to add a Control to a Spatial is with spatial.addControl().- Specified by:
setSpatial
in interfacecom.jme3.scene.control.Control
- Parameters:
newSpatial
- the Spatial to control (or null)
-
write
Serialize this Control to the specified exporter, for example when saving to a J3O file.- Specified by:
write
in interfacecom.jme3.export.Savable
- Parameters:
exporter
- (not null)- Throws:
IOException
- from the exporter
-