esp::physics::BulletRigidObject class

An individual rigid object instance implementing an interface with Bullet physics to enable MotionType::DYNAMIC objects.

See btCollisionObject for RigidObjectType::SCENE and btRigidBody for RigidObjectType::OBJECT.

Utilizes Magnum::BulletIntegration::MotionState to syncronize SceneNode state with internal btRigidBody state.

Base classes

class RigidObject
An AbstractFeature3D representing an individual rigid object instance attached to a SceneNode, updating its state through simulation. This may be a MotionType::STATIC scene collision geometry or an object of any MotionType which can interact with other members of a physical world. Must have a collision mesh. By default, a RigidObject is MotionType::KINEMATIC without an underlying simulator implementation. Derived classes can be used to introduce specific implementations of dynamics.

Constructors, destructors, conversion operators

BulletRigidObject(scene::SceneNode* rigidBodyNode, std::shared_ptr<btMultiBodyDynamicsWorld> bWorld)
Constructor for a BulletRigidObject.
~BulletRigidObject() virtual
Destructor cleans up simulation structures for the object.

Public functions

void finalizeObject() override
Finalize this object with any necessary post-creation processes.
void constructBulletCompoundFromMeshes(const Magnum::Matrix4& transformFromParentToWorld, const std::vector<assets::CollisionMeshData>& meshGroup, const assets::MeshTransformNode& node, bool join)
Recursively construct a btCompoundShape for collision from loaded mesh assets. A btConvexHullShape is constructed for each sub-component, transformed to object-local space and added to the compound in a flat manner for efficiency.
void constructBulletSceneFromMeshes(const Magnum::Matrix4& transformFromParentToWorld, const std::vector<assets::CollisionMeshData>& meshGroup, const assets::MeshTransformNode& node)
Recursively construct the static collision mesh objects from imported assets.
auto isActive() -> bool override
Check whether object is being actively simulated, or sleeping. See btCollisionObject::isActive.
void setActive() override
Set an object as being actively simulated rather than sleeping. See btCollisionObject::activate.
auto setMotionType(MotionType mt) -> bool override
Set the MotionType of the object. If the object is ObjectType::SCENE it can only be MotionType::STATIC. If the object is ObjectType::OBJECT is can also be set to MotionType::KINEMATIC or MotionType::DYNAMIC. See btRigidBody::setCollisionFlags and btCollisionObject::CF_STATIC_OBJECT,CF_KINEMATIC_OBJECT.
void shiftOrigin(const Magnum::Vector3& shift) override
Shift the object's local origin by translating all children of this BulletRigidObject and all components of its bObjectShape_.
void applyForce(const Magnum::Vector3& force, const Magnum::Vector3& relPos) override
Apply a force to an object. Does nothing for MotionType::STATIC and MotionType::KINEMATIC objects. Calls setActive(). See btRigidBody::applyForce.
void applyImpulse(const Magnum::Vector3& impulse, const Magnum::Vector3& relPos) override
Apply an impulse to an object. Directly modifies the object's velocity without requiring integration through simulation. Does nothing for MotionType::STATIC and MotionType::KINEMATIC objects. Calls setActive(). See btRigidBody::applyImpulse.
void applyTorque(const Magnum::Vector3& torque) override
Apply an internal torque to an object. Does nothing for MotionType::STATIC and MotionType::KINEMATIC objects. Calls setActive(). See btRigidBody::applyTorque.
void applyImpulseTorque(const Magnum::Vector3& impulse) override
Apply an internal impulse torque to an object. Does nothing for MotionType::STATIC and MotionType::KINEMATIC objects. Calls setActive(). See btRigidBody::applyTorqueImpulse.
void setLinearVelocity(const Magnum::Vector3& linVel) override
Linear velocity setter for an object.
void setAngularVelocity(const Magnum::Vector3& angVel) override
Angular velocity setter for an object.
auto getLinearVelocity() const -> Magnum::Vector3 override
Virtual linear velocity getter for an object.
auto getAngularVelocity() const -> Magnum::Vector3 override
Angular velocity getter for an object.
auto getMass() -> double override
Get the mass of the object. Returns 0.0 for RigidObjectType::SCENE. See btRigidBody::getInvMass.
auto getCOM() -> Magnum::Vector3 override
Get the center of mass (COM) of the object. For Bullet, COM is always the origin of the local coordinate system. Return [0,0,0] for RigidObjectType::SCENE. See btRigidBody::getCenterOfMassPosition.
auto getInertiaVector() -> Magnum::Vector3 override
Get the diagonal of the inertia matrix for an object. If an object is aligned with its principle axii of inertia, the 3x3 inertia matrix can be reduced to a diagonal. This is expected for Bullet. See BulletRigidObject::setInertiaVector. See btRigidBody::getInvInertiaDiagLocal.
auto getInertiaMatrix() -> Magnum::Matrix3 override
Get the 3x3 inertia matrix for an object. For Bullet, this will be a diagonal matrix. See getInertiaVector.
auto getScale() -> double override
Get the uniform scale of the object.
auto getFrictionCoefficient() -> double override
Get the scalar friction coefficient of the object. See btCollisionObject::getFriction.
auto getRestitutionCoefficient() -> double override
Get the scalar coefficient of restitution of the object. See btCollisionObject::getRestitution.
auto getLinearDamping() -> double override
Get the scalar linear damping coefficient of the object. See btRigidBody::getLinearDamping.
auto getAngularDamping() -> double override
Get the scalar angular damping coefficient of the object. See btRigidBody::getAngularDamping.
auto getMargin() -> double
Get the scalar collision margin of an object. Retun 0.0 for a RigidObjectType::SCENE. See btCompoundShape::getMargin.
void setMass(const double mass) override
Set the mass of the object. See btRigidBody::setMassProps. Note that changing mass should affect inertia, but this is not done automatically. Does not affect RigidObjectType::SCENE.
void setCOM(const Magnum::Vector3& COM) override
Set the center of mass (COM) of the object.
void setInertiaVector(const Magnum::Vector3& inertia) override
Set the diagonal of the inertia matrix for the object. If an object is aligned with its principle axii of inertia, the 3x3 inertia matrix can be reduced to a diagonal. This is the requirement for Bullet btRigidBody objects. See btRigidBody::setMassProps. Does not affect RigidObjectType::SCENE.
void setScale(const double scale) override
Set the uniform scale of the object.
void setFrictionCoefficient(const double frictionCoefficient) override
Set the scalar friction coefficient of the object. See btCollisionObject::setFriction.
void setRestitutionCoefficient(const double restitutionCoefficient) override
Set the scalar coefficient of restitution of the object. See btCollisionObject::setRestitution.
void setLinearDamping(const double linearDamping) override
Set the scalar linear damping coefficient of the object. See btRigidBody::setDamping. Does not affect RigidObjectType::SCENE.
void setAngularDamping(const double angularDamping) override
Set the scalar angular damping coefficient for the object. See btRigidBody::setDamping. Does not affect RigidObjectType::SCENE.
void setMargin(const double margin)
Set the scalar collision margin of an object. Does not affect RigidObjectType::SCENE. See btCompoundShape::setMargin.
void setCollisionFromBB()
ets the object's collision shape to its bounding box. Since the bounding hierarchy is not constructed when the object is initialized, this needs to be called after loading the SceneNode.
auto isUsingBBCollisionShape() const -> bool
Public getter for usingBBCollisionShape_ set from configuration.
auto contactTest() -> bool
Return result of a discrete contact test between the object and collision world.
auto getCollisionShapeAabb() const -> const Magnum::Range3D
Query the Aabb from bullet physics for the root compound shape of the rigid body in its local space. See btCompoundShape::getAabb.

