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
FieldsModifier and TypeFieldDescriptionprotected booleantrue→body is added to the physics space, false→not addedprotected booleantrue → physics coordinates match local transform, false → physics coordinates match world transformprotected booleantrue→control is enabled, false→control is disabledprotected PhysicsSpacespace to which the physics object is (or would be) addedprotected Spatialspatial to which this control is added, or null if none -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidaddPhysics(PhysicsSpace space) Add all managed physics objects to the specified space.protected voidapplyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) Apply a physics transform to the spatial.voidcloneFields(Cloner cloner, Object original) Callback fromClonerto 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 voidcreateSpatialData(Spatial spat) Create spatial-dependent data.Access the physics space to which the object is (or would be) added.protected QuaternionAccess whichever spatial rotation corresponds to the physics rotation.protected Vector3fAccess whichever spatial translation corresponds to the physics location.booleanTest whether physics-space coordinates should match the spatial's local coordinates.booleanTest whether this control is enabled.voidread(JmeImporter im) De-serialize this control from the specified importer, for example when loading from a J3O file.protected abstract voidremovePhysics(PhysicsSpace space) Remove all managed physics objects from the specified space.protected abstract voidremoveSpatialData(Spatial spat) Destroy spatial-dependent data.voidrender(RenderManager rm, ViewPort vp) Should be called prior to queuing the spatial by the RenderManager.voidsetApplyPhysicsLocal(boolean applyPhysicsLocal) Alter whether physics-space coordinates should match the spatial's local coordinates.voidsetEnabled(boolean enabled) Enable or disable this control.protected abstract voidTranslate the physics object to the specified location.protected abstract voidsetPhysicsRotation(Quaternion quat) Rotate the physics object to the specified orientation.voidsetPhysicsSpace(PhysicsSpace newSpace) If enabled, add this control's physics object to the specified physics space.voidsetSpatial(Spatial spatial) Alter which spatial is controlled.voidupdate(float tpf) Updates the control.voidwrite(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, waitMethods 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:ControlCreates a clone of the Control, the given Spatial is the cloned version of the spatial to which this control is attached to.- Specified by:
cloneForSpatialin interfaceControl- Parameters:
spatial- the Spatial to be controlled by the clone- Returns:
- A clone of this control for the spatial
-
cloneFields
Callback fromClonerto convert this shallow-cloned control into a deep-cloned one, using the specified cloner and original to resolve copied fields.- Specified by:
cloneFieldsin 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:
setSpatialin 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:
setEnabledin interfacePhysicsControl- Parameters:
enabled- true→enable the control, false→disable it
-
isEnabled
public boolean isEnabled()Test whether this control is enabled.- Specified by:
isEnabledin interfacePhysicsControl- Returns:
- true if enabled, otherwise false
-
update
public void update(float tpf) Description copied from interface:ControlUpdates the control. This should not be called from user code. -
render
Description copied from interface:ControlShould 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:
setPhysicsSpacein 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:
getPhysicsSpacein interfacePhysicsControl- Returns:
- the pre-existing space, or null for none
-
write
Serialize this object, for example when saving to a J3O file.- Specified by:
writein 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:
readin interfaceSavable- Parameters:
im- importer (not null)- Throws:
IOException- from importer
-