Package com.jme3.bullet.control
Class RigidBodyControl
java.lang.Object
com.jme3.bullet.collision.PhysicsCollisionObject
com.jme3.bullet.objects.PhysicsRigidBody
com.jme3.bullet.control.RigidBodyControl
- All Implemented Interfaces:
PhysicsControl
,Savable
,Control
,JmeCloneable
,Cloneable
A physics control to link a PhysicsRigidBody to a spatial.
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→control is enabled, false→control is disabledprotected boolean
true→body is kinematic, false→body is static or dynamicprotected PhysicsSpace
space to which the body is (or would be) addedprotected Spatial
spatial to which this control is added, or null if noneFields inherited from class com.jme3.bullet.objects.PhysicsRigidBody
constructionInfo, joints, kinematic, localInertia, mass, motionState, rBody, tempMatrix, tempTrans, tempVec, tempVec2
Fields 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
ModifierConstructorDescriptionprotected
No-argument constructor needed by SavableClassUtil.RigidBodyControl
(float mass) When using this constructor, the CollisionShape for the RigidBody is generated automatically when the control is added to a spatial.RigidBodyControl
(CollisionShape shape) Instantiate an enabled control with mass=1 and the specified collision shape.RigidBodyControl
(CollisionShape shape, float mass) Instantiate an enabled control with the specified collision shape and mass. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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) Clone this control for a different spatial.protected void
Set the collision shape based on the controlled spatial and its descendents.Access the physics space to which the body is (or would be) added.boolean
Test whether physics-space coordinates should match the spatial's local coordinates.boolean
Test whether this control is enabled.boolean
Test whether this control is in kinematic mode.jmeClone()
Create a shallow clone for the JME cloner.void
read
(JmeImporter im) De-serialize this control, for example when loading from a J3O file.void
render
(RenderManager rm, ViewPort vp) Render this control.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.void
setKinematicSpatial
(boolean kinematicSpatial) Enable or disable kinematic mode.void
setPhysicsSpace
(PhysicsSpace newSpace) If enabled, add this control's body to the specified physics space.void
setSpatial
(Spatial spatial) Alter which spatial is controlled.void
update
(float tpf) Update this control.void
write
(JmeExporter ex) Serialize this control, for example when saving to a J3O file.Methods inherited from class com.jme3.bullet.objects.PhysicsRigidBody
activate, addJoint, applyCentralForce, applyForce, applyImpulse, applyTorque, applyTorqueImpulse, clearForces, destroy, getAngularDamping, getAngularFactor, getAngularSleepingThreshold, getAngularVelocity, getAngularVelocity, getCcdMotionThreshold, getCcdSquareMotionThreshold, getCcdSweptSphereRadius, getFriction, getGravity, getGravity, getInterpolatedPhysicsLocation, getInterpolatedPhysicsRotation, getJoints, getLinearDamping, getLinearSleepingThreshold, getLinearVelocity, getLinearVelocity, getMass, getMotionState, getObjectId, getPhysicsLocation, getPhysicsLocation, getPhysicsRotation, getPhysicsRotation, getPhysicsRotationMatrix, getPhysicsRotationMatrix, getRestitution, isActive, isContactResponse, isKinematic, postRebuild, preRebuild, rebuildRigidBody, removeJoint, setAngularDamping, setAngularFactor, setAngularSleepingThreshold, setAngularVelocity, setCcdMotionThreshold, setCcdSweptSphereRadius, setCollisionShape, setContactResponse, setDamping, setFriction, setGravity, setKinematic, setLinearDamping, setLinearSleepingThreshold, setLinearVelocity, setMass, setPhysicsLocation, setPhysicsRotation, setPhysicsRotation, setRestitution, setSleepingThresholds
Methods 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 body is (or would be) added -
kinematicSpatial
protected boolean kinematicSpatialtrue→body is kinematic, false→body is static or dynamic
-
-
Constructor Details
-
RigidBodyControl
protected RigidBodyControl()No-argument constructor needed by SavableClassUtil. Do not invoke directly! -
RigidBodyControl
public RigidBodyControl(float mass) When using this constructor, the CollisionShape for the RigidBody is generated automatically when the control is added to a spatial.- Parameters:
mass
- When not 0, a HullCollisionShape is generated, otherwise a MeshCollisionShape is used. For geometries with box or sphere meshes the proper box or sphere collision shape is used.
-
RigidBodyControl
Instantiate an enabled control with mass=1 and the specified collision shape.- Parameters:
shape
- the desired shape (not null, alias created)
-
RigidBodyControl
Instantiate an enabled control with the specified collision shape and mass.- Parameters:
shape
- the desired shape (not null, alias created)mass
- the desired mass (≥0)
-
-
Method Details
-
cloneForSpatial
Clone this control for a different spatial. No longer used as of JME 3.1.- Specified by:
cloneForSpatial
in 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:
jmeClone
in interfaceJmeCloneable
- Returns:
- a new control (not null)
-
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.
-
createCollisionShape
protected void createCollisionShape()Set the collision shape based on the controlled spatial and its descendents. -
setEnabled
public void setEnabled(boolean enabled) Enable or disable this control.When the control is disabled, the body is removed from physics space. When the control is enabled again, the body is moved to the current location of the spatial 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
-
isKinematicSpatial
public boolean isKinematicSpatial()Test whether this control is in kinematic mode.- Returns:
- true if the spatial location and rotation are applied to the rigid body, otherwise false
-
setKinematicSpatial
public void setKinematicSpatial(boolean kinematicSpatial) Enable or disable kinematic mode. In kinematic mode, the spatial's location and rotation will be applied to the rigid body.- Parameters:
kinematicSpatial
- true→kinematic, false→dynamic or static
-
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)
-
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. -
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 body to the specified physics space. In not enabled, alter where the body would be added. The body is removed from any other space it's currently in.- Specified by:
setPhysicsSpace
in interfacePhysicsControl
- Parameters:
newSpace
- where to add, or null to simply remove
-
getPhysicsSpace
Access the physics space to which the body is (or would be) added.- Specified by:
getPhysicsSpace
in interfacePhysicsControl
- Returns:
- the pre-existing space, or null for none
-
write
Serialize this control, for example when saving to a J3O file.- Specified by:
write
in interfaceSavable
- Overrides:
write
in classPhysicsRigidBody
- Parameters:
ex
- exporter (not null)- Throws:
IOException
- from exporter
-
read
De-serialize this control, for example when loading from a J3O file.- Specified by:
read
in interfaceSavable
- Overrides:
read
in classPhysicsRigidBody
- Parameters:
im
- importer (not null)- Throws:
IOException
- from importer
-