Package com.jme3.bullet.control
Class RigidBodyControl
java.lang.Object
com.jme3.bullet.NativePhysicsObject
com.jme3.bullet.collision.PhysicsCollisionObject
com.jme3.bullet.objects.PhysicsBody
com.jme3.bullet.objects.PhysicsRigidBody
com.jme3.bullet.control.RigidBodyControl
- All Implemented Interfaces:
PhysicsControl
,com.jme3.export.Savable
,com.jme3.scene.control.Control
,com.jme3.util.clone.JmeCloneable
,Cloneable
,Comparable<NativePhysicsObject>
A PhysicsControl to link a PhysicsRigidBody to a Spatial.
-
Field Summary
Fields inherited from class com.jme3.bullet.objects.PhysicsRigidBody
logger2, mass
Fields inherited from class com.jme3.bullet.objects.PhysicsBody
massForStatic
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, logger
Fields inherited from class com.jme3.bullet.NativePhysicsObject
loggerN
-
Constructor Summary
ModifierConstructorDescriptionprotected
No-argument constructor needed by SavableClassUtil.RigidBodyControl
(float mass) Instantiate an enabled control.RigidBodyControl
(CollisionShape shape) Instantiate an enabled Control with an active/responsive dynamic rigid body, mass=1, and the specified shape.RigidBodyControl
(CollisionShape shape, float mass) Instantiate an enabledControl
with a dynamic or static rigid body and the specified shape and mass. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cloneFields
(com.jme3.util.clone.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.com.jme3.scene.control.Control
cloneForSpatial
(com.jme3.scene.Spatial spatial) Clone this Control for a different Spatial.protected void
Set the body's CollisionShape based on the controlled spatial and its descendants.Access the PhysicsSpace to which the body is (or would be) added.com.jme3.scene.Spatial
Access the controlled spatial.boolean
Test whether physics-space coordinates should match the spatial's local coordinates.boolean
Test whether the collision-shape scale should match the spatial's scale.boolean
Test whether this Control is enabled.final boolean
Test whether this Control is in kinematic mode.void
read
(com.jme3.export.JmeImporter importer) De-serialize this Control from the specified importer, for example when loading from a J3O file.void
render
(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) Render this Control.void
setApplyPhysicsLocal
(boolean applyPhysicsLocal) Alter whether physics-space coordinates should match the spatial's local coordinates.void
setApplyScale
(boolean setting) Alter whether the collision-shape scale should match the spatial's scale.void
setEnabled
(boolean enabled) Enable or disable this Control.void
setKinematicSpatial
(boolean kinematicSpatial) Enable or disable kinematic mode for this Control.void
setPhysicsSpace
(PhysicsSpace newSpace) If enabled, add this control's body to the specified PhysicsSpace.void
setSpatial
(com.jme3.scene.Spatial controlledSpatial) Alter which Spatial is controlled.void
update
(float tpf) Update this Control.void
write
(com.jme3.export.JmeExporter exporter) Serialize this Control to the specified exporter, for example when saving to a J3O file.Methods inherited from class com.jme3.bullet.objects.PhysicsRigidBody
activate, applyCentralForce, applyCentralImpulse, applyForce, applyImpulse, applyTorque, applyTorqueImpulse, clearForces, getAngularDamping, getAngularFactor, getAngularFactor, getAngularSleepingThreshold, getAngularVelocity, getAngularVelocity, getAngularVelocityDp, getAngularVelocityLocal, getGravity, getGravityDp, getInverseInertiaLocal, getInverseInertiaWorld, getLinearDamping, getLinearFactor, getLinearSleepingThreshold, getLinearVelocity, getLinearVelocity, getLinearVelocityDp, getMass, getMotionState, getPhysicsRotation, getSquaredSpeed, isDynamic, isGravityProtected, isKinematic, kineticEnergy, mechanicalEnergy, postRebuild, preRebuild, rebuildRigidBody, setAngularDamping, setAngularFactor, setAngularFactor, setAngularSleepingThreshold, setAngularVelocity, setAngularVelocityDp, setCollisionShape, setContactResponse, setDamping, setEnableSleep, setGravity, setGravityDp, setInverseInertiaLocal, setKinematic, setLinearDamping, setLinearFactor, setLinearSleepingThreshold, setLinearVelocity, setLinearVelocityDp, setMass, setPhysicsLocation, setPhysicsLocationDp, setPhysicsRotation, setPhysicsRotation, setPhysicsRotationDp, setPhysicsRotationDp, setPhysicsScale, setPhysicsTransform, setProtectGravity, setSleepingThresholds, totalAppliedForce, totalAppliedTorque
Methods inherited from class com.jme3.bullet.objects.PhysicsBody
addJoint, cloneJoints, countJoints, getDeactivationDeadline, isDeactivationEnabled, listJoints, readJoints, removeJoint, setDeactivationDeadline, setDeactivationEnabled, writeJoints
Methods inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
activate, addCollideWithGroup, addToIgnoreList, attachCollisionShape, boundingBox, clearIgnoreList, cloneIgnoreList, collisionFlags, copyPcoProperties, countIgnored, debugMeshInitListener, debugMeshNormals, debugMeshResolution, debugNumSides, finalizeNative, findInstance, getActivationState, getAnisotropicFriction, getApplicationData, getCcdMotionThreshold, getCcdSquareMotionThreshold, getCcdSweptSphereRadius, getCollideWithGroups, getCollisionGroup, getCollisionShape, getCollisionSpace, getContactDamping, getContactProcessingThreshold, getContactStiffness, getDeactivationTime, getDebugMaterial, getFriction, getInternalType, getPhysicsLocation, getPhysicsLocation, getPhysicsLocationDp, getPhysicsRotation, getPhysicsRotationDp, getPhysicsRotationMatrix, getPhysicsRotationMatrixDp, getRestitution, getRollingFriction, getScale, getSpinningFriction, getTransform, getUserObject, hasAnisotropicFriction, ignores, initUserPointer, isActive, isContactResponse, isInWorld, isStatic, jmeClone, listIgnoredPcos, proxyGroup, proxyMask, readPcoProperties, removeCollideWithGroup, removeFromIgnoreList, setActivationState, setAnisotropicFriction, setApplicationData, setCcdMotionThreshold, setCcdSweptSphereRadius, setCollideWithGroups, setCollisionFlags, setCollisionGroup, setContactDamping, setContactProcessingThreshold, setContactStiffness, setDeactivationTime, setDebugMaterial, setDebugMeshInitListener, setDebugMeshNormals, setDebugMeshResolution, setDebugNumSides, setFriction, setIgnoreList, setLocationAndBasis, setRestitution, setRollingFriction, setSpinningFriction, setUserIndex, setUserIndex2, setUserIndex3, setUserObject, spaceId, toString, userIndex, userIndex2, userIndex3
Methods inherited from class com.jme3.bullet.NativePhysicsObject
compareTo, countTrackers, dumpTrackers, equals, freeUnusedObjects, hasAssignedNativeObject, hashCode, nativeId, reassignNativeId, setNativeId, setNativeIdNotTracked, unassignNativeObject
-
Field Details
-
logger3
message logger for this class
-
-
Constructor Details
-
RigidBodyControl
protected RigidBodyControl()No-argument constructor needed by SavableClassUtil. -
RigidBodyControl
public RigidBodyControl(float mass) Instantiate an enabled control. The new instance is incomplete because it lacks a collision shape, so it CANNOT be immediately added to a space. Its shape will be auto-generated when it is added to a Spatial. If the controlled spatial is a Geometry with a box or sphere mesh, a matching box or sphereCollisionShape
will be generated. OtherwiseCollisionShapeFactory
will be used.- Parameters:
mass
- the desired mass (≥0)
-
RigidBodyControl
Instantiate an enabled Control with an active/responsive dynamic rigid body, mass=1, and the specified shape.- Parameters:
shape
- the desired shape (not null, alias created)
-
RigidBodyControl
Instantiate an enabledControl
with a dynamic or static rigid body and the specified shape and mass.- Parameters:
shape
- the desired shape (not null, alias created)mass
- the desired mass (≥0)
-
-
Method Details
-
getSpatial
public com.jme3.scene.Spatial getSpatial()Access the controlled spatial.- Returns:
- the pre-existing
Spatial
, or null if none
-
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
-
isApplyScale
public boolean isApplyScale()Test whether the collision-shape scale should match the spatial's scale.- Returns:
- true if matching scales, otherwise false
-
isKinematicSpatial
public final boolean isKinematicSpatial()Test whether this Control is in kinematic mode. Kinematic mode has no effect when the body isn't kinematic.- Returns:
- true if the spatial's location and rotation would be applied to a kinematic body, otherwise false
-
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)
-
setApplyScale
public void setApplyScale(boolean setting) Alter whether the collision-shape scale should match the spatial's scale. CAUTION: Not all shapes can be scaled arbitrarily.Note that if the shape is shared (between collision objects and/or compound shapes) scaling can have unintended consequences.
- Parameters:
setting
- true → enable shape scaling (to the extent the CollisionShape supports it), false → disable shape scaling (default=false)
-
setKinematicSpatial
public void setKinematicSpatial(boolean kinematicSpatial) Enable or disable kinematic mode for this Control. If both the rigid body and controlled spatial are kinematic, the spatial's location and rotation will be applied to the body during each update. Kinematic mode has no effect when the body isn't kinematic.- Parameters:
kinematicSpatial
- true→kinematic, false→dynamic (default=true)
-
createCollisionShape
protected void createCollisionShape()Set the body's CollisionShape based on the controlled spatial and its descendants. -
cloneForSpatial
public com.jme3.scene.control.Control cloneForSpatial(com.jme3.scene.Spatial spatial) Clone this Control for a different Spatial. No longer used as of JME 3.1.- Specified by:
cloneForSpatial
in interfacecom.jme3.scene.control.Control
- Parameters:
spatial
- (unused)- Returns:
- never
- Throws:
UnsupportedOperationException
- always
-
getPhysicsSpace
Access the PhysicsSpace to which the body is (or would be) added.- Specified by:
getPhysicsSpace
in interfacePhysicsControl
- Returns:
- the pre-existing space, or null for none
-
isEnabled
public boolean isEnabled()Test whether this Control is enabled.- Specified by:
isEnabled
in interfacePhysicsControl
- Returns:
- true if enabled, otherwise false
-
render
public void render(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) Render this Control. Invoked once per ViewPort per frame, provided the Control is added to a scene. Should be invoked only by a subclass or by the RenderManager.- Specified by:
render
in interfacecom.jme3.scene.control.Control
- Parameters:
rm
- the RenderManager (unused)vp
- the ViewPort to render (unused)
-
setEnabled
public void setEnabled(boolean enabled) Enable or disable this Control.When the Control is disabled, the body is removed from PhysicsSpace. When the Control is enabled again, the body is moved to the current position of the Spatial and then added to the PhysicsSpace.
- Specified by:
setEnabled
in interfacePhysicsControl
- Parameters:
enabled
- true→enable the Control, false→disable it
-
setPhysicsSpace
If enabled, add this control's body to the specified PhysicsSpace. If 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
-
setSpatial
public void setSpatial(com.jme3.scene.Spatial controlledSpatial) 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 interfacecom.jme3.scene.control.Control
- Parameters:
controlledSpatial
- the Spatial to control (or null)
-
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.- Specified by:
update
in interfacecom.jme3.scene.control.Control
- Parameters:
tpf
- the time interval between frames (in seconds, ≥0)
-
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 interfacecom.jme3.util.clone.JmeCloneable
- Overrides:
cloneFields
in classPhysicsRigidBody
- Parameters:
cloner
- the Cloner that's cloning this Control (not null)original
- the instance from which this Control was shallow-cloned (not null, unaffected)
-
read
De-serialize this Control from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfacecom.jme3.export.Savable
- Overrides:
read
in classPhysicsRigidBody
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
write
Serialize this Control to the specified exporter, for example when saving to a J3O file.- Specified by:
write
in interfacecom.jme3.export.Savable
- Overrides:
write
in classPhysicsRigidBody
- Parameters:
exporter
- (not null)- Throws:
IOException
- from the exporter
-