Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Core::PhysicsEngine Class Reference

The physics engine manages creating and destroying physics objects for the physics simulation. More...

#include <PhysicsEngine.h>

Public Member Functions

 PhysicsEngine ()
 ~PhysicsEngine ()
void onPhysicsComponentDestroyed (entt::registry &registry, 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 Public Member Functions

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.

Private Attributes

btBroadphaseInterface * broadphase
btCollisionConfiguration * collisionConfiguration
btCollisionDispatcher * dispatcher
btConstraintSolver * solver
btDiscreteDynamicsWorld * dynamicsWorld

Detailed Description

The physics engine manages creating and destroying physics objects for the physics simulation.

Definition at line 44 of file PhysicsEngine.h.

Constructor & Destructor Documentation

◆ PhysicsEngine()

Engine::Core::PhysicsEngine::PhysicsEngine ( )

◆ ~PhysicsEngine()

Engine::Core::PhysicsEngine::~PhysicsEngine ( )

Member Function Documentation

◆ createBoxShape()

btCollisionShape * Engine::Core::PhysicsEngine::createBoxShape ( const glm::vec3 & halfExtents)
static

Creates a collision box.

Parameters
halfExtentsxyz 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
radiusin meters
heightin 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
verticeslist 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
surfaceNormalsurface normal of the plane
distanceFromOriginhow much to move the plane along the surface
Returns
Pointer to the created collision shape. Needs to be cleaned up by hand

◆ createRigidBody()

btRigidBody * Engine::Core::PhysicsEngine::createRigidBody ( const Physics::RigidBodyCreateInfo & info) const
nodiscard

Creates a rigid body for the physics simulation.

Parameters
infocreate 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
radiusin meters
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
verticeslist of vertex positions
indiceslist of triangle indices (triplets)
triangleMeshOutoutput 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
registrywhich registry the element was destroyed from
entitywhich 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
originWorld-space ray origin
directionRay direction. Does not need to be normalized.
maxDistanceMaximum ray length in meters
outHitFilled 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
bodyptr 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
deltaTimeSecondstime between this and the last frame in seconds

Member Data Documentation

◆ broadphase

btBroadphaseInterface* Engine::Core::PhysicsEngine::broadphase
private

Definition at line 161 of file PhysicsEngine.h.

◆ collisionConfiguration

btCollisionConfiguration* Engine::Core::PhysicsEngine::collisionConfiguration
private

Definition at line 162 of file PhysicsEngine.h.

◆ dispatcher

btCollisionDispatcher* Engine::Core::PhysicsEngine::dispatcher
private

Definition at line 163 of file PhysicsEngine.h.

◆ dynamicsWorld

btDiscreteDynamicsWorld* Engine::Core::PhysicsEngine::dynamicsWorld
private

Definition at line 165 of file PhysicsEngine.h.

◆ solver

btConstraintSolver* Engine::Core::PhysicsEngine::solver
private

Definition at line 164 of file PhysicsEngine.h.


The documentation for this class was generated from the following file:
  • /home/magerbeton/Documents/gl3-vulkan/Engine/include/Engine/Physics/PhysicsEngine.h