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 this body if it has been deactivated due to lack of motion.void
applyCentralForce
(Vector3f force) Apply a central force to the body.void
applyCentralImpulse
(Vector3f impulse) Apply a central impulse to the body.void
applyForce
(Vector3f force, Vector3f offset) Apply a force to the body.void
applyImpulse
(Vector3f impulse, Vector3f offset) Apply an 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 this body, including gravity.float
Read this body's angular damping.getAngularFactor
(Vector3f storeResult) Copy this body's angular factor.float
Read this body's angular-motion sleeping threshold.getAngularVelocity
(Vector3f storeResult) Copy this body's angular velocity.getAngularVelocityDp
(Vec3d storeResult) Copy this body's angular velocity.getAngularVelocityLocal
(Vector3f storeResult) Calculate this body's angular velocity in its local coordinates.getGravity
(Vector3f storeResult) Copy this body's gravitational acceleration.getGravityDp
(Vec3d storeResult) Copy this 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
Read this body's linear damping.getLinearFactor
(Vector3f storeResult) Copy this body's linear factors.float
Read this body's linear-motion sleeping threshold.getLinearVelocity
(Vector3f storeResult) Copy the linear velocity of this body's center of mass.getLinearVelocityDp
(Vec3d storeResult) Copy the linear velocity of this body's center of mass.float
getMass()
Read this body's mass.Access this body's motion state.float
Calculate the squared speed of this body.boolean
Test whether this body is in dynamic mode.boolean
Test whether this body's gravity can be overwritten by PhysicsSpace.final boolean
Test whether this body is in kinematic mode.double
Calculate this body's kinetic energy (linear + angular).double
Calculate the mechanical energy of this body (kinetic + potential) assuming a uniform gravitational field.protected void
For use by subclasses.protected void
For use by subclasses.void
Rebuild this rigid body with a new native object.void
setAngularDamping
(float angularDamping) Alter this body's angular damping.void
setAngularFactor
(float factor) Alter this body's angular factor.void
setAngularFactor
(Vector3f factor) Alter this body's angular factors, used to scale applied torques.void
setAngularSleepingThreshold
(float threshold) Alter this body's angular-motion sleeping threshold.void
setAngularVelocity
(Vector3f omega) Alter this body's angular velocity.void
setAngularVelocityDp
(Vec3d omega) Alter this body's angular velocity.void
setCollisionShape
(CollisionShape collisionShape) Apply the specified CollisionShape to this body.void
setContactResponse
(boolean newState) Enable/disable this body's contact response.void
setDamping
(float linearDamping, float angularDamping) Alter this body's damping.void
setEnableSleep
(boolean setting) Alter this body's activation state to allow/disallow sleeping.void
setGravity
(Vector3f acceleration) Alter this body's gravitational acceleration.void
setGravityDp
(Vec3d acceleration) Alter this 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 this body into kinematic mode or take it out of kinematic mode.void
setLinearDamping
(float linearDamping) Alter this body's linear damping.void
setLinearFactor
(Vector3f factor) Alter this body's linear factors.void
setLinearSleepingThreshold
(float threshold) Alter this body's linear-motion sleeping threshold.void
setLinearVelocity
(Vector3f velocity) Alter the linear velocity of this body's center of mass.void
setLinearVelocityDp
(Vec3d velocity) Alter the linear velocity of this body's center of mass.void
setMass
(float mass) Alter this body's mass.void
setPhysicsLocation
(Vector3f location) Directly relocate this body's center of mass.void
setPhysicsLocationDp
(Vec3d location) Directly relocate this body's center of mass.void
setPhysicsRotation
(Matrix3f orientation) Directly alter this body's orientation.void
setPhysicsRotation
(Quaternion orientation) Directly reorient this body.void
setPhysicsRotationDp
(Matrix3d orientation) Directly reorient this body.void
setPhysicsRotationDp
(Quatd orientation) Directly reorient this body.void
setPhysicsScale
(Vector3f newScale) Rescale this body.void
setPhysicsTransform
(Transform transform) Directly alter this body's transform, including the scale of its shape.void
setProtectGravity
(boolean newState) Alter whether this 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 this body's sleeping thresholds.totalAppliedForce
(Vector3f storeResult) Determine the total force applied to this body (excluding contact forces, damping, and gravity).totalAppliedTorque
(Vector3f storeResult) Determine the total torque applied to this 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 this body if it has been deactivated due to lack of motion. -
applyCentralForce
Apply a central force to the body. 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 physics-space units per second squared in physics-space coordinates, not null, unaffected)
-
applyCentralImpulse
Apply a central impulse to the body.- Parameters:
impulse
- the impulse vector (mass times physics-space units 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 physics-space units per second squared in physics-space coordinates, not null, unaffected)offset
- the location to apply the force (relative to the body's center in physics-space coordinates, not null, unaffected)
-
applyImpulse
Apply an impulse to the body.- Parameters:
impulse
- the impulse vector (mass times physics-space units per second in physics-space coordinates, not null, unaffected)offset
- the location to apply the impulse (relative to the body's center 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 physics-space units squared per second squared in physics-space coordinates, not null, 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 this body, including gravity. -
getAngularDamping
public float getAngularDamping()Read this body's angular damping.- Returns:
- the damping fraction (≥0, ≤1)
-
getAngularFactor
Copy this body's angular factor.- 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()Read this 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 this body's angular velocity. 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 physics-space coordinates, either storeResult or a new vector, not null)
-
getAngularVelocityDp
Copy this body's angular velocity. 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 physics-space coordinates, either storeResult or a new vector, not null)
-
getAngularVelocityLocal
Calculate this 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 this 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()Read this body's linear damping.- Returns:
- the damping fraction (≥0, ≤1)
-
getLinearFactor
Copy this 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()Read this 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 this 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 this 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 this body's motion state.- Returns:
- the pre-existing instance (not null)
-
getSquaredSpeed
public float getSquaredSpeed()Calculate the squared speed of this 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 this body is in dynamic mode.- Returns:
- true if in dynamic mode, otherwise false (static/kinematic mode)
-
isGravityProtected
public boolean isGravityProtected()Test whether this body's gravity can be overwritten by PhysicsSpace.- Returns:
- false if this body's gravity can be overwritten, otherwise true
-
isKinematic
public final boolean isKinematic()Test whether this 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 this 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 this 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 this rigid body with a new native object. -
setAngularDamping
public void setAngularDamping(float angularDamping) Alter this body's angular damping.- Parameters:
angularDamping
- the desired angular damping fraction (≥0, ≤1, default=0)
-
setAngularFactor
public void setAngularFactor(float factor) Alter this body's angular factor.- Parameters:
factor
- the desired angular factor for all axes (not null, unaffected, default=1)
-
setAngularFactor
Alter this 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 this 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 this body's angular velocity.- Parameters:
omega
- the desired angular velocity (in physics-space coordinates, not null, unaffected)
-
setAngularVelocityDp
Alter this body's angular velocity.- Parameters:
omega
- the desired angular velocity (in physics-space coordinates, not null, unaffected)
-
setCollisionShape
Apply the specified CollisionShape to this body. The body gets rebuilt on the native side.- Overrides:
setCollisionShape
in classPhysicsCollisionObject
- Parameters:
collisionShape
- the shape to apply (not null, alias created)
-
setContactResponse
public void setContactResponse(boolean newState) Enable/disable this 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 this 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 this 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 this 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 this 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 this body's linear damping.- Parameters:
linearDamping
- the desired linear damping fraction (≥0, ≤1, default=0)
-
setLinearFactor
Alter this 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 this 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 this 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 this 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 this body's center of mass.- Parameters:
location
- the desired location (in physics-space coordinates, not null, unaffected)
-
setPhysicsRotation
Directly alter this body's orientation.- Parameters:
orientation
- the desired orientation (rotation matrix relative to physics-space coordinates, not null, unaffected)
-
setPhysicsRotation
Directly reorient this body.- Parameters:
orientation
- the desired orientation (relative to physics-space coordinates, not null, not zero, unaffected)
-
setPhysicsRotationDp
Directly reorient this body.- Parameters:
orientation
- the desired orientation (rotation matrix relative to physics-space coordinates, not null, unaffected)
-
setPhysicsRotationDp
Directly reorient this body.- Parameters:
orientation
- the desired orientation (relative to physics-space coordinates, not null, not zero, unaffected)
-
setPhysicsScale
Rescale this 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 this 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 this 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 this body's gravity, false to allow it to be overwritten (default=false)
-
setSleepingThresholds
public void setSleepingThresholds(float linear, float angular) Alter this 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 this 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 this 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 this 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()Read this body's mass.- Specified by:
getMass
in classPhysicsBody
- Returns:
- the mass (>0) or zero for a static body
-
setGravity
Alter this 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 this 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 this body's center of mass.- Specified by:
setPhysicsLocation
in classPhysicsBody
- Parameters:
location
- the desired location (in physics-space coordinates, not null, finite, unaffected)
-