Class PhysicsRigidBody
- All Implemented Interfaces:
Comparable<NativePhysicsObject>
- Direct Known Subclasses:
PhysicsVehicle
btRigidBody
.-
Field Summary
Modifier and TypeFieldDescriptionstatic final Logger
message logger for this classprotected float
JVM copy of the mass (>0) of a dynamic body, or 0 for a static bodyFields 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
ConstructorDescriptionPhysicsRigidBody
(CollisionShape shape) Instantiate a responsive, dynamic body with mass=1 and the specified CollisionShape.PhysicsRigidBody
(CollisionShape shape, float mass) Instantiate a responsive dynamic or static body with the specified CollisionShape and mass. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Reactivate the body if it has been deactivated due to lack of motion.void
applyCentralForce
(Vector3f force) Apply a force to the body's center of mass.void
applyCentralImpulse
(Vector3f impulse) Apply an impulse to the body's center of mass.void
applyForce
(Vector3f force, Vector3f offset) Apply a force to the body.void
applyImpulse
(Vector3f impulse, Vector3f offset) Apply an off-center impulse to the body.void
applyTorque
(Vector3f torque) Apply a torque to the body.void
applyTorqueImpulse
(Vector3f torqueImpulse) Apply a torque impulse to the body.void
Clear all forces and torques acting on the body, including gravity.float
Return the body's angular damping.getAngularFactor
(Vector3f storeResult) Copy the body's angular factors.float
Return the body's angular-motion sleeping threshold.getAngularVelocity
(Vector3f storeResult) Copy the body's angular velocity.getAngularVelocityDp
(Vec3d storeResult) Copy the body's angular velocity.getAngularVelocityLocal
(Vector3f storeResult) Calculate the body's angular velocity in its local coordinates.getGravity
(Vector3f storeResult) Copy the body's gravitational acceleration.getGravityDp
(Vec3d storeResult) Copy the body's gravitational acceleration.getInverseInertiaLocal
(Vector3f storeResult) Copy the principal (diagonal) elements of the inverse inertia tensor in the body's local coordinates.getInverseInertiaWorld
(Matrix3f storeResult) Compute the inverse inertia tensor in physics-space coordinates.float
Return the body's linear damping.getLinearFactor
(Vector3f storeResult) Copy the body's linear factors.float
Return the body's linear-motion sleeping threshold.getLinearVelocity
(Vector3f storeResult) Copy the linear velocity of the body's center of mass.getLinearVelocityDp
(Vec3d storeResult) Copy the linear velocity of the body's center of mass.float
getMass()
Return the body's mass.Access the body's motion state.float
Calculate the squared speed of the body.boolean
Test whether the body is in dynamic mode.boolean
Test whether the body's gravity can be overwritten by PhysicsSpace.final boolean
Test whether the body is in kinematic mode.double
Calculate the body's kinetic energy (linear + angular).double
Calculate the mechanical energy of the body (kinetic + potential) assuming a uniform gravitational field.protected void
For use by subclasses.protected void
For use by subclasses.void
Rebuild the rigid body with a new native object.void
setAngularDamping
(float angularDamping) Alter the body's angular damping.void
setAngularFactor
(float factor) Alter the body's angular factor.void
setAngularFactor
(Vector3f factor) Alter the body's angular factors, used to scale applied torques.void
setAngularSleepingThreshold
(float threshold) Alter the body's angular-motion sleeping threshold.void
setAngularVelocity
(Vector3f omega) Alter the body's angular velocity.void
setAngularVelocityDp
(Vec3d omega) Alter the body's angular velocity.void
setCollisionShape
(CollisionShape desiredShape) Apply the specified CollisionShape to the body.void
setContactResponse
(boolean newState) Enable/disable the body's contact response.void
setDamping
(float linearDamping, float angularDamping) Alter the body's damping.void
setEnableSleep
(boolean setting) Alter the body's activation state to allow/disallow sleeping.void
setGravity
(Vector3f acceleration) Alter the body's gravitational acceleration.void
setGravityDp
(Vec3d acceleration) Alter the body's gravitational acceleration.void
setInverseInertiaLocal
(Vector3f inverseInertia) Alter the principal (diagonal) components of the local inertia tensor in the body's local coordinates.void
setKinematic
(boolean kinematic) Put the body into kinematic mode or take it out of kinematic mode.void
setLinearDamping
(float linearDamping) Alter the body's linear damping.void
setLinearFactor
(Vector3f factor) Alter the body's linear factors.void
setLinearSleepingThreshold
(float threshold) Alter the body's linear-motion sleeping threshold.void
setLinearVelocity
(Vector3f velocity) Alter the linear velocity of the body's center of mass.void
setLinearVelocityDp
(Vec3d velocity) Alter the linear velocity of the body's center of mass.void
setMass
(float mass) Alter the body's mass.void
setPhysicsLocation
(Vector3f location) Directly relocate the body's center of mass.void
setPhysicsLocationDp
(Vec3d location) Directly relocate the body's center of mass.void
setPhysicsRotation
(Matrix3f orientation) Directly alter the body's orientation.void
setPhysicsRotation
(Quaternion orientation) Directly reorient the body.void
setPhysicsRotationDp
(Matrix3d orientation) Directly reorient the body.void
setPhysicsRotationDp
(Quatd orientation) Directly reorient the body.void
setPhysicsScale
(Vector3f newScale) Rescale the body.void
setPhysicsTransform
(Transform transform) Directly alter the body's transform, including the scale of its shape.void
setProtectGravity
(boolean newState) Alter whether the body's gravity should be overwritten if the body gets added to a PhysicsSpace or the gravity of the PhysicsSpace changes.void
setSleepingThresholds
(float linear, float angular) Alter the body's sleeping thresholds.totalAppliedForce
(Vector3f storeResult) Determine the total force applied to the body (excluding contact forces, damping, and gravity).totalAppliedTorque
(Vector3f storeResult) Determine the total torque applied to the body (excluding contact forces and damping).Methods inherited from class com.jme3.bullet.objects.PhysicsBody
addJoint, countJoints, getDeactivationDeadline, isDeactivationEnabled, listJoints, removeJoint, setDeactivationDeadline, setDeactivationEnabled
Methods inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
activate, addCollideWithGroup, addToIgnoreList, attachCollisionShape, boundingBox, clearIgnoreList, collisionFlags, copyPcoProperties, countIgnored, finalizeNative, findInstance, getActivationState, getAnisotropicFriction, getCcdMotionThreshold, getCcdSquareMotionThreshold, getCcdSweptSphereRadius, getCollideWithGroups, getCollisionGroup, getCollisionShape, getCollisionSpace, getContactDamping, getContactProcessingThreshold, getContactStiffness, getDeactivationTime, getFriction, getInternalType, getPhysicsLocation, getPhysicsLocationDp, getPhysicsRotation, getPhysicsRotationDp, getPhysicsRotationMatrix, getPhysicsRotationMatrixDp, getRestitution, getRollingFriction, getScale, getSpinningFriction, getTransform, getTransformDp, getUserObject, hasAnisotropicFriction, ignores, initUserPointer, isActive, isContactResponse, isInWorld, isStatic, listIgnoredPcos, proxyGroup, proxyMask, removeCollideWithGroup, removeFromIgnoreList, setActivationState, setAnisotropicFriction, setCcdMotionThreshold, setCcdSweptSphereRadius, setCollideWithGroups, setCollisionFlags, setCollisionGroup, setContactDamping, setContactProcessingThreshold, setContactStiffness, setDeactivationTime, 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
-
logger2
message logger for this class -
mass
protected float massJVM copy of the mass (>0) of a dynamic body, or 0 for a static body
-
-
Constructor Details
-
PhysicsRigidBody
Instantiate a responsive, dynamic body with mass=1 and the specified CollisionShape. The new body is not added to any PhysicsSpace.- Parameters:
shape
- the desired shape (not null, alias created)
-
PhysicsRigidBody
Instantiate a responsive dynamic or static body with the specified CollisionShape and mass. The new body is not added to any PhysicsSpace.- Parameters:
shape
- the desired shape (not null, alias created)mass
- if 0, a static body is created; otherwise a dynamic body is created (≥0, default=1)
-
-
Method Details
-
activate
public void activate()Reactivate the body if it has been deactivated due to lack of motion. -
applyCentralForce
Apply a force to the body's center of mass. Effective on the next simulation step, then cleared.To apply an impulse, use
applyCentralImpulse(com.jme3.math.Vector3f)
.- Parameters:
force
- the force vector (mass times distance per second squared in physics-space coordinates, not null, finite, unaffected)
-
applyCentralImpulse
Apply an impulse to the body's center of mass.- Parameters:
impulse
- the impulse vector (mass times distance per second in physics-space coordinates, not null, unaffected)
-
applyForce
Apply a force to the body. Effective on the next simulation step, then cleared.To apply an impulse, use
applyImpulse(com.jme3.math.Vector3f, com.jme3.math.Vector3f)
.- Parameters:
force
- the force vector (mass times distance per second squared in physics-space coordinates, not null, finite, unaffected)offset
- the location to apply the force (relative to the body's center in physics-space coordinates, not null, finite, unaffected)
-
applyImpulse
Apply an off-center impulse to the body.- Parameters:
impulse
- the impulse vector (mass times distance per second in physics-space coordinates, not null, unaffected)offset
- where to apply the impulse (relative to the body's center of mass in physics-space coordinates, not null, unaffected)
-
applyTorque
Apply a torque to the body. Effective on the next simulation step, then cleared.To apply a torque impulse, use
applyTorqueImpulse(com.jme3.math.Vector3f)
.- Parameters:
torque
- the torque vector (mass times distance squared per second squared in physics-space coordinates, not null, finite, unaffected)
-
applyTorqueImpulse
Apply a torque impulse to the body.- Parameters:
torqueImpulse
- the torque impulse vector (mass times physics-space units squared per second in physics-space coordinates, not null, unaffected)
-
clearForces
public void clearForces()Clear all forces and torques acting on the body, including gravity. -
getAngularDamping
public float getAngularDamping()Return the body's angular damping.- Returns:
- the damping fraction (≥0, ≤1)
-
getAngularFactor
Copy the body's angular factors.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- the angular factor for each axis (either storeResult or a new vector, not null)
-
getAngularSleepingThreshold
public float getAngularSleepingThreshold()Return the body's angular-motion sleeping threshold. Note that "sleeping" is synonym for "deactivation".- Returns:
- the angular-motion threshold (in radians per second, ≥0)
-
getAngularVelocity
Copy the body's angular velocity. The body must be in dynamic mode.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- an angular-velocity vector (radians per second in physics-space coordinates, either storeResult or a new vector, not null)
-
getAngularVelocityDp
Copy the body's angular velocity. The body must be in dynamic mode.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- an angular-velocity vector (radians per second in physics-space coordinates, either storeResult or a new vector, not null)
-
getAngularVelocityLocal
Calculate the body's angular velocity in its local coordinates. The body must be in dynamic mode.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- a velocity vector (radians per second in local coordinates, either storeResult or a new vector, not null)
-
getGravityDp
Copy the body's gravitational acceleration.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- an acceleration vector in physics-space coordinates (either storeResult or a new vector, not null)
-
getInverseInertiaLocal
Copy the principal (diagonal) elements of the inverse inertia tensor in the body's local coordinates.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- a vector (either storeResult or a new vector, not null)
-
getInverseInertiaWorld
Compute the inverse inertia tensor in physics-space coordinates.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- a matrix (either storeResult or a new matrix, not null)
-
getLinearDamping
public float getLinearDamping()Return the body's linear damping.- Returns:
- the damping fraction (≥0, ≤1)
-
getLinearFactor
Copy the body's linear factors.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- the linear factor for each axis (either storeResult or a new vector, not null)
-
getLinearSleepingThreshold
public float getLinearSleepingThreshold()Return the body's linear-motion sleeping threshold. Note that "sleeping" is synonym for "deactivation".- Returns:
- the linear-motion threshold (in physics-space units per second, ≥0)
-
getLinearVelocity
Copy the linear velocity of the body's center of mass. The body must be in dynamic mode.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- a velocity vector (physics-space units per second in physics-space coordinates, either storeResult or a new vector, not null)
-
getLinearVelocityDp
Copy the linear velocity of the body's center of mass. The body must be in dynamic mode.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- a velocity vector (physics-space units per second in physics-space coordinates, either storeResult or a new vector, not null)
-
getMotionState
Access the body's motion state.- Returns:
- the pre-existing instance (not null)
-
getSquaredSpeed
public float getSquaredSpeed()Calculate the squared speed of the body. The body must be in dynamic mode.- Returns:
- the squared speed (in physics-space units squared per second squared, ≥0)
-
isDynamic
public boolean isDynamic()Test whether the body is in dynamic mode.- Returns:
- true if in dynamic mode, otherwise false (static/kinematic mode)
-
isGravityProtected
public boolean isGravityProtected()Test whether the body's gravity can be overwritten by PhysicsSpace.- Returns:
- false if the body's gravity can be overwritten, otherwise true
-
isKinematic
public final boolean isKinematic()Test whether the body is in kinematic mode.In kinematic mode, the body is not influenced by physics but can affect other physics objects. Its kinetic force is calculated based on its movement and weight.
- Returns:
- true if in kinematic mode, otherwise false (dynamic/static mode)
-
kineticEnergy
public double kineticEnergy()Calculate the body's kinetic energy (linear + angular). The body must be in dynamic mode.- Returns:
- the total kinetic energy (≥0)
-
mechanicalEnergy
public double mechanicalEnergy()Calculate the mechanical energy of the body (kinetic + potential) assuming a uniform gravitational field. The body must be in dynamic mode.- Returns:
- the total mechanical energy
-
rebuildRigidBody
public void rebuildRigidBody()Rebuild the rigid body with a new native object. -
setAngularDamping
public void setAngularDamping(float angularDamping) Alter the body's angular damping.- Parameters:
angularDamping
- the desired angular damping fraction (≥0, ≤1, default=0)
-
setAngularFactor
public void setAngularFactor(float factor) Alter the body's angular factor.- Parameters:
factor
- the desired angular factor for all axes (not null, unaffected, default=1)
-
setAngularFactor
Alter the body's angular factors, used to scale applied torques.- Parameters:
factor
- the desired angular factor for each axis (not null, unaffected, default=(1,1,1))
-
setAngularSleepingThreshold
public void setAngularSleepingThreshold(float threshold) Alter the body's angular-motion sleeping threshold. Note that "sleeping" is synonym for "deactivation".- Parameters:
threshold
- the desired threshold (in radians per second, ≥0, default=1)
-
setAngularVelocity
Alter the body's angular velocity.- Parameters:
omega
- the desired angular velocity (radians per second in physics-space coordinates, not null, finite, unaffected)
-
setAngularVelocityDp
Alter the body's angular velocity.- Parameters:
omega
- the desired angular velocity (radians per second in physics-space coordinates, not null, unaffected)
-
setCollisionShape
Apply the specified CollisionShape to the body. The body gets rebuilt on the native side.- Overrides:
setCollisionShape
in classPhysicsCollisionObject
- Parameters:
desiredShape
- the shape to apply (not null, alias created)
-
setContactResponse
public void setContactResponse(boolean newState) Enable/disable the body's contact response.- Parameters:
newState
- true to respond to contacts, false to ignore them (default=true)
-
setDamping
public void setDamping(float linearDamping, float angularDamping) Alter the body's damping.- Parameters:
linearDamping
- the desired linear damping fraction (≥0, ≤1, default=0)angularDamping
- the desired angular damping fraction (≥0, ≤1, default=0)
-
setEnableSleep
public void setEnableSleep(boolean setting) Alter the body's activation state to allow/disallow sleeping. Note that "sleeping" is synonym for "deactivation".- Parameters:
setting
- true→enable sleeping, false→disable sleeping (default=true)
-
setGravityDp
Alter the body's gravitational acceleration.Invoke this method after adding the body to a PhysicsSpace. Unless protection is set, adding a body to a PhysicsSpace overrides its gravity.
- Parameters:
acceleration
- the desired acceleration vector (in physics-space coordinates, not null, unaffected, default=(0,0,0))- See Also:
-
setInverseInertiaLocal
Alter the principal (diagonal) components of the local inertia tensor in the body's local coordinates.- Parameters:
inverseInertia
- the desired component values (not null, unaffected)
-
setKinematic
public void setKinematic(boolean kinematic) Put the body into kinematic mode or take it out of kinematic mode.In kinematic mode, the body is not influenced by physics but can affect other physics objects. Its kinetic force is calculated based on its mass and motion.
- Parameters:
kinematic
- true→set kinematic mode, false→set dynamic (default=false)
-
setLinearDamping
public void setLinearDamping(float linearDamping) Alter the body's linear damping.- Parameters:
linearDamping
- the desired linear damping fraction (≥0, ≤1, default=0)
-
setLinearFactor
Alter the body's linear factors.- Parameters:
factor
- the desired linear factor for each axis (not null, unaffected, default=(1,1,1))
-
setLinearSleepingThreshold
public void setLinearSleepingThreshold(float threshold) Alter the body's linear-motion sleeping threshold. Note that "sleeping" is synonym for "deactivation".- Parameters:
threshold
- the desired threshold (in physics-space units per second, ≥0, default=0.8)
-
setLinearVelocity
Alter the linear velocity of the body's center of mass.- Parameters:
velocity
- the desired velocity (physics-space units per second in physics-space coordinates, not null, finite, unaffected)
-
setLinearVelocityDp
Alter the linear velocity of the body's center of mass.- Parameters:
velocity
- the desired velocity (physics-space units per second in physics-space coordinates, not null, unaffected)
-
setPhysicsLocationDp
Directly relocate the body's center of mass.- Parameters:
location
- the desired location (in physics-space coordinates, not null, unaffected)
-
setPhysicsRotation
Directly alter the body's orientation.- Parameters:
orientation
- the desired orientation (rotation matrix relative to physics-space coordinates, not null, unaffected)
-
setPhysicsRotation
Directly reorient the body.- Parameters:
orientation
- the desired orientation (relative to physics-space coordinates, not null, not zero, unaffected)
-
setPhysicsRotationDp
Directly reorient the body.- Parameters:
orientation
- the desired orientation (rotation matrix relative to physics-space coordinates, not null, unaffected)
-
setPhysicsRotationDp
Directly reorient the body.- Parameters:
orientation
- the desired orientation (relative to physics-space coordinates, not null, not zero, unaffected)
-
setPhysicsScale
Rescale the body. Note that if it has joints, their pivot locations will not be adjusted.- Parameters:
newScale
- the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
-
setPhysicsTransform
Directly alter the body's transform, including the scale of its shape. If the body has joints, their pivot points will not be adjusted for scale changes.- Parameters:
transform
- the desired transform (relative to physics-space coordinates, not null, unaffected)
-
setProtectGravity
public void setProtectGravity(boolean newState) Alter whether the body's gravity should be overwritten if the body gets added to a PhysicsSpace or the gravity of the PhysicsSpace changes.- Parameters:
newState
- true to preserve the body's gravity, false to allow it to be overwritten (default=false)
-
setSleepingThresholds
public void setSleepingThresholds(float linear, float angular) Alter the body's sleeping thresholds. Note that "sleeping" is synonym for "deactivation".These thresholds influence whether the body will be deactivated to save resources. Low values keep the body active when it barely moves.
- Parameters:
linear
- the desired linear threshold (in physics-space units per second, ≥0, default=0.8)angular
- the desired angular threshold (in radians per second, ≥0, default=1)
-
totalAppliedForce
Determine the total force applied to the body (excluding contact forces, damping, and gravity).- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- the total force (either storeResult or a new vector, mass times physics-space units per second squared in physics-space coordinates)
-
totalAppliedTorque
Determine the total torque applied to the body (excluding contact forces and damping).- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- the total torque (either storeResult or a new vector, mass times physics-space units squared per second squared in physics-space coordinates)
-
postRebuild
protected void postRebuild()For use by subclasses. -
preRebuild
protected void preRebuild()For use by subclasses. -
getGravity
Copy the body's gravitational acceleration.- Specified by:
getGravity
in classPhysicsBody
- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- an acceleration vector in physics-space coordinates (either storeResult or a new vector, not null)
-
getMass
public float getMass()Return the body's mass.- Specified by:
getMass
in classPhysicsBody
- Returns:
- the mass (>0) or zero for a static body
-
setGravity
Alter the body's gravitational acceleration.Invoke this method after adding the body to a PhysicsSpace. Unless protection is set, adding a body to a PhysicsSpace overrides its gravity.
- Specified by:
setGravity
in classPhysicsBody
- Parameters:
acceleration
- the desired acceleration vector (in physics-space coordinates, not null, finite, unaffected, default=(0,0,0))- See Also:
-
setMass
public void setMass(float mass) Alter the body's mass. Static bodies have mass=0. For dynamic bodies, it is best to keep the mass on the order of 1.- Specified by:
setMass
in classPhysicsBody
- Parameters:
mass
- the desired mass (≥0, default=1)
-
setPhysicsLocation
Directly relocate the body's center of mass.- Specified by:
setPhysicsLocation
in classPhysicsBody
- Parameters:
location
- the desired location (in physics-space coordinates, not null, finite, unaffected)
-