Package com.jme3.bullet.objects
Class PhysicsRigidBody
java.lang.Object
com.jme3.bullet.collision.PhysicsCollisionObject
com.jme3.bullet.objects.PhysicsRigidBody
- All Implemented Interfaces:
Savable
- Direct Known Subclasses:
PhysicsVehicle
,RigidBodyControl
PhysicsRigidBody - Basic physics object
-
Field Summary
Modifier and TypeFieldDescriptionprotected com.bulletphysics.dynamics.RigidBodyConstructionInfo
protected ArrayList<PhysicsJoint>
protected boolean
protected javax.vecmath.Vector3f
protected float
protected RigidBodyMotionState
protected com.bulletphysics.dynamics.RigidBody
protected javax.vecmath.Matrix3f
protected com.bulletphysics.linearmath.Transform
protected javax.vecmath.Vector3f
protected javax.vecmath.Vector3f
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
PhysicsRigidBody
(CollisionShape shape) Creates a new PhysicsRigidBody with the supplied collision shapePhysicsRigidBody
(CollisionShape shape, float mass) -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
reactivates this PhysicsRigidBody when it has been deactivated because it was not movingvoid
addJoint
(PhysicsJoint joint) do not use manually, joints are added automaticallyvoid
applyCentralForce
(Vector3f force) Apply a force to the PhysicsRigidBody, only applies force if the next physics update call updates the physics space.
To apply an impulse, use applyImpulse.void
applyForce
(Vector3f force, Vector3f location) Apply a force to the PhysicsRigidBody, only applies force if the next physics update call updates the physics space.
To apply an impulse, use applyImpulse, use applyContinuousForce to apply continuous force.void
applyImpulse
(Vector3f impulse, Vector3f relativePosition) Apply an impulse to the PhysicsRigidBody in the next physics update.void
applyTorque
(Vector3f torque) Apply a force to the PhysicsRigidBody, only applies force if the next physics update call updates the physics space.
To apply an impulse, use applyImpulse.void
Apply a torque impulse to the PhysicsRigidBody in the next physics update.void
Clear all forces from the PhysicsRigidBodyvoid
destroy()
destroys this PhysicsRigidBody and removes it from memoryfloat
float
float
Get the current angular velocity of this PhysicsRigidBodyvoid
Get the current angular velocity of this PhysicsRigidBodyfloat
float
float
float
getGravity
(Vector3f gravity) getInterpolatedPhysicsLocation
(Vector3f location) Gets the physics object locationgetInterpolatedPhysicsRotation
(Matrix3f rotation) Gets the physics object rotationReturns a list of connected joints.float
float
Get the current linear velocity of this PhysicsRigidBodyvoid
Get the current linear velocity of this PhysicsRigidBodyfloat
getMass()
com.bulletphysics.dynamics.RigidBody
used internallyGets the physics object location, instantiates a new Vector3f objectgetPhysicsLocation
(Vector3f location) Gets the physics object location, no object instantiationGets the physics object rotation as a quaternion, converts the bullet Matrix3f value, instantiates new objectgetPhysicsRotation
(Quaternion rotation) Gets the physics object rotation as a quaternion, converts the bullet Matrix3f valueGets the physics object rotationgetPhysicsRotationMatrix
(Matrix3f rotation) Gets the physics object rotation as a matrix, no conversions and no object instantiationfloat
boolean
isActive()
boolean
Test whether this body responds to contacts.boolean
protected void
protected void
void
read
(JmeImporter importer) De-serialize this body, for example when loading from a J3O file.protected void
Builds/rebuilds the physics body when parameters have changedvoid
removeJoint
(PhysicsJoint joint) void
setAngularDamping
(float angularDamping) void
setAngularFactor
(float factor) void
setAngularSleepingThreshold
(float angularSleepingThreshold) void
Sets the angular velocity of this PhysicsRigidBodyvoid
setCcdMotionThreshold
(float threshold) Sets the amount of motion that has to happen in one physics tick to trigger the continuous motion detection
This avoids the problem of fast objects moving through other objects, set to zero to disable (default)void
setCcdSweptSphereRadius
(float radius) void
setCollisionShape
(CollisionShape collisionShape) Sets a CollisionShape to this physics object, note that the object should not be in the physics space when adding a new collision shape as it is rebuilt on the physics side.void
setContactResponse
(boolean responsive) Enable/disable this body's contact response.void
setDamping
(float linearDamping, float angularDamping) void
setFriction
(float friction) Sets the friction of this physics objectvoid
setGravity
(Vector3f gravity) Set the local gravity of this PhysicsRigidBody
Set this after adding the node to the PhysicsSpace, the PhysicsSpace assigns its current gravity to the physics node when it's added.void
setKinematic
(boolean kinematic) Sets the node to kinematic mode.void
setLinearDamping
(float linearDamping) void
setLinearSleepingThreshold
(float linearSleepingThreshold) void
Sets the linear velocity of this PhysicsRigidBodyvoid
setMass
(float mass) Sets the mass of this PhysicsRigidBody, objects with mass=0 are static.void
setPhysicsLocation
(Vector3f location) Sets the physics object locationvoid
setPhysicsRotation
(Matrix3f rotation) Sets the physics object rotationvoid
setPhysicsRotation
(Quaternion rotation) Sets the physics object rotationvoid
setRestitution
(float restitution) The "bounciness" of the PhysicsRigidBody.void
setSleepingThresholds
(float linear, float angular) sets the sleeping thresholds, these define when the object gets deactivated to save resources.void
write
(JmeExporter e) Serialize this body, for example when saving to a J3O file.Methods inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
addCollideWithGroup, getCollideWithGroups, getCollisionGroup, getCollisionShape, getUserObject, removeCollideWithGroup, setCollideWithGroups, setCollisionGroup, setUserObject
-
Field Details
-
constructionInfo
protected com.bulletphysics.dynamics.RigidBodyConstructionInfo constructionInfo -
rBody
protected com.bulletphysics.dynamics.RigidBody rBody -
motionState
-
mass
protected float mass -
kinematic
protected boolean kinematic -
tempVec
protected javax.vecmath.Vector3f tempVec -
tempVec2
protected javax.vecmath.Vector3f tempVec2 -
tempTrans
protected com.bulletphysics.linearmath.Transform tempTrans -
tempMatrix
protected javax.vecmath.Matrix3f tempMatrix -
localInertia
protected javax.vecmath.Vector3f localInertia -
joints
-
-
Constructor Details
-
PhysicsRigidBody
protected PhysicsRigidBody() -
PhysicsRigidBody
Creates a new PhysicsRigidBody with the supplied collision shape- Parameters:
shape
- the desired shape (not null, alias created)
-
PhysicsRigidBody
-
-
Method Details
-
rebuildRigidBody
protected void rebuildRigidBody()Builds/rebuilds the physics body when parameters have changed -
preRebuild
protected void preRebuild() -
postRebuild
protected void postRebuild() -
getMotionState
- Returns:
- the motionState
-
setPhysicsLocation
Sets the physics object location- Parameters:
location
- the location of the actual physics object
-
setPhysicsRotation
Sets the physics object rotation- Parameters:
rotation
- the rotation of the actual physics object
-
setPhysicsRotation
Sets the physics object rotation- Parameters:
rotation
- the rotation of the actual physics object
-
getPhysicsLocation
Gets the physics object location, instantiates a new Vector3f object- Returns:
- a new location vector (in physics-space coordinates, not null)
-
getPhysicsRotationMatrix
Gets the physics object rotation- Returns:
- a new rotation matrix (in physics-space coordinates, not null)
-
getPhysicsLocation
Gets the physics object location, no object instantiation- Parameters:
location
- the location of the actual physics object is stored in this Vector3f- Returns:
- a location vector (in physics-space coordinates, either location or a new vector)
-
getPhysicsRotationMatrix
Gets the physics object rotation as a matrix, no conversions and no object instantiation- Parameters:
rotation
- the rotation of the actual physics object is stored in this Matrix3f- Returns:
- a rotation matrix (in physics-space coordinates, either rotation or a new matrix)
-
getPhysicsRotation
Gets the physics object rotation as a quaternion, converts the bullet Matrix3f value, instantiates new object- Returns:
- a new rotation Quaternion (in physics-space coordinates)
-
getPhysicsRotation
Gets the physics object rotation as a quaternion, converts the bullet Matrix3f value- Parameters:
rotation
- the rotation of the actual physics object is stored in this Quaternion- Returns:
- a rotation Quaternion (in physics-space coordinates, either rotation or a new instance)
-
getInterpolatedPhysicsLocation
Gets the physics object location- Parameters:
location
- the location of the actual physics object is stored in this Vector3f- Returns:
- a location vector (in physics-space coordinates, either location or a new vector)
-
getInterpolatedPhysicsRotation
Gets the physics object rotation- Parameters:
rotation
- the rotation of the actual physics object is stored in this Matrix3f- Returns:
- a rotation matrix (in physics-space coordinates, either rotation or a new matrix)
-
setKinematic
public void setKinematic(boolean kinematic) Sets the node to kinematic mode. in this mode the node is not affected by physics but affects other physics objects. Its kinetic force is calculated by the amount of movement it is exposed to and its weight.- Parameters:
kinematic
- true→set kinematic mode, false→set dynamic (default=false)
-
isKinematic
public boolean isKinematic() -
setContactResponse
public void setContactResponse(boolean responsive) Enable/disable this body's contact response.- Parameters:
responsive
- true to respond to contacts, false to ignore them (default=true)
-
isContactResponse
public boolean isContactResponse()Test whether this body responds to contacts.- Returns:
- true if responsive, otherwise false
-
setCcdSweptSphereRadius
public void setCcdSweptSphereRadius(float radius) -
setCcdMotionThreshold
public void setCcdMotionThreshold(float threshold) Sets the amount of motion that has to happen in one physics tick to trigger the continuous motion detection
This avoids the problem of fast objects moving through other objects, set to zero to disable (default)- Parameters:
threshold
- the desired minimum distance per timestep to trigger CCD (in physics-space units, >0) or zero to disable CCD (default=0)
-
getCcdSweptSphereRadius
public float getCcdSweptSphereRadius() -
getCcdMotionThreshold
public float getCcdMotionThreshold() -
getCcdSquareMotionThreshold
public float getCcdSquareMotionThreshold() -
getMass
public float getMass() -
setMass
public void setMass(float mass) Sets the mass of this PhysicsRigidBody, objects with mass=0 are static.- Parameters:
mass
- the desired mass (>0) or 0 for a static body (default=1)
-
getGravity
-
getGravity
-
setGravity
Set the local gravity of this PhysicsRigidBody
Set this after adding the node to the PhysicsSpace, the PhysicsSpace assigns its current gravity to the physics node when it's added.- Parameters:
gravity
- the gravity vector to set
-
getFriction
public float getFriction() -
setFriction
public void setFriction(float friction) Sets the friction of this physics object- Parameters:
friction
- the friction of this physics object
-
setDamping
public void setDamping(float linearDamping, float angularDamping) -
setLinearDamping
public void setLinearDamping(float linearDamping) -
setAngularDamping
public void setAngularDamping(float angularDamping) -
getLinearDamping
public float getLinearDamping() -
getAngularDamping
public float getAngularDamping() -
getRestitution
public float getRestitution() -
setRestitution
public void setRestitution(float restitution) The "bounciness" of the PhysicsRigidBody. Best performance with restitution=0.- Parameters:
restitution
- the desired value (default=0)
-
getAngularVelocity
Get the current angular velocity of this PhysicsRigidBody- Returns:
- the current linear velocity
-
getAngularVelocity
Get the current angular velocity of this PhysicsRigidBody- Parameters:
vec
- the vector to store the velocity in
-
setAngularVelocity
Sets the angular velocity of this PhysicsRigidBody- Parameters:
vec
- the angular velocity of this PhysicsRigidBody
-
getLinearVelocity
Get the current linear velocity of this PhysicsRigidBody- Returns:
- the current linear velocity
-
getLinearVelocity
Get the current linear velocity of this PhysicsRigidBody- Parameters:
vec
- the vector to store the velocity in
-
setLinearVelocity
Sets the linear velocity of this PhysicsRigidBody- Parameters:
vec
- the linear velocity of this PhysicsRigidBody
-
applyForce
Apply a force to the PhysicsRigidBody, only applies force if the next physics update call updates the physics space.
To apply an impulse, use applyImpulse, use applyContinuousForce to apply continuous force.- Parameters:
force
- the forcelocation
- the location of the force
-
applyCentralForce
Apply a force to the PhysicsRigidBody, only applies force if the next physics update call updates the physics space.
To apply an impulse, use applyImpulse.- Parameters:
force
- the force
-
applyTorque
Apply a force to the PhysicsRigidBody, only applies force if the next physics update call updates the physics space.
To apply an impulse, use applyImpulse.- Parameters:
torque
- the torque
-
applyImpulse
Apply an impulse to the PhysicsRigidBody in the next physics update.- Parameters:
impulse
- applied impulserelativePosition
- location relative to object
-
applyTorqueImpulse
Apply a torque impulse to the PhysicsRigidBody in the next physics update.- Parameters:
vec
- the torque impulse vector (in physics-space coordinates, not null, unaffected)
-
clearForces
public void clearForces()Clear all forces from the PhysicsRigidBody -
setCollisionShape
Description copied from class:PhysicsCollisionObject
Sets a CollisionShape to this physics object, note that the object should not be in the physics space when adding a new collision shape as it is rebuilt on the physics side.- Overrides:
setCollisionShape
in classPhysicsCollisionObject
- Parameters:
collisionShape
- the CollisionShape to set
-
activate
public void activate()reactivates this PhysicsRigidBody when it has been deactivated because it was not moving -
isActive
public boolean isActive() -
setSleepingThresholds
public void setSleepingThresholds(float linear, float angular) sets the sleeping thresholds, these define when the object gets deactivated to save resources. Low values keep the object active when it barely moves- Parameters:
linear
- the linear sleeping thresholdangular
- the angular sleeping threshold
-
setLinearSleepingThreshold
public void setLinearSleepingThreshold(float linearSleepingThreshold) -
setAngularSleepingThreshold
public void setAngularSleepingThreshold(float angularSleepingThreshold) -
getLinearSleepingThreshold
public float getLinearSleepingThreshold() -
getAngularSleepingThreshold
public float getAngularSleepingThreshold() -
getAngularFactor
public float getAngularFactor() -
setAngularFactor
public void setAngularFactor(float factor) -
addJoint
do not use manually, joints are added automatically- Parameters:
joint
- the joint to add (not null, alias created)
-
removeJoint
- Parameters:
joint
- the joint to remove (not null, unaffected)
-
getJoints
Returns a list of connected joints. This list is only filled when the PhysicsRigidBody is actually added to the physics space or loaded from disk.- Returns:
- list of active joints connected to this PhysicsRigidBody
-
getObjectId
public com.bulletphysics.dynamics.RigidBody getObjectId()used internally- Returns:
- the pre-existing object
-
destroy
public void destroy()destroys this PhysicsRigidBody and removes it from memory -
write
Serialize this body, for example when saving to a J3O file.- Specified by:
write
in interfaceSavable
- Overrides:
write
in classPhysicsCollisionObject
- Parameters:
e
- exporter (not null)- Throws:
IOException
- from exporter
-
read
De-serialize this body, for example when loading from a J3O file.- Specified by:
read
in interfaceSavable
- Overrides:
read
in classPhysicsCollisionObject
- Parameters:
importer
- importer (not null)- Throws:
IOException
- from importer
-