PxRigidBodyExt

Defined in include/extensions/PxRigidBodyExt.h

class PxRigidBodyExt

utility functions for use with PxRigidBody and subclasses

See also

PxRigidBody PxRigidDynamic PxArticulationLink

Public Static Functions

static bool updateMassAndInertia(PxRigidBody &body, const PxReal *shapeDensities, PxU32 shapeDensityCount, const PxVec3 *massLocalPose = NULL, bool includeNonSimShapes = false)

Computation of mass properties for a rigid body actor.

To simulate a dynamic rigid actor, the SDK needs a mass and an inertia tensor.

This method offers functionality to compute the necessary mass and inertia properties based on the shapes declared in the PxRigidBody descriptor and some additionally specified parameters. For each shape, the shape geometry, the shape positioning within the actor and the specified shape density are used to compute the body’s mass and inertia properties.

  • Shapes without PxShapeFlag::eSIMULATION_SHAPE set are ignored unless includeNonSimShapes is true.

  • Shapes with plane, triangle mesh or heightfield geometry and PxShapeFlag::eSIMULATION_SHAPE set are not allowed for PxRigidBody collision.

This method will set the mass, center of mass, and inertia tensor

if no collision shapes are found, the inertia tensor is set to (1,1,1) and the mass to 1

if massLocalPose is non-NULL, the rigid body’s center of mass parameter will be set to the user provided value (massLocalPose) and the inertia tensor will be resolved at that point.

See also

PxRigidBody::setMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass

Note

If all shapes of the actor have the same density then the overloaded method updateMassAndInertia() with a single density parameter can be used instead.

Parameters
  • body[inout] The rigid body.

  • shapeDensities[in] The per shape densities. There must be one entry for each shape which has the PxShapeFlag::eSIMULATION_SHAPE set (or for all shapes if includeNonSimShapes is set to true). Other shapes are ignored. The density values must be greater than 0.

  • shapeDensityCount[in] The number of provided density values.

  • massLocalPose[in] The center of mass relative to the actor frame. If set to null then (0,0,0) is assumed.

  • includeNonSimShapes[in] True if all kind of shapes (PxShapeFlag::eSCENE_QUERY_SHAPE, PxShapeFlag::eTRIGGER_SHAPE) should be taken into account.

Returns

Boolean. True on success else false.

static bool updateMassAndInertia(PxRigidBody &body, PxReal density, const PxVec3 *massLocalPose = NULL, bool includeNonSimShapes = false)

Computation of mass properties for a rigid body actor.

See previous method for details.

See also

PxRigidBody::setMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass

Parameters
  • body[inout] The rigid body.

  • density[in] The density of the body. Used to compute the mass of the body. The density must be greater than 0.

  • massLocalPose[in] The center of mass relative to the actor frame. If set to null then (0,0,0) is assumed.

  • includeNonSimShapes[in] True if all kind of shapes (PxShapeFlag::eSCENE_QUERY_SHAPE, PxShapeFlag::eTRIGGER_SHAPE) should be taken into account.

Returns

Boolean. True on success else false.

static bool setMassAndUpdateInertia(PxRigidBody &body, const PxReal *shapeMasses, PxU32 shapeMassCount, const PxVec3 *massLocalPose = NULL, bool includeNonSimShapes = false)

Computation of mass properties for a rigid body actor.

This method sets the mass, inertia and center of mass of a rigid body. The mass is set to the sum of all user-supplied shape mass values, and the inertia and center of mass are computed according to the rigid body’s shapes and the per shape mass input values.

If no collision shapes are found, the inertia tensor is set to (1,1,1)

See also

updateMassAndInertia for more details.

See also

PxRigidBody::setCMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass

Note

If a single mass value should be used for the actor as a whole then the overloaded method setMassAndUpdateInertia() with a single mass parameter can be used instead.