Protected functions

void syncPose() override
Used to synchronize Bullet's notion of the object state after it was changed kinematically. Called automatically on kinematic updates. See btRigidBody::setWorldTransform.

Protected variables

bool usingBBCollisionShape_

Private functions

auto initializeSceneFinalize(const assets::ResourceManager& resMgr, const assets::PhysicsSceneAttributes::ptr physicsSceneAttributes, const std::vector<assets::CollisionMeshData>& meshGroup) -> bool override
Initializes this BulletRigidObject as static scene geometry. See PhysicsManager::staticSceneObject_. Sets rigidObjectType_ to RigidObjectType::SCENE. See btCollisionObject.
auto initializeObjectFinalize(const assets::ResourceManager& resMgr, const assets::PhysicsObjectAttributes::ptr physicsObjectAttributes, const std::vector<assets::CollisionMeshData>& meshGroup) -> bool override
Finalize initialization of this BulletRigidObject as a MotionType::DYNAMIC object. See btRigidBody.

Function documentation

esp::physics::BulletRigidObject::BulletRigidObject(scene::SceneNode* rigidBodyNode, std::shared_ptr<btMultiBodyDynamicsWorld> bWorld)

Constructor for a BulletRigidObject.

Parameters
rigidBodyNode The scene::SceneNode this feature will be attached to.
bWorld

