Class PhysicsCollisionObject

java.lang.Object
com.jme3.bullet.NativePhysicsObject
com.jme3.bullet.collision.PhysicsCollisionObject
All Implemented Interfaces:
Comparable<NativePhysicsObject>
Direct Known Subclasses:
MultiBodyCollider, PhysicsBody, PhysicsCharacter, PhysicsGhostObject

public abstract class PhysicsCollisionObject extends NativePhysicsObject
The abstract base class for collision objects based on Bullet's btCollisionObject.

Subclasses include MultiBodyCollider, PhysicsBody, PhysicsCharacter, and PhysicsGhostObject.

  • Field Details

    • COLLISION_GROUP_NONE

      public static final int COLLISION_GROUP_NONE
      collideWithGroups bitmask that represents "no groups"
      See Also:
    • COLLISION_GROUP_01

      public static final int COLLISION_GROUP_01
      collisionGroup/collideWithGroups bitmask that represents group #1
      See Also:
    • COLLISION_GROUP_02

      public static final int COLLISION_GROUP_02
      collisionGroup/collideWithGroups bitmask that represents group #2
      See Also:
    • COLLISION_GROUP_03

      public static final int COLLISION_GROUP_03
      collisionGroup/collideWithGroups bitmask that represents group #3
      See Also:
    • COLLISION_GROUP_04

      public static final int COLLISION_GROUP_04
      collisionGroup/collideWithGroups bitmask that represents group #4
      See Also:
    • COLLISION_GROUP_05

      public static final int COLLISION_GROUP_05
      collisionGroup/collideWithGroups bitmask that represents group #5
      See Also:
    • COLLISION_GROUP_06

      public static final int COLLISION_GROUP_06
      collisionGroup/collideWithGroups bitmask that represents group #6
      See Also:
    • COLLISION_GROUP_07

      public static final int COLLISION_GROUP_07
      collisionGroup/collideWithGroups bitmask that represents group #7
      See Also:
    • COLLISION_GROUP_08

      public static final int COLLISION_GROUP_08
      collisionGroup/collideWithGroups bitmask that represents group #8
      See Also:
    • COLLISION_GROUP_09

      public static final int COLLISION_GROUP_09
      collisionGroup/collideWithGroups bitmask that represents group #9
      See Also:
    • COLLISION_GROUP_10

      public static final int COLLISION_GROUP_10
      collisionGroup/collideWithGroups bitmask that represents group #10
      See Also:
    • COLLISION_GROUP_11

      public static final int COLLISION_GROUP_11
      collisionGroup/collideWithGroups bitmask that represents group #11
      See Also:
    • COLLISION_GROUP_12

      public static final int COLLISION_GROUP_12
      collisionGroup/collideWithGroups bitmask that represents group #12
      See Also:
    • COLLISION_GROUP_13

      public static final int COLLISION_GROUP_13
      collisionGroup/collideWithGroups bitmask that represents group #13
      See Also:
    • COLLISION_GROUP_14

      public static final int COLLISION_GROUP_14
      collisionGroup/collideWithGroups bitmask that represents group #14
      See Also:
    • COLLISION_GROUP_15

      public static final int COLLISION_GROUP_15
      collisionGroup/collideWithGroups bitmask that represents group #15
      See Also:
    • COLLISION_GROUP_16

      public static final int COLLISION_GROUP_16
      collisionGroup/collideWithGroups bitmask that represents group #16
      See Also:
    • logger

      public static final Logger logger
      message logger for this class
  • Constructor Details

    • PhysicsCollisionObject

      protected PhysicsCollisionObject()
      Instantiate a collision object with no tracker and no assigned native object.

      This no-arg constructor was made explicit to avoid javadoc warnings from JDK 18+.

  • Method Details

    • activate

      public void activate(boolean forceFlag)
      Reactivate the collision object if it has been deactivated due to lack of motion.

      Deactivation doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      forceFlag - true to force activation
    • addCollideWithGroup

      public void addCollideWithGroup(int collisionGroup)
      Add collision groups to the set with which this object can collide.

      Two objects can collide only if one of them has the collisionGroup of the other in its collideWithGroups set.

      Parameters:
      collisionGroup - the groups to add, ORed together (bitmask)
    • addToIgnoreList

      public void addToIgnoreList(PhysicsCollisionObject otherPco)
      Add another collision object to this object's ignore list and vice versa.

      Any collisions with objects on the list will be ignored. However, the wheels of a PhysicsVehicle aren't collision objects, so the vehicle's ignore list doesn't affect them.

      Parameters:
      otherPco - the other collision object (not null, not this, modified)
    • boundingBox

      public BoundingBox boundingBox(BoundingBox storeResult)
      Calculate an axis-aligned bounding box for this object, based on its collision shape. Note: the calculated bounds are seldom minimal; they are typically larger than necessary due to centering constraints and collision margins.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a bounding box in physics-space coordinates (either storeResult or a new instance)
    • clearIgnoreList

      public void clearIgnoreList()
      Clear this object's ignore list.
    • collisionFlags

      public int collisionFlags()
      Return the collision flags. Flag values are defined in CollisionFlag.
      Returns:
      the values of all flags that are set, ORed together
    • copyPcoProperties

      public final void copyPcoProperties(PhysicsCollisionObject old)
      Copy common properties from another collision object.
      Parameters:
      old - the instance to copy from (not null, unaffected)
    • countIgnored

      public int countIgnored()
      Count the collision objects in this object's ignore list.
      Returns:
      the count (≥0)
      See Also:
    • findInstance

      public static PhysicsCollisionObject findInstance(long pcoId)
      Find the collision object with the specified ID. Native method.
      Parameters:
      pcoId - the native identifier (not zero)
      Returns:
      the pre-existing instance, or null if it's been reclaimed
    • getActivationState

      public int getActivationState()
      Return this object's activation state (native field: m_activationState1).

      Deactivation doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      the state (1=active tag, 2=island sleeping, 3=wants deactivation, 4=disable deactivation, 5=disable simulation)
      See Also:
    • getAnisotropicFriction

      public Vector3f getAnisotropicFriction(Vector3f storeResult)
      Copy this object's anisotropic friction components (native field: m_anisotropicFriction).

      Friction doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      the components of the friction (either storeResult or a new vector, not null)
    • getCcdMotionThreshold

      public float getCcdMotionThreshold()
      Return the continuous collision detection (CCD) motion threshold (native field: m_ccdMotionThreshold).

      CCD doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      the minimum distance per simulation step to trigger CCD (in physics-space units, ≥0)
    • getCcdSquareMotionThreshold

      public float getCcdSquareMotionThreshold()
      Return the squared motion threshold.

      CCD doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      the minimum distance squared (in physics-space units, ≥0)
    • getCcdSweptSphereRadius

      public float getCcdSweptSphereRadius()
      Return the radius of the sphere used for continuous collision detection (CCD) (native field: m_ccdSweptSphereRadius).

      CCD doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      the radius (in physics-space units, ≥0)
    • getCollideWithGroups

      public int getCollideWithGroups()
      Return the set of collision groups with which this object can collide.
      Returns:
      the bitmask
    • getCollisionGroup

      public int getCollisionGroup()
      Return the collision group of this object.
      Returns:
      the collision group (bitmask with exactly one bit set)
    • getCollisionShape

      public CollisionShape getCollisionShape()
      Access the shape of the collision object.
      Returns:
      the pre-existing instance, or null if none
    • getCollisionSpace

      public CollisionSpace getCollisionSpace()
      Access the space where the collision object is added.
      Returns:
      the pre-existing instance, or null if none
    • getContactDamping

      public float getContactDamping()
      Return the contact damping (native field: m_contactDamping).

      Contact damping doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      the damping
    • getContactProcessingThreshold

      public float getContactProcessingThreshold()
      Return the contact-processing threshold (native field: m_contactProcessingThreshold).

      Contact processing doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      the threshold distance (in physics-space units)
    • getContactStiffness

      public float getContactStiffness()
      Return the contact stiffness (native field: m_contactStiffness).

      Contact stiffness doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      the stiffness
    • getDeactivationTime

      public float getDeactivationTime()
      Return the deactivation time (native field: m_deactivationTime).

      Deactivation doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      the time (in seconds)
    • getFriction

      public float getFriction()
      Return the collision object's friction parameter (native field: m_friction).

      Friction doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      the parameter value (≥0)
    • getPhysicsLocation

      public Vector3f getPhysicsLocation(Vector3f storeResult)
      Locate the collision object's center.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a location vector (in physics-space coordinates, either storeResult or a new vector, finite)
    • getPhysicsLocationDp

      public Vec3d getPhysicsLocationDp(Vec3d storeResult)
      Locate the collision object's center in double precision.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a location vector (in physics-space coordinates, either storeResult or a new vector, not null, finite)
    • getPhysicsRotation

      public Quaternion getPhysicsRotation(Quaternion storeResult)
      Copy the orientation (rotation) of the collision object to a Quaternion.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a rotation Quaternion (in physics-space coordinates, either storeResult or a new instance, not null)
    • getPhysicsRotationDp

      public Quatd getPhysicsRotationDp(Quatd storeResult)
      Copy the orientation (rotation) of this object to a Quatd.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a rotation Quatd (in physics-space coordinates, either storeResult or a new instance, not null)
    • getPhysicsRotationMatrix

      public Matrix3f getPhysicsRotationMatrix(Matrix3f storeResult)
      Copy the orientation of the collision object (the basis of its local coordinate system) to a Matrix3f.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a rotation matrix (in physics-space coordinates, either storeResult or a new matrix, not null)
    • getPhysicsRotationMatrixDp

      public Matrix3d getPhysicsRotationMatrixDp(Matrix3d storeResult)
      Copy the orientation of the collision object (the basis of its local coordinate system) to a Matrix3d.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a rotation matrix (in physics-space coordinates, either storeResult or a new matrix, not null)
    • getRestitution

      public float getRestitution()
      Return the collision object's restitution (bounciness) (native field: m_restitution).

      Restitution doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      restitution value
    • getRollingFriction

      public float getRollingFriction()
      Return this object's rolling friction (native field: m_rollingFriction).

      Friction doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      friction value
    • getScale

      public Vector3f getScale(Vector3f storeResult)
      Copy the scale of this object.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      the scale factor for each local axis (either storeResult or a new vector, not null, no negative component)
    • getSpinningFriction

      public float getSpinningFriction()
      Return this object's spinning friction (native field: m_spinningFriction).

      Friction doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      friction value
    • getTransform

      public Transform getTransform(Transform storeResult)
      Copy the coordinate transform of this object, including the scale of its shape.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a coordinate transform (in physics-space coordinates, either storeResult or a new Transform, not null)
    • getTransformDp

      public TransformDp getTransformDp(TransformDp storeResult)
      Copy the coordinate transform of this object, including the scale of its shape.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a coordinate transform (in physics-space coordinates, either storeResult or a new Transform, not null)
    • getUserObject

      public Object getUserObject()
      Access the "user" of this collision object.
      Returns:
      the pre-existing instance, or null if none
      See Also:
    • hasAnisotropicFriction

      public boolean hasAnisotropicFriction(int mode)
      Test whether the collision object has anisotropic friction.

      Friction doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      mode - the mode(s) to test for: 1=basic anisotropic friction, 2=anisotropic rolling friction, 3=either one
      Returns:
      true if (one of) the specified mode(s) is active, otherwise false
    • ignores

      public boolean ignores(PhysicsCollisionObject other)
      Test whether the specified collision object is in the current collision object's ignore list.
      Parameters:
      other - the collision object to search for
      Returns:
      true if found, otherwise false
      See Also:
    • isActive

      public boolean isActive()
      Test whether the collision object has been deactivated due to lack of motion.

      Deactivation doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Returns:
      true if object still active, false if deactivated
    • isContactResponse

      public final boolean isContactResponse()
      Test whether the collision object responds to contact with other objects. All ghost objects are non-responsive. Other types are responsive by default.
      Returns:
      true if responsive, otherwise false
    • isInWorld

      public final boolean isInWorld()
      Test whether the collision object is added to a space.
      Returns:
      true→added to a space, false→not added to a space
    • isStatic

      public final boolean isStatic()
      Test whether the collision object is static (immobile).
      Returns:
      true if static, otherwise false
    • listIgnoredPcos

      public PhysicsCollisionObject[] listIgnoredPcos()
      Enumerate all collision objects in this object's ignore list.
      Returns:
      a new array (not null, may be empty)
      See Also:
    • proxyGroup

      public Integer proxyGroup()
      Return the collision group of the collision object's broadphase proxy. A proxy is created when the collision object is added to a space, and its group is 32 for a PhysicsCharacter, 2 for a static object, or 1 for anything else.
      Returns:
      the proxy's collision group (a bitmask with exactly one bit set) or null if this object has no proxy
    • proxyMask

      public Integer proxyMask()
      Return the collision mask of this object's broadphase proxy. A proxy is created when the collision object is added to a space, and its mask is -3 for a static object or -1 for anything else.
      Returns:
      the proxy's bitmask, or null if this object has no proxy
    • removeCollideWithGroup

      public void removeCollideWithGroup(int collisionGroup)
      Remove collision groups from the set with which this object can collide.
      Parameters:
      collisionGroup - the groups to remove, ORed together (bitmask)
    • removeFromIgnoreList

      public void removeFromIgnoreList(PhysicsCollisionObject otherPco)
      Remove a collision object from this object's ignore list and vice versa.
      Parameters:
      otherPco - the other collision object (not null, not this, modified)
    • setAnisotropicFriction

      public void setAnisotropicFriction(Vector3f components, int mode)
      Alter this object's anisotropic friction (native field: m_anisotropicFriction).

      Friction doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      components - the desired friction components (not null, unaffected, default=(1,1,1))
      mode - the desired friction mode: 0=isotropic, 1=basic anisotropic friction, 2=anisotropic rolling friction (default=0)
    • setCcdMotionThreshold

      public void setCcdMotionThreshold(float threshold)
      Alter the amount of motion required to trigger continuous collision detection (CCD) (native field: m_ccdMotionThreshold).

      CCD addresses the issue of fast-moving bodies passing through other bodies without creating any contacts.

      CCD doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      threshold - the desired minimum distance per simulation step to trigger CCD (in physics-space units, >0) or zero to disable CCD (default=0)
    • setCcdSweptSphereRadius

      public void setCcdSweptSphereRadius(float radius)
      Alter the continuous collision detection (CCD) swept-sphere radius for this object (native field: m_ccdSweptSphereRadius).

      CCD doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      radius - (in physics-space units, ≥0, default=0)
    • setCollideWithGroups

      public void setCollideWithGroups(int collisionGroups)
      Directly alter the collision groups with which this object can collide.
      Parameters:
      collisionGroups - the desired groups, ORed together (bitmask, default=COLLISION_GROUP_01)
    • setCollisionGroup

      public void setCollisionGroup(int collisionGroup)
      Alter which collision group this object belongs to.

      Groups are represented by bitmasks with exactly one bit set. Manifest constants are defined in PhysicsCollisionObject.

      Two objects can collide only if one of them has the collisionGroup of the other in its collideWithGroups set.

      Parameters:
      collisionGroup - the collisionGroup to apply (bitmask with exactly one bit set, default=COLLISION_GROUP_01)
    • setCollisionShape

      public void setCollisionShape(CollisionShape collisionShape)
      Apply the specified shape to the collision object. Meant to be overridden.
      Parameters:
      collisionShape - the shape to apply (not null, alias created)
    • setContactDamping

      public void setContactDamping(float damping)
      Alter the contact damping (native field: m_contactDamping). Also affects the collision flags.

      Contact damping doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      damping - the desired damping (default=0.1)
    • setContactProcessingThreshold

      public void setContactProcessingThreshold(float distance)
      Alter the contact-processing threshold (native field: m_contactProcessingThreshold).

      Contact processing doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      distance - the desired threshold distance (in physics-space units, default=1e18 with SP library or 1e30 with DP library)
    • setContactStiffness

      public void setContactStiffness(float stiffness)
      Alter the contact stiffness (native field: m_contactStiffness). Also affects the collision flags.

      Contact stiffness doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      stiffness - the desired stiffness (default=1e18 with SP library or 1e30 with DP library)
    • setDeactivationTime

      public void setDeactivationTime(float time)
      Alter the deactivation time (native field: m_deactivationTime).

      Deactivation doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      time - the desired time (in seconds, default=0)
    • setFriction

      public void setFriction(float friction)
      Alter the collision object's friction (native field: m_friction).

      Friction doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      friction - the desired friction value (≥0, default=0.5)
    • setIgnoreList

      public void setIgnoreList(PhysicsCollisionObject[] desiredList)
      Replace the ignore list.
      Parameters:
      desiredList - collision objects to ignore (not null, may be empty, may contain nulls or duplicates or this, unaffected)
    • setRestitution

      public void setRestitution(float restitution)
      Alter the collision object's restitution (bounciness) (native field: m_restitution). For perfect elasticity, set restitution=1.

      Restitution doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      restitution - the desired value (default=0)
    • setRollingFriction

      public void setRollingFriction(float friction)
      Alter this object's rolling friction: torsional friction orthogonal to the contact normal (native field: m_rollingFriction). Use this to stop bodies from rolling.

      Friction doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      friction - the desired friction value (default=0)
    • setSpinningFriction

      public void setSpinningFriction(float friction)
      Alter this object's spinning friction: torsional friction around the contact normal (native field: m_spinningFriction). Use for grasping.

      Friction doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      friction - the desired friction value (default=0)
    • setUserIndex

      public void setUserIndex(int index)
      Alter the collision object's primary user index. Applications may use this parameter for any purpose (native field: m_userIndex).
      Parameters:
      index - the desired value (default=-1)
    • setUserIndex2

      public void setUserIndex2(int index)
      Alter the collision object's secondary user index. Applications may use this parameter for any purpose (native field: m_userIndex2).
      Parameters:
      index - the desired value (default=-1)
    • setUserIndex3

      public void setUserIndex3(int index)
      Alter the collision object's tertiary user index. Applications may use this parameter for any purpose (native field: m_userIndex3).
      Parameters:
      index - the desired value (default=-1)
    • setUserObject

      public void setUserObject(Object user)
      Associate a "user" with the collision object.
      Parameters:
      user - the desired scene object (alias created, default=null)
      See Also:
    • spaceId

      public long spaceId()
      Return the ID of the space where the collision object is added.
      Returns:
      the ID, or zero if not added to any space
    • userIndex

      public int userIndex()
      Return the collision object's primary user index (native field: m_userIndex).
      Returns:
      the value of the index
    • userIndex2

      public int userIndex2()
      Return the collision object's secondary user index (native field: m_userIndex2).
      Returns:
      the value of the index
    • userIndex3

      public int userIndex3()
      Return the collision object's tertiary user index (native field: m_userIndex3).
      Returns:
      the value of the index
    • attachCollisionShape

      protected static void attachCollisionShape(long objectId, long collisionShapeId)
      Attach the identified btCollisionShape to the identified btCollisionObject. Native method.
      Parameters:
      objectId - the identifier of the btCollisionObject (not zero)
      collisionShapeId - the identifier of the btCollisionShape (not zero)
    • finalizeNative

      protected static void finalizeNative(long objectId)
      Finalize the identified btCollisionObject. Native method.
      Parameters:
      objectId - the ID of the btCollisionObject (not zero)
    • getInternalType

      protected static final int getInternalType(long objectId)
      Return the type of this object. Native method.
      Parameters:
      objectId - the ID of the btCollisionObject (not zero)
      Returns:
      the type value
      See Also:
    • initUserPointer

      protected void initUserPointer()
      (Re-)initialize the native user info of this collision object, which stores the collision group, collide-with groups, and spaceId (native field: m_userPointer).
    • setActivationState

      protected static void setActivationState(long objectId, int desiredState)
      Alter the activation state of the collision object. Native method.

      Deactivation doesn't affect a PhysicsCharacter or PhysicsGhostObject.

      Parameters:
      objectId - the ID of the btCollisionObject (not zero)
      desiredState - the desired state
    • setCollisionFlags

      protected static void setCollisionFlags(long objectId, int desiredFlags)
      Alter the collision flags of the collision object (native field: m_collisionFlags). Flag values are defined in CollisionFlag. Native method.
      Parameters:
      objectId - the ID of the btCollisionObject (not zero)
      desiredFlags - the desired collision flags, ORed together
    • setLocationAndBasis

      protected void setLocationAndBasis(Vector3f centerLocation, Matrix3f orientation)
      Directly alter the collision object's location and basis.
      Parameters:
      centerLocation - the desired location for the collision object's center (in physics-space coordinates, not null, unaffected)
      orientation - the desired orientation for the collision object (rotation matrix in physics-space coordinates, not null, unaffected)
    • toString

      public String toString()
      Represent the collision object as a String.
      Overrides:
      toString in class NativePhysicsObject
      Returns:
      a descriptive string of text (not null, not empty)