Parameters
  • body[inout] The rigid body for which to set the mass and centre of mass local pose properties.

  • shapeMasses[in] The per shape mass values. There must be one entry for each shape which has the PxShapeFlag::eSIMULATION_SHAPE set. Other shapes are ignored. The mass values must be greater than 0.

  • shapeMassCount[in] The number of provided mass values.

  • massLocalPose[in] The center of mass relative to the actor frame. If set to null then (0,0,0) is assumed.

  • includeNonSimShapes[in] True if all kind of shapes (PxShapeFlag::eSCENE_QUERY_SHAPE, PxShapeFlag::eTRIGGER_SHAPE) should be taken into account.

Returns

Boolean. True on success else false.

static bool setMassAndUpdateInertia(PxRigidBody &body, PxReal mass, const PxVec3 *massLocalPose = NULL, bool includeNonSimShapes = false)

Computation of mass properties for a rigid body actor.

This method sets the mass, inertia and center of mass of a rigid body. The mass is set to the user-supplied value, and the inertia and center of mass are computed according to the rigid body’s shapes and the input mass.

If no collision shapes are found, the inertia tensor is set to (1,1,1)

See also

updateMassAndInertia for more details.

See also

PxRigidBody::setCMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass

Parameters
  • body[inout] The rigid body for which to set the mass and centre of mass local pose properties.

  • mass[in] The mass of the body. Must be greater than 0.

  • massLocalPose[in] The center of mass relative to the actor frame. If set to null then (0,0,0) is assumed.

  • includeNonSimShapes[in] True if all kind of shapes (PxShapeFlag::eSCENE_QUERY_SHAPE, PxShapeFlag::eTRIGGER_SHAPE) should be taken into account.

Returns

Boolean. True on success else false.

static PxMassProperties computeMassPropertiesFromShapes(const PxShape *const *shapes, PxU32 shapeCount)

Compute the mass, inertia tensor and center of mass from a list of shapes.

See also

PxRigidBody::setCMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass

Parameters
  • shapes[in] The shapes to compute the mass properties from.

  • shapeCount[in] The number of provided shapes.

Returns

The mass properties from the combined shapes.

static void addForceAtPos(PxRigidBody &body, const PxVec3 &force, const PxVec3 &pos, PxForceMode::Enum mode = PxForceMode::eFORCE, bool wakeup = true)

Applies a force (or impulse) defined in the global coordinate frame, acting at a particular point in global coordinates, to the actor.

Note that if the force does not act along the center of mass of the actor, this will also add the corresponding torque. Because forces are reset at the end of every timestep, you can maintain a total external force on an object by calling this once every frame.

PxForceMode determines if the force is to be conventional or impulsive. Only eFORCE and eIMPULSE are supported, as the force required to produce a given velocity change or acceleration is underdetermined given only the desired change at a given point.

Sleeping: This call wakes the actor if it is sleeping and the wakeup parameter is true (default).

See also

PxForceMode

See also

addForceAtLocalPos() addLocalForceAtPos() addLocalForceAtLocalPos()

Note

if this call is used to apply a force or impulse to an articulation link, only the link is updated, not the entire articulation

Parameters
  • body[in] The rigid body to apply the force to.

  • force[in] Force/impulse to add, defined in the global frame. Range: force vector

  • pos[in] Position in the global frame to add the force at. Range: position vector

  • mode[in] The mode to use when applying the force/impulse(see PxForceMode).

  • wakeup[in] Specify if the call should wake up the actor.

static void addForceAtLocalPos(PxRigidBody &body, const PxVec3 &force, const PxVec3 &pos, PxForceMode::Enum mode = PxForceMode::eFORCE, bool wakeup = true)

Applies a force (or impulse) defined in the global coordinate frame, acting at a particular point in local coordinates, to the actor.

Note that if the force does not act along the center of mass of the actor, this will also add the corresponding torque. Because forces are reset at the end of every timestep, you can maintain a total external force on an object by calling this once every frame.

PxForceMode determines if the force is to be conventional or impulsive. Only eFORCE and eIMPULSE are supported, as the force required to produce a given velocity change or acceleration is underdetermined given only the desired change at a given point.

Sleeping: This call wakes the actor if it is sleeping and the wakeup parameter is true (default).

See also

PxForceMode

See also

