esp::physics::BulletPhysicsManager class

Dynamic scene and object manager interfacing with Bullet physics engine: https://github.com/bulletphysics/bullet3.

See btMultiBodyDynamicsWorld.

Enables RigidObject simulation with MotionType::DYNAMIC.

This class handles initialization and stepping of the world as well as getting and setting global simulation parameters. The BulletRigidObject class handles most of the specific implementations for object interactions with Bullet.

Base classes

class PhysicsManager
Kinematic and dynamic scene and object manager.

Constructors, destructors, conversion operators

BulletPhysicsManager(assets::ResourceManager& _resourceManager) explicit
Construct a BulletPhysicsManager with access to specific resourse assets.
~BulletPhysicsManager() virtual
Destructor which destructs necessary Bullet physics structures.

Public functions

void stepPhysics(double dt) override
Step the physical world forward in time. Time may only advance in increments of fixedTimeStep_. See btMultiBodyDynamicsWorld::stepSimulation.
void setGravity(const Magnum::Vector3& gravity) override
Set the gravity of the physical world.
auto getGravity() const -> Magnum::Vector3 override
Get the current gravity in the physical world.
void setMargin(const int physObjectID, const double margin) override
Set the scalar collision margin of an object. See BulletRigidObject::setMargin.
void setSceneFrictionCoefficient(const double frictionCoefficient) override
Set the friction coefficient of the scene collision geometry. See staticSceneObject_. See BulletRigidObject::setFrictionCoefficient.
void setSceneRestitutionCoefficient(const double restitutionCoefficient) override
Set the coefficient of restitution for the scene collision geometry. See staticSceneObject_. See BulletRigidObject::setRestitutionCoefficient.
auto getMargin(const int physObjectID) const -> double override
Get the scalar collision margin of an object. See BulletRigidObject::getMargin.
auto getSceneFrictionCoefficient() const -> double override
Get the current friction coefficient of the scene collision geometry. See staticSceneObject_ and BulletRigidObject::getFrictionCoefficient.
auto getSceneRestitutionCoefficient() const -> double override
Get the current coefficient of restitution for the scene collision geometry. This determines the ratio of initial to final relative velocity between the scene and collidiing object. See staticSceneObject_ and BulletRigidObject::getRestitutionCoefficient.
auto getCollisionShapeAabb(const int physObjectID) const -> const Magnum::Range3D
Query the Aabb from bullet physics for the root compound shape of a rigid body in its local space. See btCompoundShape::getAabb.
auto getSceneCollisionShapeAabb() const -> const Magnum::Range3D
Query the Aabb from bullet physics for the root compound shape of the static scene in its local space. See btCompoundShape::getAabb.
void debugDraw(const Magnum::Matrix4& projTrans) const override
Render the debugging visualizations provided by Magnum::BulletIntegration::DebugDraw. This draws wireframes for all collision objects.
auto contactTest(const int physObjectID) -> bool override
Check whether an object is in contact with any other objects or the scene.

Protected functions

auto initPhysicsFinalize(const assets::PhysicsManagerAttributes::ptr physicsManagerAttributes) -> bool override
Finalize physics initialization: Setup staticSceneObject_ and initialize any other physics-related values.
auto addSceneFinalize(const assets::PhysicsSceneAttributes::ptr physicsSceneAttributes, const std::vector<assets::CollisionMeshData>& meshGroup) -> bool override
Finalize scene initialization. Checks that the collision mesh can be used by Bullet. See BulletRigidObject::initializeScene. Bullet mesh conversion adapted from: https://github.com/mosra/magnum-integration/issues/20.
auto makeAndAddRigidObject(int newObjectID, const std::vector<assets::CollisionMeshData>& meshGroup, assets::PhysicsObjectAttributes::ptr physicsObjectAttributes, scene::SceneNode* objectNode) -> bool override
Create and initialize an RigidObject and add it to existingObjects_ map keyed with newObjectID.

Protected variables

btDbvtBroadphase bBroadphase_
btDefaultCollisionConfiguration bCollisionConfig_
btMultiBodyConstraintSolver bSolver_
btCollisionDispatcher bDispatcher_
std::shared_ptr<btMultiBodyDynamicsWorld> bWorld_
A pointer to the Bullet world. See btMultiBodyDynamicsWorld.
Magnum::BulletIntegration::DebugDraw debugDrawer_

Private functions

auto isMeshPrimitiveValid(const assets::CollisionMeshData& meshData) -> bool override
Check if a particular mesh can be used as a collision mesh for Bullet.

Function documentation

esp::physics::BulletPhysicsManager::BulletPhysicsManager(assets::ResourceManager& _resourceManager) explicit

Construct a BulletPhysicsManager with access to specific resourse assets.

Parameters
_resourceManager The esp::assets::ResourceManager which tracks the assets this BulletPhysicsManager will have access to.

void esp::physics::BulletPhysicsManager::stepPhysics(double dt) override

Step the physical world forward in time. Time may only advance in increments of fixedTimeStep_. See btMultiBodyDynamicsWorld::stepSimulation.

Parameters
dt The desired amount of time to advance the physical world.

void esp::physics::BulletPhysicsManager::setGravity(const Magnum::Vector3& gravity) override

Set the gravity of the physical world.

Parameters
gravity The desired gravity force of the physical world.

