Rigid Body Overview

Introduction

This chapter will introduce the fundamentals of simulating rigid body dynamics using the NVIDIA PhysX engine.

Rigid Body Object Model

PhysX uses a hierarchical rigid body object/actor model.

Class

Extends

Functionality

PxBase

N/A

Reflection/querying object types.

PxActor

PxBase

Actor name, actor flags, dominance, clients, aggregates, query world bounds.

PxRigidActor

PxActor

Shapes, transforms, and querying constraints.

PxRigidBody

PxRigidActor

Mass, inertia, velocities, damping, forces, body flags.

PxRigidStatic

PxRigidActor

Interface for static body in the scene. This kind of body has implicit infinite mass/inertia.

PxRigidDynamic

PxRigidBody

Interface for dynamic rigid body in the scene. Introduces support for kinematic targets and object sleeping.

PxArticulationLink

PxRigidBody

Interface for a dynamic rigid body link in a PxArticulation. Introduces support for querying the articulation and adjacent links.

PxArticulationReducedCoordinate

PxBase

Defines interface for a PxArticulation. Effectively a container referencing multiple PxArticulationLink rigid bodies.

The following diagram shows the relationship between the main types involved in the rigid body pipeline:

../_images/RigidBodyOverview.PNG

Creating Rigid Actors

Rigid actors along with their shapes can be created through the PxPhysics instance:

PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE;
PxMaterial* materialPtr = &material;

//plane rigid static
PxRigidStatic* rigidStatic = mPhysics.createRigidStatic(PxTransformFromPlaneEquation(PxPlane(PxVec3(0.f, 1.f, 0.f), 0.f)));
{
        PxShape* shape = mPhysics.createShape(PxPlaneGeometry(), &materialPtr, 1, true, shapeFlags);
        rigidStatic->attachShape(*shape);
        shape->release(); // this way shape gets automatically released with actor
}

//single shape rigid dynamic
PxRigidDynamic* rigidDynamic = mPhysics.createRigidDynamic(PxTransform(PxVec3(0.f, 2.5f, 0.f)));
{
        PxShape* shape = mPhysics.createShape(PxBoxGeometry(2.f, 2.f, 2.f), &materialPtr, 1, true, shapeFlags);
        rigidDynamic->attachShape(*shape);
        shape->release(); // this way shape gets automatically released with actor
}

mScene.addActor(*rigidStatic);
mScene.addActor(*rigidDynamic);

More details on collision geometry and shapes are provided in Rigid Body Collision. In the case of single shape actors the PxRigidActorExt::createExclusiveShape() function from PxRigidActorExt.h can be used:

//plane rigid static
PxRigidStatic* rigidStatic = mPhysics.createRigidStatic(PxTransformFromPlaneEquation(PxPlane(PxVec3(0.f, 1.f, 0.f), 0.f)));
PxRigidActorExt::createExclusiveShape(*rigidStatic, PxPlaneGeometry(), material);

//single shape rigid dynamic
PxRigidDynamic* rigidDynamic = mPhysics.createRigidDynamic(PxTransform(PxVec3(0.f, 2.5f, 0.f)));
PxRigidActorExt::createExclusiveShape(*rigidDynamic, PxBoxGeometry(2.f, 2.f, 2.f), material);

mScene.addActor(*rigidStatic);
mScene.addActor(*rigidDynamic);

Helper functions in PxSimpleFactory.h can further simplify the setup for common cases:

//plane rigid static
PxRigidStatic* rigidStatic = PxCreatePlane(mPhysics, PxPlane(PxVec3(0.f, 1.f, 0.f), 0.f), material);

//single shape rigid dynamic
PxRigidDynamic* rigidDynamic = PxCreateDynamic(mPhysics, PxTransform(PxVec3(0.f, 2.5f, 0.f)), PxBoxGeometry(2.f, 2.f, 2.f), material, 1.f);

mScene.addActor(*rigidStatic);
mScene.addActor(*rigidDynamic);

The helpers in PxSimpleFactory.h further support creating kinematic actors, cloning shapes, actors and scaling actors.

Simulation

For the actual simulation rigid body objects need to be added to a scene and that scene will be stepped forwards in time. See section The Simulation Loop.