void esp::physics::BulletRigidObject::constructBulletCompoundFromMeshes(const Magnum::Matrix4& transformFromParentToWorld, const std::vector<assets::CollisionMeshData>& meshGroup, const assets::MeshTransformNode& node, bool join)

Recursively construct a btCompoundShape for collision from loaded mesh assets. A btConvexHullShape is constructed for each sub-component, transformed to object-local space and added to the compound in a flat manner for efficiency.

Parameters
transformFromParentToWorld The cumulative parent-to-world transformation matrix constructed by composition down the MeshTransformNode tree to the current node.
meshGroup Access structure for collision mesh data.
node The current MeshTransformNode in the recursion.
join Whether or not to join sub-meshes into a single con convex shape, rather than creating individual convexes under the compound.

void esp::physics::BulletRigidObject::constructBulletSceneFromMeshes(const Magnum::Matrix4& transformFromParentToWorld, const std::vector<assets::CollisionMeshData>& meshGroup, const assets::MeshTransformNode& node)

Recursively construct the static collision mesh objects from imported assets.

Parameters
transformFromParentToWorld The cumulative parent-to-world transformation matrix constructed by composition down the MeshTransformNode tree to the current node.
meshGroup Access structure for collision mesh data.
node The current MeshTransformNode in the recursion.

bool esp::physics::BulletRigidObject::isActive() override

Check whether object is being actively simulated, or sleeping. See btCollisionObject::isActive.

Returns true if active, false otherwise.

bool esp::physics::BulletRigidObject::setMotionType(MotionType mt) override

Set the MotionType of the object. If the object is ObjectType::SCENE it can only be MotionType::STATIC. If the object is ObjectType::OBJECT is can also be set to MotionType::KINEMATIC or MotionType::DYNAMIC. See btRigidBody::setCollisionFlags and btCollisionObject::CF_STATIC_OBJECT,CF_KINEMATIC_OBJECT.

Parameters
mt The desirved MotionType.
Returns true if successfully set, false otherwise.

void esp::physics::BulletRigidObject::shiftOrigin(const Magnum::Vector3& shift) override

Shift the object's local origin by translating all children of this BulletRigidObject and all components of its bObjectShape_.

Parameters
shift The translation to apply.

void esp::physics::BulletRigidObject::applyForce(const Magnum::Vector3& force, const Magnum::Vector3& relPos) override

Apply a force to an object. Does nothing for MotionType::STATIC and MotionType::KINEMATIC objects. Calls setActive(). See btRigidBody::applyForce.

Parameters
force The desired linear force on the object in the global coordinate system.
relPos The desired location of force application in the global coordinate system relative to the object's center of mass.

void esp::physics::BulletRigidObject::applyImpulse(const Magnum::Vector3& impulse, const Magnum::Vector3& relPos) override

Apply an impulse to an object. Directly modifies the object's velocity without requiring integration through simulation. Does nothing for MotionType::STATIC and MotionType::KINEMATIC objects. Calls setActive(). See btRigidBody::applyImpulse.

Parameters
impulse The desired impulse on the object in the global coordinate system.
relPos The desired location of impulse application in the global coordinate system relative to the object's center of mass.

void esp::physics::BulletRigidObject::applyTorque(const Magnum::Vector3& torque) override

Apply an internal torque to an object. Does nothing for MotionType::STATIC and MotionType::KINEMATIC objects. Calls setActive(). See btRigidBody::applyTorque.

Parameters
torque The desired torque on the object in the local coordinate system.

void esp::physics::BulletRigidObject::applyImpulseTorque(const Magnum::Vector3& impulse) override