addForceAtPos() addLocalForceAtPos() addLocalForceAtLocalPos()

Note

if this call is used to apply a force or impulse to an articulation link, only the link is updated, not the entire articulation

Parameters
  • body[in] The rigid body to apply the force to.

  • force[in] Force/impulse to add, defined in the global frame. Range: force vector

  • pos[in] Position in the local frame to add the force at. Range: position vector

  • mode[in] The mode to use when applying the force/impulse(see PxForceMode).

  • wakeup[in] Specify if the call should wake up the actor.

static void addLocalForceAtPos(PxRigidBody &body, const PxVec3 &force, const PxVec3 &pos, PxForceMode::Enum mode = PxForceMode::eFORCE, bool wakeup = true)

Applies a force (or impulse) defined in the actor local coordinate frame, acting at a particular point in global coordinates, to the actor.

Note that if the force does not act along the center of mass of the actor, this will also add the corresponding torque. Because forces are reset at the end of every timestep, you can maintain a total external force on an object by calling this once every frame.

PxForceMode determines if the force is to be conventional or impulsive. Only eFORCE and eIMPULSE are supported, as the force required to produce a given velocity change or acceleration is underdetermined given only the desired change at a given point.

Sleeping: This call wakes the actor if it is sleeping and the wakeup parameter is true (default).

See also

PxForceMode

See also

addForceAtPos() addForceAtLocalPos() addLocalForceAtLocalPos()

Note

if this call is used to apply a force or impulse to an articulation link, only the link is updated, not the entire articulation

Parameters
  • body[in] The rigid body to apply the force to.

  • force[in] Force/impulse to add, defined in the local frame. Range: force vector

  • pos[in] Position in the global frame to add the force at. Range: position vector

  • mode[in] The mode to use when applying the force/impulse(see PxForceMode).

  • wakeup[in] Specify if the call should wake up the actor.

static void addLocalForceAtLocalPos(PxRigidBody &body, const PxVec3 &force, const PxVec3 &pos, PxForceMode::Enum mode = PxForceMode::eFORCE, bool wakeup = true)

Applies a force (or impulse) defined in the actor local coordinate frame, acting at a particular point in local coordinates, to the actor.

Note that if the force does not act along the center of mass of the actor, this will also add the corresponding torque. Because forces are reset at the end of every timestep, you can maintain a total external force on an object by calling this once every frame.

PxForceMode determines if the force is to be conventional or impulsive. Only eFORCE and eIMPULSE are supported, as the force required to produce a given velocity change or acceleration is underdetermined given only the desired change at a given point.

Sleeping: This call wakes the actor if it is sleeping and the wakeup parameter is true (default).

See also

PxForceMode

See also

addForceAtPos() addForceAtLocalPos() addLocalForceAtPos()

Note

if this call is used to apply a force or impulse to an articulation link, only the link is updated, not the entire articulation

Parameters
  • body[in] The rigid body to apply the force to.

  • force[in] Force/impulse to add, defined in the local frame. Range: force vector

  • pos[in] Position in the local frame to add the force at. Range: position vector

  • mode[in] The mode to use when applying the force/impulse(see PxForceMode).

  • wakeup[in] Specify if the call should wake up the actor.

static PxVec3 getVelocityAtPos(const PxRigidBody &body, const PxVec3 &pos)

Computes the velocity of a point given in world coordinates if it were attached to the specified body and moving with it.

See also

getLocalPointVelocity()

Parameters
  • body[in] The rigid body the point is attached to.

  • pos[in] Position we wish to determine the velocity for, defined in the global frame. Range: position vector

Returns

The velocity of point in the global frame.

static PxVec3 getLocalVelocityAtLocalPos(const PxRigidBody &body, const PxVec3 &pos)

Computes the velocity of a point given in local coordinates if it were attached to the specified body and moving with it.

See also

getLocalPointVelocity()

Parameters
  • body[in] The rigid body the point is attached to.

  • pos[in] Position we wish to determine the velocity for, defined in the local frame. Range: position vector

Returns

The velocity of point in the local frame.

