Package com.jme3.bullet.control
Class AbstractPhysicsControl
java.lang.Object
com.jme3.bullet.control.AbstractPhysicsControl
- All Implemented Interfaces:
PhysicsControl
,Savable
,Control
,JmeCloneable
,Cloneable
- Direct Known Subclasses:
BetterCharacterControl
,DacConfiguration
,KinematicRagdollControl
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 Summary
Modifier and TypeFieldDescriptionprotected boolean
true→body is added to the physics space, false→not addedprotected boolean
true → physics coordinates match local transform, false → physics coordinates match world transformprotected boolean
true→control is enabled, false→control is disabledprotected PhysicsSpace
space to which the physics object is (or would be) addedprotected Spatial
spatial to which this control is added, or null if none -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
addPhysics
(PhysicsSpace space) Add all managed physics objects to the specified space.protected void
applyPhysicsTransform
(Vector3f worldLocation, Quaternion worldRotation) Apply a physics transform to the spatial.void
cloneFields
(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.cloneForSpatial
(Spatial spatial) Deprecated.protected abstract void
createSpatialData
(Spatial spat) Create spatial-dependent data.Access the physics space to which the object is (or would be) added.protected Quaternion
Access whichever spatial rotation corresponds to the physics rotation.protected 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
(JmeImporter im) De-serialize this control from the specified importer, for example when loading from a J3O file.protected abstract void
removePhysics
(PhysicsSpace space) Remove all managed physics objects from the specified space.protected abstract void
removeSpatialData
(Spatial spat) Destroy spatial-dependent data.void
render
(RenderManager rm, ViewPort vp) Should be called prior to queuing the spatial by the RenderManager.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
Translate the physics object to the specified location.protected abstract void
setPhysicsRotation
(Quaternion quat) Rotate the physics object to the specified orientation.void
setPhysicsSpace
(PhysicsSpace newSpace) If enabled, add this control's physics object to the specified physics space.void
setSpatial
(Spatial spatial) Alter which spatial is controlled.void
update
(float tpf) Updates the control.void
write
(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
spatial to which this control is added, or null if none -
enabled
protected boolean enabledtrue→control is enabled, false→control is disabled -
added
protected boolean addedtrue→body is added to the physics space, false→not added -
space
space to which the physics object is (or would be) added -
applyLocal
protected boolean applyLocaltrue → physics coordinates match local transform, false → physics coordinates match world transform
-
-
Constructor Details
-
AbstractPhysicsControl
public AbstractPhysicsControl()
-
-
Method Details
-
createSpatialData
Create spatial-dependent data. Invoked when this control is added to a spatial.- Parameters:
spat
- the controlled spatial (not null)
-
removeSpatialData
Destroy spatial-dependent data. Invoked when this control is removed from a spatial.- Parameters:
spat
- the previously controlled spatial (not null)
-
setPhysicsLocation
Translate the physics object to the specified location.- Parameters:
vec
- desired location (not null, unaffected)
-
setPhysicsRotation
Rotate the physics object to the specified orientation.- Parameters:
quat
- desired orientation (not null, unaffected)
-
addPhysics
Add all managed physics objects to the specified space.- Parameters:
space
- which physics space to add to (not null)
-
removePhysics
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
Access whichever spatial translation corresponds to the physics location.- Returns:
- the pre-existing location vector (in physics-space coordinates, not null)
-
getSpatialRotation
Access whichever spatial rotation corresponds to the physics rotation.- Returns:
- the pre-existing quaternion (in physics-space coordinates, not null)
-
applyPhysicsTransform
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.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 interfaceControl
- Parameters:
spatial
- the Spatial to be controlled by the clone- Returns:
- A clone of this control for the spatial
-
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 interfaceJmeCloneable
- Parameters:
cloner
- the cloner that's cloning this control (not null)original
- the control from which this control was shallow-cloned (unused)
-
setSpatial
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 interfaceControl
- Parameters:
spatial
- the spatial to control (or null)
-
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 interfacePhysicsControl
- Parameters:
enabled
- true→enable the control, false→disable it
-
isEnabled
public boolean isEnabled()Test whether this control is enabled.- Specified by:
isEnabled
in interfacePhysicsControl
- 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. -
render
Description copied from interface:Control
Should be called prior to queuing the spatial by the RenderManager. This should not be called from user code. -
setPhysicsSpace
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 interfacePhysicsControl
- Parameters:
newSpace
- where to add, or null to simply remove
-
getPhysicsSpace
Access the physics space to which the object is (or would be) added.- Specified by:
getPhysicsSpace
in interfacePhysicsControl
- Returns:
- the pre-existing space, or null for none
-
write
Serialize this object, for example when saving to a J3O file.- Specified by:
write
in interfaceSavable
- Parameters:
ex
- exporter (not null)- Throws:
IOException
- from exporter
-
read
De-serialize this control from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfaceSavable
- Parameters:
im
- importer (not null)- Throws:
IOException
- from importer
-