Magnum::Vector3 esp::physics::BulletPhysicsManager::getGravity() const override

Get the current gravity in the physical world.

Returns The current gravity vector in the physical world.

void esp::physics::BulletPhysicsManager::setMargin(const int physObjectID, const double margin) override

Set the scalar collision margin of an object. See BulletRigidObject::setMargin.

Parameters
physObjectID The object ID and key identifying the object in PhysicsManager::existingObjects_.
margin The desired collision margin for the object.

void esp::physics::BulletPhysicsManager::setSceneFrictionCoefficient(const double frictionCoefficient) override

Set the friction coefficient of the scene collision geometry. See staticSceneObject_. See BulletRigidObject::setFrictionCoefficient.

Parameters
frictionCoefficient The scalar friction coefficient of the scene geometry.

void esp::physics::BulletPhysicsManager::setSceneRestitutionCoefficient(const double restitutionCoefficient) override

Set the coefficient of restitution for the scene collision geometry. See staticSceneObject_. See BulletRigidObject::setRestitutionCoefficient.

Parameters
restitutionCoefficient The scalar coefficient of restitution to set.

double esp::physics::BulletPhysicsManager::getMargin(const int physObjectID) const override

Get the scalar collision margin of an object. See BulletRigidObject::getMargin.

Parameters
physObjectID The object ID and key identifying the object in PhysicsManager::existingObjects_.
Returns The scalar collision margin of the object or esp::PHYSICS_ATTR_UNDEFINED if failed..

double esp::physics::BulletPhysicsManager::getSceneFrictionCoefficient() const override

Get the current friction coefficient of the scene collision geometry. See staticSceneObject_ and BulletRigidObject::getFrictionCoefficient.

Returns The scalar friction coefficient of the scene geometry.

double esp::physics::BulletPhysicsManager::getSceneRestitutionCoefficient() const override

Get the current coefficient of restitution for the scene collision geometry. This determines the ratio of initial to final relative velocity between the scene and collidiing object. See staticSceneObject_ and BulletRigidObject::getRestitutionCoefficient.

Returns The scalar coefficient of restitution for the scene geometry.

const Magnum::Range3D esp::physics::BulletPhysicsManager::getCollisionShapeAabb(const int physObjectID) const

Query the Aabb from bullet physics for the root compound shape of a rigid body in its local space. See btCompoundShape::getAabb.

Parameters
physObjectID The object ID and key identifying the object in PhysicsManager::existingObjects_.
Returns The Aabb.

const Magnum::Range3D esp::physics::BulletPhysicsManager::getSceneCollisionShapeAabb() const

Query the Aabb from bullet physics for the root compound shape of the static scene in its local space. See btCompoundShape::getAabb.

Returns The scene collision Aabb.

void esp::physics::BulletPhysicsManager::debugDraw(const Magnum::Matrix4& projTrans) const override

Render the debugging visualizations provided by Magnum::BulletIntegration::DebugDraw. This draws wireframes for all collision objects.

Parameters
projTrans The composed projection and transformation matrix for the render camera.

bool esp::physics::BulletPhysicsManager::contactTest(const int physObjectID) override

Check whether an object is in contact with any other objects or the scene.

Parameters
physObjectID The object ID and key identifying the object in PhysicsManager::existingObjects_.
Returns Whether or not the object is in contact with any other collision enabled objects.

bool esp::physics::BulletPhysicsManager::initPhysicsFinalize(const assets::PhysicsManagerAttributes::ptr physicsManagerAttributes) override protected

Finalize physics initialization: Setup staticSceneObject_ and initialize any other physics-related values.

Parameters
physicsManagerAttributes A structure containing values for physical parameters necessary to initialize the physical scene and simulator.

bool esp::physics::BulletPhysicsManager::addSceneFinalize(const assets::PhysicsSceneAttributes::ptr physicsSceneAttributes, const std::vector<assets::CollisionMeshData>& meshGroup) override protected

Finalize scene initialization. Checks that the collision mesh can be used by Bullet. See BulletRigidObject::initializeScene. Bullet mesh conversion adapted from: https://github.com/mosra/magnum-integration/issues/20.

Parameters
physicsSceneAttributes a pointer to the structure defining physical properties of the scene.
meshGroup collision meshs for the scene.
Returns true if successful and false otherwise

bool esp::physics::BulletPhysicsManager::makeAndAddRigidObject(int newObjectID, const std::vector<assets::CollisionMeshData>& meshGroup, assets::PhysicsObjectAttributes::ptr physicsObjectAttributes, scene::SceneNode* objectNode) override protected

Create and initialize an RigidObject and add it to existingObjects_ map keyed with newObjectID.

Parameters
newObjectID valid object ID for the new object
meshGroup The object's mesh.
physicsObjectAttributes The physical object's template defining its physical parameters.
objectNode Valid, existing scene node
Returns whether the object has been successfully initialized and added to existingObjects_ map

bool esp::physics::BulletPhysicsManager::isMeshPrimitiveValid(const assets::CollisionMeshData& meshData) override private

Check if a particular mesh can be used as a collision mesh for Bullet.

Parameters
meshData The mesh to validate. Only a triangle mesh is valid. Checks that the only ref Magnum::MeshPrimitive are Magnum::MeshPrimitive::Triangles.
Returns true if valid, false otherwise.