The physics engine manages creating and destroying physics objects for the physics simulation.
More...
#include <PhysicsEngine.h>
|
| | PhysicsEngine () |
| | ~PhysicsEngine () |
| void | onPhysicsComponentDestroyed (entt::registry ®istry, entt::entity entity) |
| | Cleans up the hit box pointers and motion state if applicable.
|
| void | update (float deltaTimeSeconds) |
| | Steps the physics simulation by 1/120th of a second. The idea of the engine is that it should run on 120hz so the update rate of the physics engine should be quite close to it.
|
| btDiscreteDynamicsWorld * | getDynamicsWorld () const |
| | Gets the world where the physics simulation is performed inside.
|
| bool | raycastClosest (const glm::vec3 &origin, const glm::vec3 &direction, float maxDistance, Physics::RaycastHit &outHit) const |
| | Casts a ray through the physics world and returns the closest hit, if any.
|
| btRigidBody * | createRigidBody (const Physics::RigidBodyCreateInfo &info) const |
| | Creates a rigid body for the physics simulation.
|
| void | removeRigidBody (btRigidBody *body) const |
| | Removes a rigid body from the physics simulation.
|
| void | debugDrawAll () const |
| | Draws debug visualization of all collision shapes in the world.
|
|
| static btCollisionShape * | createBoxShape (const glm::vec3 &halfExtents) |
| | Creates a collision box.
|
| static btCollisionShape * | createSphereShape (float radius) |
| | Creates a collision sphere.
|
| static btCollisionShape * | createCapsuleShape (float radius, float height) |
| | creates a capsule with a height and a radius.
|
| static btCollisionShape * | createPlaneShape (const glm::vec3 &surfaceNormal, float distanceFromOrigin) |
| | Creates a plane from.
|
| static btCollisionShape * | createConvexHullShape (const std::vector< glm::vec3 > &vertices) |
| | Creates a convex hull collision shape from a set of vertices.
|
| static btCollisionShape * | createTriangleMeshShape (const std::vector< glm::vec3 > &vertices, const std::vector< uint32_t > &indices, btTriangleMesh *&triangleMeshOut) |
| | Creates a triangle mesh collision shape from vertices and indices.
|
| static btCompoundShape * | createCompoundShape () |
| | Creates an empty compound shape for combining multiple collision shapes.
|
The physics engine manages creating and destroying physics objects for the physics simulation.
Definition at line 44 of file PhysicsEngine.h.
◆ PhysicsEngine()
| Engine::Core::PhysicsEngine::PhysicsEngine |
( |
| ) |
|
◆ ~PhysicsEngine()
| Engine::Core::PhysicsEngine::~PhysicsEngine |
( |
| ) |
|
◆ createBoxShape()
| btCollisionShape * Engine::Core::PhysicsEngine::createBoxShape |
( |
const glm::vec3 & | halfExtents | ) |
|
|
static |
Creates a collision box.
- Parameters
-
| halfExtents | xyz half extents |
- Returns
- Pointer to the created collision shape. Needs to be cleaned up by hand
◆ createCapsuleShape()
| btCollisionShape * Engine::Core::PhysicsEngine::createCapsuleShape |
( |
float | radius, |
|
|
float | height ) |
|
static |
creates a capsule with a height and a radius.
- Parameters
-
| radius | in meters |
| height | in meters |
- Returns
- Pointer to the created collision shape. Needs to be cleaned up by hand
◆ createCompoundShape()
| btCompoundShape * Engine::Core::PhysicsEngine::createCompoundShape |
( |
| ) |
|
|
static |
Creates an empty compound shape for combining multiple collision shapes.
- Returns
- Pointer to the created compound shape. Needs to be cleaned up by hand
◆ createConvexHullShape()
| btCollisionShape * Engine::Core::PhysicsEngine::createConvexHullShape |
( |
const std::vector< glm::vec3 > & | vertices | ) |
|
|
static |
Creates a convex hull collision shape from a set of vertices.
- Parameters
-
| vertices | list of vertex positions to create the hull from |
- Returns
- Pointer to the created collision shape. Needs to be cleaned up by hand
◆ createPlaneShape()
| btCollisionShape * Engine::Core::PhysicsEngine::createPlaneShape |
( |
const glm::vec3 & | surfaceNormal, |
|
|
float | distanceFromOrigin ) |
|
static |
Creates a plane from.
- Parameters
-
| surfaceNormal | surface normal of the plane |
| distanceFromOrigin | how much to move the plane along the surface |
- Returns
- Pointer to the created collision shape. Needs to be cleaned up by hand
◆ createRigidBody()
Creates a rigid body for the physics simulation.
- Parameters
-
| info | create info which defines how the rigid body should behave in the simulation |
- Returns
- Pointer to the created collision shape. Needs to be cleaned up manually by hand
◆ createSphereShape()
| btCollisionShape * Engine::Core::PhysicsEngine::createSphereShape |
( |
float | radius | ) |
|
|
static |
Creates a collision sphere.
- Parameters
-
- Returns
- Pointer to the created collision shape. Needs to be cleaned up by hand
◆ createTriangleMeshShape()
| btCollisionShape * Engine::Core::PhysicsEngine::createTriangleMeshShape |
( |
const std::vector< glm::vec3 > & | vertices, |
|
|
const std::vector< uint32_t > & | indices, |
|
|
btTriangleMesh *& | triangleMeshOut ) |
|
static |
Creates a triangle mesh collision shape from vertices and indices.
- Parameters
-
| vertices | list of vertex positions |
| indices | list of triangle indices (triplets) |
| triangleMeshOut | output parameter for the btTriangleMesh (caller must delete) |
- Returns
- Pointer to the created collision shape. Needs to be cleaned up by hand
- Note
- The returned shape uses the triangleMeshOut, which must be kept alive and deleted separately when the shape is no longer needed
◆ debugDrawAll()
| void Engine::Core::PhysicsEngine::debugDrawAll |
( |
| ) |
const |
Draws debug visualization of all collision shapes in the world.
Iterates through all rigid bodies and calls debugDraw() on their associated PhysicsBodyComponent. Only draws if CollisionComponent::isDebugDrawEnabled().
◆ getDynamicsWorld()
| btDiscreteDynamicsWorld * Engine::Core::PhysicsEngine::getDynamicsWorld |
( |
| ) |
const |
|
nodiscard |
Gets the world where the physics simulation is performed inside.
- Returns
- Pointer to the physics world
◆ onPhysicsComponentDestroyed()
| void Engine::Core::PhysicsEngine::onPhysicsComponentDestroyed |
( |
entt::registry & | registry, |
|
|
entt::entity | entity ) |
Cleans up the hit box pointers and motion state if applicable.
- Parameters
-
| registry | which registry the element was destroyed from |
| entity | which entity the component belonged to |
◆ raycastClosest()
| bool Engine::Core::PhysicsEngine::raycastClosest |
( |
const glm::vec3 & | origin, |
|
|
const glm::vec3 & | direction, |
|
|
float | maxDistance, |
|
|
Physics::RaycastHit & | outHit ) const |
|
nodiscard |
Casts a ray through the physics world and returns the closest hit, if any.
- Parameters
-
| origin | World-space ray origin |
| direction | Ray direction. Does not need to be normalized. |
| maxDistance | Maximum ray length in meters |
| outHit | Filled with world-space hit data when the function returns true |
- Returns
- true if the ray hit a collision object
◆ removeRigidBody()
| void Engine::Core::PhysicsEngine::removeRigidBody |
( |
btRigidBody * | body | ) |
const |
Removes a rigid body from the physics simulation.
- Parameters
-
| body | ptr to the rigid body to remove |
◆ update()
| void Engine::Core::PhysicsEngine::update |
( |
float | deltaTimeSeconds | ) |
|
Steps the physics simulation by 1/120th of a second. The idea of the engine is that it should run on 120hz so the update rate of the physics engine should be quite close to it.
- Parameters
-
| deltaTimeSeconds | time between this and the last frame in seconds |
◆ broadphase
| btBroadphaseInterface* Engine::Core::PhysicsEngine::broadphase |
|
private |
◆ collisionConfiguration
| btCollisionConfiguration* Engine::Core::PhysicsEngine::collisionConfiguration |
|
private |
◆ dispatcher
| btCollisionDispatcher* Engine::Core::PhysicsEngine::dispatcher |
|
private |
◆ dynamicsWorld
| btDiscreteDynamicsWorld* Engine::Core::PhysicsEngine::dynamicsWorld |
|
private |
◆ solver
| btConstraintSolver* Engine::Core::PhysicsEngine::solver |
|
private |
The documentation for this class was generated from the following file:
- /home/magerbeton/Documents/gl3-vulkan/Engine/include/Engine/Physics/PhysicsEngine.h