Apply an internal impulse torque to an object. Does nothing for MotionType::STATIC and MotionType::KINEMATIC objects. Calls setActive(). See btRigidBody::applyTorqueImpulse.

Parameters
impulse The desired impulse torque on the object in the local coordinate system. Directly modifies the object's angular velocity without requiring integration through simulation.

void esp::physics::BulletRigidObject::setLinearVelocity(const Magnum::Vector3& linVel) override

Linear velocity setter for an object.

Parameters
linVel Linear velocity to set.

Does nothing for MotionType::KINEMATIC or MotionType::STATIC objects. Sets internal btRigidObject state. Treated as initial velocity during simulation simulation step.

void esp::physics::BulletRigidObject::setAngularVelocity(const Magnum::Vector3& angVel) override

Angular velocity setter for an object.

Parameters
angVel Angular velocity vector corresponding to world unit axis angles.

Does nothing for MotionType::KINEMATIC or MotionType::STATIC objects. Sets internal btRigidObject state. Treated as initial velocity during simulation simulation step.

Magnum::Vector3 esp::physics::BulletRigidObject::getLinearVelocity() const override

Virtual linear velocity getter for an object.

Returns Linear velocity of the object.

Magnum::Vector3 esp::physics::BulletRigidObject::getAngularVelocity() const override

Angular velocity getter for an object.

Returns Angular velocity vector corresponding to world unit axis angles.

double esp::physics::BulletRigidObject::getMass() override

Get the mass of the object. Returns 0.0 for RigidObjectType::SCENE. See btRigidBody::getInvMass.

Returns The mass of the object.

Magnum::Vector3 esp::physics::BulletRigidObject::getCOM() override

Get the center of mass (COM) of the object. For Bullet, COM is always the origin of the local coordinate system. Return [0,0,0] for RigidObjectType::SCENE. See btRigidBody::getCenterOfMassPosition.

Returns Object 3D center of mass in the global coordinate system.

Magnum::Vector3 esp::physics::BulletRigidObject::getInertiaVector() override

Get the diagonal of the inertia matrix for an object. If an object is aligned with its principle axii of inertia, the 3x3 inertia matrix can be reduced to a diagonal. This is expected for Bullet. See BulletRigidObject::setInertiaVector. See btRigidBody::getInvInertiaDiagLocal.

Returns The diagonal of the object's inertia matrix.

Magnum::Matrix3 esp::physics::BulletRigidObject::getInertiaMatrix() override

Get the 3x3 inertia matrix for an object. For Bullet, this will be a diagonal matrix. See getInertiaVector.

Returns The object's 3x3 inertia matrix.

double esp::physics::BulletRigidObject::getScale() override

Get the uniform scale of the object.

Returns The scalar uniform scale for the object relative to its initially loaded meshes.

double esp::physics::BulletRigidObject::getFrictionCoefficient() override

Get the scalar friction coefficient of the object. See btCollisionObject::getFriction.

Returns The scalar friction coefficient of the object.

double esp::physics::BulletRigidObject::getRestitutionCoefficient() override

Get the scalar coefficient of restitution of the object. See btCollisionObject::getRestitution.

Returns The scalar coefficient of restitution of the object.

double esp::physics::BulletRigidObject::getLinearDamping() override

Get the scalar linear damping coefficient of the object. See btRigidBody::getLinearDamping.

Returns The scalar linear damping coefficient of the object. 0.0 for RigidObjectType::SCENE.

double esp::physics::BulletRigidObject::getAngularDamping() override

Get the scalar angular damping coefficient of the object. See btRigidBody::getAngularDamping.

Returns The scalar angular damping coefficient of the object. 0.0 for RigidObjectType::SCENE.

double esp::physics::BulletRigidObject::getMargin()

Get the scalar collision margin of an object. Retun 0.0 for a RigidObjectType::SCENE. See btCompoundShape::getMargin.

Returns The scalar collision margin of the object.

void esp::physics::BulletRigidObject::setMass(const double mass) override

Set the mass of the object. See btRigidBody::setMassProps. Note that changing mass should affect inertia, but this is not done automatically. Does not affect RigidObjectType::SCENE.

Parameters
mass The new mass of the object.

void esp::physics::BulletRigidObject::setCOM(const Magnum::Vector3& COM) override

