Class PhysicsRigidBody

java.lang.Object
com.jme3.bullet.collision.PhysicsCollisionObject
com.jme3.bullet.objects.PhysicsRigidBody
All Implemented Interfaces:
Savable
Direct Known Subclasses:
PhysicsVehicle, RigidBodyControl

public class PhysicsRigidBody extends PhysicsCollisionObject

PhysicsRigidBody - Basic physics object

  • Field Details Link icon

    • constructionInfo Link icon

      protected com.bulletphysics.dynamics.RigidBodyConstructionInfo constructionInfo
    • rBody Link icon

      protected com.bulletphysics.dynamics.RigidBody rBody
    • motionState Link icon

      protected RigidBodyMotionState motionState
    • mass Link icon

      protected float mass
    • kinematic Link icon

      protected boolean kinematic
    • tempVec Link icon

      protected javax.vecmath.Vector3f tempVec
    • tempVec2 Link icon

      protected javax.vecmath.Vector3f tempVec2
    • tempTrans Link icon

      protected com.bulletphysics.linearmath.Transform tempTrans
    • tempMatrix Link icon

      protected javax.vecmath.Matrix3f tempMatrix
    • localInertia Link icon

      protected javax.vecmath.Vector3f localInertia
    • joints Link icon

      protected ArrayList<PhysicsJoint> joints
  • Constructor Details Link icon

    • PhysicsRigidBody Link icon

      protected PhysicsRigidBody()
    • PhysicsRigidBody Link icon

      public PhysicsRigidBody(CollisionShape shape)
      Creates a new PhysicsRigidBody with the supplied collision shape
      Parameters:
      shape - the desired shape (not null, alias created)
    • PhysicsRigidBody Link icon

      public PhysicsRigidBody(CollisionShape shape, float mass)
  • Method Details Link icon

    • rebuildRigidBody Link icon

      protected void rebuildRigidBody()
      Builds/rebuilds the physics body when parameters have changed
    • preRebuild Link icon

      protected void preRebuild()
    • postRebuild Link icon

      protected void postRebuild()
    • getMotionState Link icon

      public RigidBodyMotionState getMotionState()
      Returns:
      the motionState
    • setPhysicsLocation Link icon

      public void setPhysicsLocation(Vector3f location)
      Sets the physics object location
      Parameters:
      location - the location of the actual physics object
    • setPhysicsRotation Link icon

      public void setPhysicsRotation(Matrix3f rotation)
      Sets the physics object rotation
      Parameters:
      rotation - the rotation of the actual physics object
    • setPhysicsRotation Link icon

      public void setPhysicsRotation(Quaternion rotation)
      Sets the physics object rotation
      Parameters:
      rotation - the rotation of the actual physics object
    • getPhysicsLocation Link icon

      public Vector3f getPhysicsLocation()
      Gets the physics object location, instantiates a new Vector3f object
      Returns:
      a new location vector (in physics-space coordinates, not null)
    • getPhysicsRotationMatrix Link icon

      public Matrix3f getPhysicsRotationMatrix()
      Gets the physics object rotation
      Returns:
      a new rotation matrix (in physics-space coordinates, not null)
    • getPhysicsLocation Link icon

      public Vector3f getPhysicsLocation(Vector3f location)
      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 Link icon

      public Matrix3f getPhysicsRotationMatrix(Matrix3f rotation)
      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 Link icon

      public Quaternion 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 Link icon

      public Quaternion getPhysicsRotation(Quaternion rotation)
      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 Link icon

      public Vector3f getInterpolatedPhysicsLocation(Vector3f location)
      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 Link icon

      public Matrix3f getInterpolatedPhysicsRotation(Matrix3f rotation)
      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 Link icon

      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 Link icon

      public boolean isKinematic()
    • setContactResponse Link icon

      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 Link icon

      public boolean isContactResponse()
      Test whether this body responds to contacts.
      Returns:
      true if responsive, otherwise false
    • setCcdSweptSphereRadius Link icon

      public void setCcdSweptSphereRadius(float radius)
    • setCcdMotionThreshold Link icon

      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 Link icon

      public float getCcdSweptSphereRadius()
    • getCcdMotionThreshold Link icon

      public float getCcdMotionThreshold()
    • getCcdSquareMotionThreshold Link icon

      public float getCcdSquareMotionThreshold()
    • getMass Link icon

      public float getMass()
    • setMass Link icon

      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 Link icon

      public Vector3f getGravity()
    • getGravity Link icon

      public Vector3f getGravity(Vector3f gravity)
    • setGravity Link icon

      public void 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.
      Parameters:
      gravity - the gravity vector to set
    • getFriction Link icon

      public float getFriction()
    • setFriction Link icon

      public void setFriction(float friction)
      Sets the friction of this physics object
      Parameters:
      friction - the friction of this physics object
    • setDamping Link icon

      public void setDamping(float linearDamping, float angularDamping)
    • setLinearDamping Link icon

      public void setLinearDamping(float linearDamping)
    • setAngularDamping Link icon

      public void setAngularDamping(float angularDamping)
    • getLinearDamping Link icon

      public float getLinearDamping()
    • getAngularDamping Link icon

      public float getAngularDamping()
    • getRestitution Link icon

      public float getRestitution()
    • setRestitution Link icon

      public void setRestitution(float restitution)
      The "bounciness" of the PhysicsRigidBody. Best performance with restitution=0.
      Parameters:
      restitution - the desired value (default=0)
    • getAngularVelocity Link icon

      public Vector3f getAngularVelocity()
      Get the current angular velocity of this PhysicsRigidBody
      Returns:
      the current linear velocity
    • getAngularVelocity Link icon

      public void getAngularVelocity(Vector3f vec)
      Get the current angular velocity of this PhysicsRigidBody
      Parameters:
      vec - the vector to store the velocity in
    • setAngularVelocity Link icon

      public void setAngularVelocity(Vector3f vec)
      Sets the angular velocity of this PhysicsRigidBody
      Parameters:
      vec - the angular velocity of this PhysicsRigidBody
    • getLinearVelocity Link icon

      public Vector3f getLinearVelocity()
      Get the current linear velocity of this PhysicsRigidBody
      Returns:
      the current linear velocity
    • getLinearVelocity Link icon

      public void getLinearVelocity(Vector3f vec)
      Get the current linear velocity of this PhysicsRigidBody
      Parameters:
      vec - the vector to store the velocity in
    • setLinearVelocity Link icon

      public void setLinearVelocity(Vector3f vec)
      Sets the linear velocity of this PhysicsRigidBody
      Parameters:
      vec - the linear velocity of this PhysicsRigidBody
    • applyForce Link icon

      public 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.
      Parameters:
      force - the force
      location - the location of the force
    • applyCentralForce Link icon

      public void 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.
      Parameters:
      force - the force
    • applyTorque Link icon

      public 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.
      Parameters:
      torque - the torque
    • applyImpulse Link icon

      public void applyImpulse(Vector3f impulse, Vector3f relativePosition)
      Apply an impulse to the PhysicsRigidBody in the next physics update.
      Parameters:
      impulse - applied impulse
      relativePosition - location relative to object
    • applyTorqueImpulse Link icon

      public void applyTorqueImpulse(Vector3f vec)
      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 Link icon

      public void clearForces()
      Clear all forces from the PhysicsRigidBody
    • setCollisionShape Link icon

      public void setCollisionShape(CollisionShape collisionShape)
      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 class PhysicsCollisionObject
      Parameters:
      collisionShape - the CollisionShape to set
    • activate Link icon

      public void activate()
      reactivates this PhysicsRigidBody when it has been deactivated because it was not moving
    • isActive Link icon

      public boolean isActive()
    • setSleepingThresholds Link icon

      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 threshold
      angular - the angular sleeping threshold
    • setLinearSleepingThreshold Link icon

      public void setLinearSleepingThreshold(float linearSleepingThreshold)
    • setAngularSleepingThreshold Link icon

      public void setAngularSleepingThreshold(float angularSleepingThreshold)
    • getLinearSleepingThreshold Link icon

      public float getLinearSleepingThreshold()
    • getAngularSleepingThreshold Link icon

      public float getAngularSleepingThreshold()
    • getAngularFactor Link icon

      public float getAngularFactor()
    • setAngularFactor Link icon

      public void setAngularFactor(float factor)
    • addJoint Link icon

      public void addJoint(PhysicsJoint joint)
      do not use manually, joints are added automatically
      Parameters:
      joint - the joint to add (not null, alias created)
    • removeJoint Link icon

      public void removeJoint(PhysicsJoint joint)
      Parameters:
      joint - the joint to remove (not null, unaffected)
    • getJoints Link icon

      public List<PhysicsJoint> 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 Link icon

      public com.bulletphysics.dynamics.RigidBody getObjectId()
      used internally
      Returns:
      the pre-existing object
    • destroy Link icon

      public void destroy()
      destroys this PhysicsRigidBody and removes it from memory
    • write Link icon

      public void write(JmeExporter e) throws IOException
      Serialize this body, for example when saving to a J3O file.
      Specified by:
      write in interface Savable
      Overrides:
      write in class PhysicsCollisionObject
      Parameters:
      e - exporter (not null)
      Throws:
      IOException - from exporter
    • read Link icon

      public void read(JmeImporter importer) throws IOException
      De-serialize this body, for example when loading from a J3O file.
      Specified by:
      read in interface Savable
      Overrides:
      read in class PhysicsCollisionObject
      Parameters:
      importer - importer (not null)
      Throws:
      IOException - from importer