class
BulletPhysicsManagerDynamic scene and object manager interfacing with Bullet physics engine: https:/
Contents
Enables RigidObject simulation with MotionType::
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, const assets::PhysicsManagerAttributes::cptr _physicsManagerAttributes) 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.
-
auto castRay(const esp::
geo:: Ray& ray, double maxDistance = 100.0) -> RaycastResults override - Cast a ray into the collision world and return a RaycastResults with hit information.
Protected functions
- auto initPhysicsFinalize() -> bool override
- Finalize physics initialization: Setup staticSceneObject_ and initialize any other physics-related values.
-
auto addSceneFinalize(const std::
string& handle) -> 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::
string& handle, 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_ -
std::
shared_ptr<std:: map<const btCollisionObject*, int>> collisionObjToObjIds_
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,
const assets::PhysicsManagerAttributes::cptr _physicsManagerAttributes) explicit
Construct a BulletPhysicsManager with access to specific resourse assets.
Parameters | |
---|---|
_resourceManager | The esp:: |
_physicsManagerAttributes |
void esp:: physics:: BulletPhysicsManager:: stepPhysics(double dt) override
Step the physical world forward in time. Time may only advance in increments of fixedTimeStep_
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::
Parameters | |
---|---|
physObjectID | The object ID and key identifying the object in PhysicsManager:: |
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_
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_
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::
Parameters | |
---|---|
physObjectID | The object ID and key identifying the object in PhysicsManager:: |
Returns | The scalar collision margin of the object or esp:: |
double esp:: physics:: BulletPhysicsManager:: getSceneFrictionCoefficient() const override
Get the current friction coefficient of the scene collision geometry. See staticSceneObject_
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_
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::
Parameters | |
---|---|
physObjectID | The object ID and key identifying the object in PhysicsManager:: |
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::
Returns | The scene collision Aabb. |
---|
void esp:: physics:: BulletPhysicsManager:: debugDraw(const Magnum:: Matrix4& projTrans) const override
Render the debugging visualizations provided by Magnum::
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:: |
Returns | Whether or not the object is in contact with any other collision enabled objects. |
RaycastResults esp:: physics:: BulletPhysicsManager:: castRay(const esp:: geo:: Ray& ray,
double maxDistance = 100.0) override
Cast a ray into the collision world and return a RaycastResults with hit information.
Parameters | |
---|---|
ray | The ray to cast. Need not be unit length, but returned hit distances will be in units of ray length. |
maxDistance | The maximum distance along the ray direction to search. In units of ray length. |
Returns | The raycast results sorted by distance. |
bool esp:: physics:: BulletPhysicsManager:: addSceneFinalize(const std:: string& handle) override protected
Finalize scene initialization. Checks that the collision mesh can be used by Bullet. See BulletRigidObject::initializeScene. Bullet mesh conversion adapted from: https:/
Parameters | |
---|---|
handle | The handle of the attributes structure defining physical properties of the scene. |
Returns | true if successful and false otherwise |
bool esp:: physics:: BulletPhysicsManager:: makeAndAddRigidObject(int newObjectID,
const std:: string& handle,
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 |
handle | The handle to 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:: |
Returns | true if valid, false otherwise. |
Variable documentation
std:: shared_ptr<std:: map<const btCollisionObject*, int>> esp:: physics:: BulletPhysicsManager:: collisionObjToObjIds_ protected
keep a map of collision objects to object ids for quick lookups from Bullet collision checking.