Set the center of mass (COM) of the object.

Parameters
COM Object 3D center of mass in the local coordinate system. !!! Currently not supported !!! All Bullet btRigidBody objects must have a COM located at thier local origins.

void esp::physics::BulletRigidObject::setInertiaVector(const Magnum::Vector3& inertia) override

Set the diagonal of the inertia matrix for the object. If an object is aligned with its principle axii of inertia, the 3x3 inertia matrix can be reduced to a diagonal. This is the requirement for Bullet btRigidBody objects. See btRigidBody::setMassProps. Does not affect RigidObjectType::SCENE.

Parameters
inertia The new diagonal for the object's inertia matrix.

void esp::physics::BulletRigidObject::setScale(const double scale) override

Set the uniform scale of the object.

Parameters
scale The new scalar uniform scale for the object relative to its initially loaded meshes.

void esp::physics::BulletRigidObject::setFrictionCoefficient(const double frictionCoefficient) override

Set the scalar friction coefficient of the object. See btCollisionObject::setFriction.

Parameters
frictionCoefficient The new scalar friction coefficient of the object.

void esp::physics::BulletRigidObject::setRestitutionCoefficient(const double restitutionCoefficient) override

Set the scalar coefficient of restitution of the object. See btCollisionObject::setRestitution.

Parameters
restitutionCoefficient The new scalar coefficient of restitution of the object.

void esp::physics::BulletRigidObject::setLinearDamping(const double linearDamping) override

Set the scalar linear damping coefficient of the object. See btRigidBody::setDamping. Does not affect RigidObjectType::SCENE.

Parameters
linearDamping The new scalar linear damping coefficient of the object.

void esp::physics::BulletRigidObject::setAngularDamping(const double angularDamping) override

Set the scalar angular damping coefficient for the object. See btRigidBody::setDamping. Does not affect RigidObjectType::SCENE.

Parameters
angularDamping The new scalar angular damping coefficient for the object.

void esp::physics::BulletRigidObject::setMargin(const double margin)

Set the scalar collision margin of an object. Does not affect RigidObjectType::SCENE. See btCompoundShape::setMargin.

Parameters
margin The new scalar collision margin of the object.

bool esp::physics::BulletRigidObject::isUsingBBCollisionShape() const

Public getter for usingBBCollisionShape_ set from configuration.

Returns usingBBCollisionShape_ is true if "useBoundingBoxForCollision" was set in object's configuration.

bool esp::physics::BulletRigidObject::contactTest()

Return result of a discrete contact test between the object and collision world.

Returns Whether or not the object is in contact with any other collision enabled objects.

See SimulationContactResultCallback

const Magnum::Range3D esp::physics::BulletRigidObject::getCollisionShapeAabb() const

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

Returns The Aabb.

bool esp::physics::BulletRigidObject::initializeSceneFinalize(const assets::ResourceManager& resMgr, const assets::PhysicsSceneAttributes::ptr physicsSceneAttributes, const std::vector<assets::CollisionMeshData>& meshGroup) override private

Initializes this BulletRigidObject as static scene geometry. See PhysicsManager::staticSceneObject_. Sets rigidObjectType_ to RigidObjectType::SCENE. See btCollisionObject.

Parameters
resMgr
physicsSceneAttributes The template structure defining relevant phyiscal parameters for the physical scene.
meshGroup The collision mesh data for the scene.
Returns true if initialized successfully, false otherwise.

bool esp::physics::BulletRigidObject::initializeObjectFinalize(const assets::ResourceManager& resMgr, const assets::PhysicsObjectAttributes::ptr physicsObjectAttributes, const std::vector<assets::CollisionMeshData>& meshGroup) override private

Finalize initialization of this BulletRigidObject as a MotionType::DYNAMIC object. See btRigidBody.

Parameters
resMgr Reference to resource manager, to access relevant components pertaining to the scene object
physicsObjectAttributes The template structure defining relevant phyiscal parameters for the object. See esp::assets::ResourceManager::physicsObjectLibrary_.
meshGroup The collision mesh data for the object.
Returns true if initialized successfully, false otherwise.

Variable documentation

bool esp::physics::BulletRigidObject::usingBBCollisionShape_ protected

If true, the object's bounding box will be used for collision once computed