Package com.jme3.bullet.control
Class GhostControl
java.lang.Object
com.jme3.bullet.collision.PhysicsCollisionObject
com.jme3.bullet.objects.PhysicsGhostObject
com.jme3.bullet.control.GhostControl
- All Implemented Interfaces:
PhysicsControl,Savable,Control,JmeCloneable,Cloneable
A physics control to link a PhysicsGhostObject to a spatial.
The ghost object moves with the spatial it is attached to and can be used to detect overlaps with other physics objects (e.g. aggro radius).
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 ghost object is (or would be) addedprotected Spatialspatial to which this control is added, or null if noneFields inherited from class com.jme3.bullet.objects.PhysicsGhostObject
gObject, locationDirty, tempRot, tempTrans, tmp_inverseWorldRotationFields inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
COLLISION_GROUP_01, COLLISION_GROUP_02, COLLISION_GROUP_03, COLLISION_GROUP_04, COLLISION_GROUP_05, COLLISION_GROUP_06, COLLISION_GROUP_07, COLLISION_GROUP_08, COLLISION_GROUP_09, COLLISION_GROUP_10, COLLISION_GROUP_11, COLLISION_GROUP_12, COLLISION_GROUP_13, COLLISION_GROUP_14, COLLISION_GROUP_15, COLLISION_GROUP_16, COLLISION_GROUP_NONE, collisionGroup, collisionGroupsMask, collisionShape -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNo-argument constructor needed by SavableClassUtil.GhostControl(CollisionShape shape) Instantiate an enabled control with the specified shape. -
Method Summary
Modifier and TypeMethodDescriptionvoidcloneFields(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.Access the physics space to which the ghost object is (or would be) added.booleanTest whether physics-space coordinates should match the spatial's local coordinates.booleanTest whether this control is enabled.jmeClone()Create a shallow clone for the JME cloner.voidread(JmeImporter im) De-serialize this control, for example when loading from a J3O file.voidrender(RenderManager rm, ViewPort vp) Render this control.voidsetApplyPhysicsLocal(boolean applyPhysicsLocal) Alter whether physics-space coordinates should match the spatial's local coordinates.voidsetEnabled(boolean enabled) Enable or disable this control.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) Update this control.voidwrite(JmeExporter ex) Serialize this control, for example when saving to a J3O file.Methods inherited from class com.jme3.bullet.objects.PhysicsGhostObject
buildObject, destroy, getCcdMotionThreshold, getCcdSquareMotionThreshold, getCcdSweptSphereRadius, getObjectId, getOverlapping, getOverlappingCount, getOverlappingObjects, getPhysicsLocation, getPhysicsLocation, getPhysicsRotation, getPhysicsRotation, getPhysicsRotationMatrix, getPhysicsRotationMatrix, getPhysicsTransform, setCcdMotionThreshold, setCcdSweptSphereRadius, setCollisionShape, setPhysicsLocation, setPhysicsRotation, setPhysicsRotationMethods inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
addCollideWithGroup, getCollideWithGroups, getCollisionGroup, getCollisionShape, getUserObject, removeCollideWithGroup, setCollideWithGroups, setCollisionGroup, setUserObject
-
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 ghost object is (or would be) added -
applyLocal
protected boolean applyLocaltrue → physics coordinates match local transform, false → physics coordinates match world transform
-
-
Constructor Details
-
GhostControl
protected GhostControl()No-argument constructor needed by SavableClassUtil. Do not invoke directly! -
GhostControl
Instantiate an enabled control with the specified shape.- Parameters:
shape- (not null)
-
-
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
Deprecated.Clone this control for a different spatial. No longer used as of JME 3.1.- Specified by:
cloneForSpatialin interfaceControl- Parameters:
spatial- the spatial for the clone to control (or null)- Returns:
- a new control (not null)
-
jmeClone
Create a shallow clone for the JME cloner.- Specified by:
jmeClonein interfaceJmeCloneable- Returns:
- a new control (not null)
-
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 ghost object is removed from physics space. When the control is enabled again, the object is moved to the current location of the spatial 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) Update this control. Invoked once per frame during the logical-state update, provided the control is added to a scene. Do not invoke directly from user code. -
render
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. -
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 currently in.- Specified by:
setPhysicsSpacein interfacePhysicsControl- Parameters:
newSpace- where to add, or null to simply remove
-
getPhysicsSpace
Access the physics space to which the ghost object is (or would be) added.- Specified by:
getPhysicsSpacein interfacePhysicsControl- Returns:
- the pre-existing space, or null for none
-
write
Serialize this control, for example when saving to a J3O file.- Specified by:
writein interfaceSavable- Overrides:
writein classPhysicsGhostObject- Parameters:
ex- exporter (not null)- Throws:
IOException- from exporter
-
read
De-serialize this control, for example when loading from a J3O file.- Specified by:
readin interfaceSavable- Overrides:
readin classPhysicsGhostObject- Parameters:
im- importer (not null)- Throws:
IOException- from importer
-