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,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
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 com.jme3.scene.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(com.jme3.math.Vector3f worldLocation, com.jme3.math.Quaternion worldRotation) Apply a physics transform to the spatial.voidcloneFields(com.jme3.util.clone.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.com.jme3.scene.control.ControlcloneForSpatial(com.jme3.scene.Spatial spatial) Deprecated.protected abstract voidcreateSpatialData(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.Spatialprotected com.jme3.math.QuaternionAccess whichever spatial rotation corresponds to the physics rotation.protected com.jme3.math.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(com.jme3.export.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(com.jme3.scene.Spatial spat) Destroy spatial-dependent data.voidrender(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) 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 voidsetPhysicsLocation(com.jme3.math.Vector3f vec) Translate the physics object to the specified location.protected abstract voidsetPhysicsRotation(com.jme3.math.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(com.jme3.scene.Spatial spatial) Alter which spatial is controlled.voidupdate(float tpf) voidwrite(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, waitMethods inherited from interface com.jme3.util.clone.JmeCloneable
jmeClone
-
Field Details
-
spatial
protected com.jme3.scene.Spatial spatialspatial 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
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
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
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.- Specified by:
cloneForSpatialin interfacecom.jme3.scene.control.Control
-
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 interfacecom.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:
setSpatialin interfacecom.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:
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) - Specified by:
updatein interfacecom.jme3.scene.control.Control
-
render
public void render(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) - Specified by:
renderin interfacecom.jme3.scene.control.Control
-
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 interfacecom.jme3.export.Savable- 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 interfacecom.jme3.export.Savable- Parameters:
im- importer (not null)- Throws:
IOException- from importer
-