static PxVec3 getVelocityAtOffset(const PxRigidBody &body, const PxVec3 &pos)

Computes the velocity of a point (offset from the origin of the body) given in world coordinates if it were attached to the specified body and moving with it.

See also

getLocalPointVelocity()

Parameters
  • body[in] The rigid body the point is attached to.

  • pos[in] Position (offset from the origin of the body) we wish to determine the velocity for, defined in the global frame. Range: position vector

Returns

The velocity of point (offset from the origin of the body) in the global frame.

static void computeVelocityDeltaFromImpulse(const PxRigidBody &body, const PxVec3 &impulsiveForce, const PxVec3 &impulsiveTorque, PxVec3 &deltaLinearVelocity, PxVec3 &deltaAngularVelocity)

Compute the change to linear and angular velocity that would occur if an impulsive force and torque were to be applied to a specified rigid body.

The rigid body is left unaffected unless a subsequent independent call is executed that actually applies the computed changes to velocity and angular velocity.

See also

PxRigidBody::getLinearVelocity, PxRigidBody::setLinearVelocity, PxRigidBody::getAngularVelocity, PxRigidBody::setAngularVelocity

Note

if this call is used to determine the velocity delta for an articulation link, only the mass properties of the link are taken into account.

Parameters
  • body[in] The body under consideration.

  • impulsiveForce[in] The impulsive force that would be applied to the specified rigid body.

  • impulsiveTorque[in] The impulsive torque that would be applied to the specified rigid body.

  • deltaLinearVelocity[out] The change in linear velocity that would arise if impulsiveForce was to be applied to the specified rigid body.

  • deltaAngularVelocity[out] The change in angular velocity that would arise if impulsiveTorque was to be applied to the specified rigid body.

static void computeVelocityDeltaFromImpulse(const PxRigidBody &body, const PxTransform &globalPose, const PxVec3 &point, const PxVec3 &impulse, const PxReal invMassScale, const PxReal invInertiaScale, PxVec3 &deltaLinearVelocity, PxVec3 &deltaAngularVelocity)

Computes the linear and angular velocity change vectors for a given impulse at a world space position taking a mass and inertia scale into account.

This function is useful for extracting the respective linear and angular velocity changes from a contact or joint when the mass/inertia ratios have been adjusted.

Note

if this call is used to determine the velocity delta for an articulation link, only the mass properties of the link are taken into account.

Parameters
  • body[in] The rigid body

  • globalPose[in] The body’s world space transform

  • point[in] The point in world space where the impulse is applied

  • impulse[in] The impulse vector in world space

  • invMassScale[in] The inverse mass scale

  • invInertiaScale[in] The inverse inertia scale

  • deltaLinearVelocity[out] The linear velocity change

  • deltaAngularVelocity[out] The angular velocity change

static void computeLinearAngularImpulse(const PxRigidBody &body, const PxTransform &globalPose, const PxVec3 &point, const PxVec3 &impulse, const PxReal invMassScale, const PxReal invInertiaScale, PxVec3 &linearImpulse, PxVec3 &angularImpulse)

Computes the linear and angular impulse vectors for a given impulse at a world space position taking a mass and inertia scale into account.

This function is useful for extracting the respective linear and angular impulses from a contact or joint when the mass/inertia ratios have been adjusted.

Parameters
  • body[in] The rigid body

  • globalPose[in] The body’s world space transform

  • point[in] The point in world space where the impulse is applied

  • impulse[in] The impulse vector in world space

  • invMassScale[in] The inverse mass scale

  • invInertiaScale[in] The inverse inertia scale

  • linearImpulse[out] The linear impulse

  • angularImpulse[out] The angular impulse

static bool linearSweepSingle(PxRigidBody &body, PxScene &scene, const PxVec3 &unitDir, const PxReal distance, PxHitFlags outputFlags, PxSweepHit &closestHit, PxU32 &shapeIndex, const PxQueryFilterData &filterData = PxQueryFilterData(), PxQueryFilterCallback *filterCall = NULL, const PxQueryCache *cache = NULL, const PxReal inflation = 0.0f)

