public class PhysicsRigidBody extends PhysicsCollisionObject
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<PhysicsJoint> |
joints
joint list
|
protected boolean |
kinematic
copy of kinematic flag: true→set kinematic mode (spatial controls
body), false→dynamic/static mode (body controls spatial)
(default=false)
|
protected float |
mass
copy of mass (>0) of a dynamic body, or 0 for a static body
(default=1)
|
protected RigidBodyMotionState |
motionState
motion state
|
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, objectId
Modifier | Constructor and Description |
---|---|
protected |
PhysicsRigidBody()
No-argument constructor needed by SavableClassUtil.
|
|
PhysicsRigidBody(CollisionShape shape)
Instantiate a dynamic body with mass=1 and the specified collision shape.
|
|
PhysicsRigidBody(CollisionShape shape,
float mass)
Instantiate a body with the specified collision shape and mass.
|
Modifier and Type | Method and Description |
---|---|
void |
activate()
Reactivates this body if it has been deactivated due to lack of motion.
|
void |
addJoint(PhysicsJoint joint)
Do not invoke directly! Joints are added automatically when created.
|
void |
applyCentralForce(Vector3f force)
Apply a force to the PhysicsRigidBody.
|
void |
applyForce(Vector3f force,
Vector3f location)
Apply a force to the PhysicsRigidBody.
|
void |
applyImpulse(Vector3f impulse,
Vector3f rel_pos)
Apply an impulse to the body the next physics update.
|
void |
applyTorque(Vector3f torque)
Apply a force to the PhysicsRigidBody.
|
void |
applyTorqueImpulse(Vector3f vec)
Apply a torque impulse to the body in the next physics update.
|
void |
clearForces()
Clear all forces acting on this body.
|
float |
getAngularDamping()
Read this body's angular damping.
|
float |
getAngularFactor()
Read this body's angular factor for the X axis.
|
Vector3f |
getAngularFactor(Vector3f store)
Copy this body's angular factors.
|
float |
getAngularSleepingThreshold()
Read this body's angular sleeping threshold.
|
Vector3f |
getAngularVelocity()
Copy this body's angular velocity.
|
void |
getAngularVelocity(Vector3f vec)
Copy this body's angular velocity.
|
float |
getCcdMotionThreshold()
Calculate this body's continuous collision detection (CCD) motion
threshold.
|
float |
getCcdSquareMotionThreshold()
Calculate the square of this body's continuous collision detection (CCD)
motion threshold.
|
float |
getCcdSweptSphereRadius()
Read the radius of the swept sphere used for continuous collision
detection (CCD).
|
float |
getFriction()
Read this body's friction.
|
Vector3f |
getGravity()
Copy this body's gravitational acceleration.
|
Vector3f |
getGravity(Vector3f gravity)
Copy this body's gravitational acceleration.
|
Vector3f |
getInverseInertiaLocal(Vector3f trans)
Copy the principal components of the local inverse inertia tensor.
|
java.util.List<PhysicsJoint> |
getJoints()
Access the list of joints connected with this body.
|
float |
getLinearDamping()
Read this body's linear damping.
|
Vector3f |
getLinearFactor()
Copy this body's linear factors.
|
float |
getLinearSleepingThreshold()
Read this body's linear sleeping threshold.
|
Vector3f |
getLinearVelocity()
Copy the linear velocity of this body's center of mass.
|
void |
getLinearVelocity(Vector3f vec)
Copy the linear velocity of this body's center of mass.
|
float |
getMass()
Read this body's mass.
|
RigidBodyMotionState |
getMotionState()
Access this body's motion state.
|
Vector3f |
getPhysicsLocation()
Copy the location of this body's center of mass.
|
Vector3f |
getPhysicsLocation(Vector3f trans)
Copy the location of this body's center of mass.
|
Quaternion |
getPhysicsRotation()
Copy this body's orientation to a quaternion.
|
Quaternion |
getPhysicsRotation(Quaternion rot)
Copy this body's orientation to a quaternion.
|
Matrix3f |
getPhysicsRotationMatrix()
Copy this body's orientation to a matrix.
|
Matrix3f |
getPhysicsRotationMatrix(Matrix3f rot)
Copy this body's orientation to a matrix.
|
float |
getRestitution()
Read this body's restitution (bounciness).
|
boolean |
isActive()
Test whether this body has been deactivated due to lack of motion.
|
boolean |
isInWorld()
Test whether this body is in a physics space.
|
boolean |
isKinematic()
Test whether this body is in kinematic mode.
|
protected void |
postRebuild()
For use by subclasses.
|
protected void |
preRebuild()
For use by subclasses.
|
void |
read(JmeImporter e)
De-serialize this body, for example when loading from a J3O file.
|
protected void |
rebuildRigidBody()
Build/rebuild this body after parameters have changed.
|
void |
removeJoint(PhysicsJoint joint)
Do not invoke directly! Joints are removed automatically when destroyed.
|
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.
|
void |
setAngularSleepingThreshold(float angularSleepingThreshold)
Alter this body's angular sleeping threshold.
|
void |
setAngularVelocity(Vector3f vec)
Alter this body's angular velocity.
|
void |
setCcdMotionThreshold(float threshold)
Alter the amount of motion required to activate continuous collision
detection (CCD).
|
void |
setCcdSweptSphereRadius(float radius)
Alter the radius of the swept sphere used for continuous collision
detection (CCD).
|
void |
setCollisionShape(CollisionShape collisionShape)
Apply the specified CollisionShape to this body.
|
void |
setContactResponse(boolean responsive)
Enable/disable this body's contact response.
|
void |
setDamping(float linearDamping,
float angularDamping)
Alter this body's damping.
|
void |
setFriction(float friction)
Alter this body's friction.
|
void |
setGravity(Vector3f gravity)
Alter this body's gravitational acceleration.
|
void |
setInverseInertiaLocal(Vector3f gravity)
Alter the principal components of the local inertia tensor.
|
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 linearSleepingThreshold)
Alter this body's linear sleeping threshold.
|
void |
setLinearVelocity(Vector3f vec)
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 alter the location of this body's center of mass.
|
void |
setPhysicsRotation(Matrix3f rotation)
Directly alter this body's orientation.
|
void |
setPhysicsRotation(Quaternion rotation)
Directly alter this body's orientation.
|
void |
setRestitution(float restitution)
Alter this body's restitution (bounciness).
|
void |
setSleepingThresholds(float linear,
float angular)
Alter this body's sleeping thresholds.
|
void |
write(JmeExporter e)
Serialize this body, for example when saving to a J3O file.
|
addCollideWithGroup, attachCollisionShape, finalize, finalizeNative, getCollideWithGroups, getCollisionFlags, getCollisionGroup, getCollisionShape, getDeactivationTime, getObjectId, getUserObject, initUserPointer, isContactResponse, removeCollideWithGroup, setCollideWithGroups, setCollisionFlags, setCollisionGroup, setUserObject
protected RigidBodyMotionState motionState
protected float mass
protected boolean kinematic
protected java.util.ArrayList<PhysicsJoint> joints
protected PhysicsRigidBody()
public PhysicsRigidBody(CollisionShape shape)
shape
- the desired shape (not null, alias created)public PhysicsRigidBody(CollisionShape shape, float mass)
shape
- the desired shape (not null, alias created)mass
- if 0, a static body is created; otherwise a dynamic body is
created (≥0)protected void rebuildRigidBody()
protected void preRebuild()
protected void postRebuild()
public RigidBodyMotionState getMotionState()
public boolean isInWorld()
public void setPhysicsLocation(Vector3f location)
location
- the desired location (not null, unaffected)public void setPhysicsRotation(Matrix3f rotation)
rotation
- the desired orientation (rotation matrix, not null,
unaffected)public void setPhysicsRotation(Quaternion rotation)
rotation
- the desired orientation (quaternion, in physics-space
coordinates, not null, unaffected)public Vector3f getPhysicsLocation(Vector3f trans)
trans
- storage for the result (modified if not null)public Quaternion getPhysicsRotation(Quaternion rot)
rot
- storage for the result (modified if not null)public void setInverseInertiaLocal(Vector3f gravity)
gravity
- (not null, unaffected)public Vector3f getInverseInertiaLocal(Vector3f trans)
trans
- storage for the result (modified if not null)public Matrix3f getPhysicsRotationMatrix(Matrix3f rot)
rot
- storage for the result (modified if not null)public Vector3f getPhysicsLocation()
public Quaternion getPhysicsRotation()
public Matrix3f getPhysicsRotationMatrix()
public void setKinematic(boolean kinematic)
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.
kinematic
- true→set kinematic mode, false→set
dynamic/static mode (default=false)public boolean isKinematic()
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.
public void setContactResponse(boolean responsive)
responsive
- true to respond to contacts, false to ignore them
(default=true)public void setCcdSweptSphereRadius(float radius)
radius
- the desired radius (≥0, default=0)public void setCcdMotionThreshold(float threshold)
This addresses the issue of fast objects passing through other objects with no collision detected.
threshold
- the desired threshold velocity (>0) or zero to
disable CCD (default=0)public float getCcdSweptSphereRadius()
public float getCcdMotionThreshold()
public float getCcdSquareMotionThreshold()
public float getMass()
public void setMass(float mass)
mass
- the desired mass (>0) or 0 for a static body (default=1)public Vector3f getGravity()
public Vector3f getGravity(Vector3f gravity)
gravity
- storage for the result (modified if not null)public void setGravity(Vector3f gravity)
Invoke this after adding the body to a PhysicsSpace. Adding a body to a PhysicsSpace alters its gravity.
gravity
- the desired acceleration vector (not null, unaffected)public float getFriction()
public void setFriction(float friction)
friction
- the desired friction value (default=0.5)public void setDamping(float linearDamping, float angularDamping)
linearDamping
- the desired linear damping value (default=0)angularDamping
- the desired angular damping value (default=0)public void setLinearDamping(float linearDamping)
linearDamping
- the desired linear damping value (default=0)public void setAngularDamping(float angularDamping)
angularDamping
- the desired angular damping value (default=0)public float getLinearDamping()
public float getAngularDamping()
public float getRestitution()
public void setRestitution(float restitution)
restitution
- the desired value (default=0)public Vector3f getAngularVelocity()
public void getAngularVelocity(Vector3f vec)
vec
- storage for the result (in physics-space coordinates, not
null, modified)public void setAngularVelocity(Vector3f vec)
vec
- the desired angular velocity vector (not null, unaffected)public Vector3f getLinearVelocity()
public void getLinearVelocity(Vector3f vec)
vec
- storage for the result (in physics-space coordinates, not
null, modified)public void setLinearVelocity(Vector3f vec)
vec
- the desired velocity vector (not null)public void applyForce(Vector3f force, Vector3f location)
To apply an impulse, use applyImpulse, use applyContinuousForce to apply continuous force.
force
- the force (not null, unaffected)location
- the location of the forcepublic void applyCentralForce(Vector3f force)
To apply an impulse, use
applyImpulse(com.jme3.math.Vector3f, com.jme3.math.Vector3f)
.
force
- the force (not null, unaffected)public void applyTorque(Vector3f torque)
To apply an impulse, use
applyImpulse(com.jme3.math.Vector3f, com.jme3.math.Vector3f)
.
torque
- the torque (not null, unaffected)public void applyImpulse(Vector3f impulse, Vector3f rel_pos)
impulse
- applied impulse (not null, unaffected)rel_pos
- location relative to object (not null, unaffected)public void applyTorqueImpulse(Vector3f vec)
vec
- the torque to applypublic void clearForces()
public void setCollisionShape(CollisionShape collisionShape)
Note that the body should not be in any physics space while changing shape; the body gets rebuilt on the physics side.
setCollisionShape
in class PhysicsCollisionObject
collisionShape
- the shape to apply (not null, alias created)public void activate()
public boolean isActive()
public void setSleepingThresholds(float linear, float angular)
These thresholds determine when the body can be deactivated to save resources. Low values keep the body active when it barely moves.
linear
- the desired linear sleeping threshold (≥0, default=0.8)angular
- the desired angular sleeping threshold (≥0, default=1)public void setLinearSleepingThreshold(float linearSleepingThreshold)
linearSleepingThreshold
- the desired threshold (≥0, default=0.8)public void setAngularSleepingThreshold(float angularSleepingThreshold)
angularSleepingThreshold
- the desired threshold (≥0, default=1)public float getLinearSleepingThreshold()
public float getAngularSleepingThreshold()
public float getAngularFactor()
public Vector3f getAngularFactor(Vector3f store)
store
- storage for the result (modified if not null)public void setAngularFactor(float factor)
factor
- the desired angular factor for all axes (not null,
unaffected, default=1)public void setAngularFactor(Vector3f factor)
factor
- the desired angular factor for each axis (not null,
unaffected, default=(1,1,1))public Vector3f getLinearFactor()
public void setLinearFactor(Vector3f factor)
factor
- the desired linear factor for each axis (not null,
unaffected, default=(1,1,1))public void addJoint(PhysicsJoint joint)
joint
- the joint to add (not null)public void removeJoint(PhysicsJoint joint)
joint
- the joint to remove (not null)public java.util.List<PhysicsJoint> getJoints()
This list is only filled when the PhysicsRigidBody is added to a physics space.
public void write(JmeExporter e) throws java.io.IOException
write
in interface Savable
write
in class PhysicsCollisionObject
e
- exporter (not null)java.io.IOException
- from exporterpublic void read(JmeImporter e) throws java.io.IOException
read
in interface Savable
read
in class PhysicsCollisionObject
e
- importer (not null)java.io.IOException
- from importer