Performs a linear sweep through space with the body’s geometry objects.

The function sweeps all shapes attached to a given rigid body through space and reports the nearest object in the scene which intersects any of of the shapes swept paths. Information about the closest intersection is written to a PxSweepHit structure.

See also

PxScene PxQueryFlags PxFilterData PxSweepHit

Note

Supported geometries are: box, sphere, capsule, convex. Other geometry types will be ignored.

Note

If eTOUCH is returned from the filter callback, it will trigger an error and the hit will be discarded.

Parameters
  • body[in] The rigid body to sweep.

  • scene[in] The scene object to process the query.

  • unitDir[in] Normalized direction of the sweep.

  • distance[in] Sweep distance. Needs to be larger than 0.

  • outputFlags[in] Specifies which properties should be written to the hit information.

  • closestHit[out] Closest hit result.

  • shapeIndex[out] Index of the body shape that caused the closest hit.

  • filterData[in] If any word in filterData.data is non-zero then filterData.data will be used for filtering, otherwise shape->getQueryFilterData() will be used instead.

  • filterCall[in] Custom filtering logic (optional). Only used if the corresponding PxQueryFlag flags are set. If NULL, all hits are assumed to be blocking.

  • cache[in] Cached hit shape (optional). Ray is tested against cached shape first then against the scene. Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.

  • inflation[in] This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal.

Returns

True if a blocking hit was found.

static PxU32 linearSweepMultiple(PxRigidBody &body, PxScene &scene, const PxVec3 &unitDir, const PxReal distance, PxHitFlags outputFlags, PxSweepHit *touchHitBuffer, PxU32 *touchHitShapeIndices, PxU32 touchHitBufferSize, PxSweepHit &block, PxI32 &blockingShapeIndex, bool &overflow, const PxQueryFilterData &filterData = PxQueryFilterData(), PxQueryFilterCallback *filterCall = NULL, const PxQueryCache *cache = NULL, const PxReal inflation = 0.0f)

Performs a linear sweep through space with the body’s geometry objects, returning all overlaps.

This function sweeps all shapes attached to a given rigid body through space and reports all objects in the scene that intersect any of the shapes’ swept paths until there are no more objects to report or a blocking hit is encountered.

See also

PxScene PxQueryFlags PxFilterData PxSweepHit

Note

Supported geometries are: box, sphere, capsule, convex. Other geometry types will be ignored.

Parameters
  • body[in] The rigid body to sweep.

  • scene[in] The scene object to process the query.

  • unitDir[in] Normalized direction of the sweep.

  • distance[in] Sweep distance. Needs to be larger than 0.

  • outputFlags[in] Specifies which properties should be written to the hit information.

  • touchHitBuffer[out] Raycast hit information buffer. If the buffer overflows, an arbitrary subset of touch hits is returned (typically the query should be restarted with a larger buffer).

  • touchHitShapeIndices[out] After the query is completed, touchHitShapeIndices[i] will contain the body index that caused the hit stored in hitBuffer[i]

  • touchHitBufferSize[in] Size of both touch hit buffers in elements.

  • block[out] Closest blocking hit is returned via this reference.

  • blockingShapeIndex[out] Set to -1 if if a blocking hit was not found, otherwise set to closest blocking hit shape index. The touching hits are reported separately in hitBuffer.

  • overflow[out] Set to true if touchHitBuffer didn’t have enough space for all results. Touch hits will be incomplete if overflow occurred. Possible solution is to restart the query with a larger buffer.

  • filterData[in] If any word in filterData.data is non-zero then filterData.data will be used for filtering, otherwise shape->getQueryFilterData() will be used instead.

  • filterCall[in] Custom filtering logic (optional). Only used if the corresponding PxQueryFlag flags are set. If NULL, all hits are assumed to be blocking.

  • cache[in] Cached hit shape (optional). Ray is tested against cached shape first then against the scene. Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.

  • inflation[in] This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal.

Returns

the number of touching hits. If overflow is set to true, the results are incomplete. In case of overflow there are also no guarantees that all touching hits returned are closer than the blocking hit.