Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
EngineCore::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.
btRigidBody * createRigidBody (const RigidBodyCreateInfo &info) const
 Creates a rigid body for the physics simulation.
void removeRigidBody (btRigidBody *body) const
 Removes a rigid body from the physics simulation.

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.

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.

Author
Konstantin Passig
Date
31.12.2025

Definition at line 32 of file PhysicsEngine.h.

Constructor & Destructor Documentation

◆ PhysicsEngine()

EngineCore::PhysicsEngine::PhysicsEngine ( )

Definition at line 11 of file PhysicsEngine.cpp.

References broadphase, collisionConfiguration, dispatcher, dynamicsWorld, Ecs::RegistryManager::get(), and solver.

Here is the call graph for this function:

◆ ~PhysicsEngine()

EngineCore::PhysicsEngine::~PhysicsEngine ( )

Definition at line 24 of file PhysicsEngine.cpp.

References broadphase, collisionConfiguration, dispatcher, dynamicsWorld, and solver.

Member Function Documentation

◆ createBoxShape()

btCollisionShape * EngineCore::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

Definition at line 75 of file PhysicsEngine.cpp.

References bt::getVec3().

Here is the call graph for this function:

◆ createCapsuleShape()

btCollisionShape * EngineCore::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

Definition at line 85 of file PhysicsEngine.cpp.

◆ createPlaneShape()

btCollisionShape * EngineCore::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

Definition at line 90 of file PhysicsEngine.cpp.

References bt::getVec3().

Here is the call graph for this function:

◆ createRigidBody()

btRigidBody * EngineCore::PhysicsEngine::createRigidBody ( const 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

Definition at line 95 of file PhysicsEngine.cpp.

References dynamicsWorld, EngineCore::RigidBodyCreateInfo::friction, EngineCore::RigidBodyCreateInfo::mass, EngineCore::RigidBodyCreateInfo::restitution, EngineCore::RigidBodyCreateInfo::shape, and EngineCore::RigidBodyCreateInfo::transform.

Referenced by EngineCore::PhysicsBodyComponent::createRigidBody().

Here is the caller graph for this function:

◆ createSphereShape()

btCollisionShape * EngineCore::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

Definition at line 80 of file PhysicsEngine.cpp.

◆ getDynamicsWorld()

btDiscreteDynamicsWorld * EngineCore::PhysicsEngine::getDynamicsWorld ( ) const
nodiscard

Gets the world where the physics simulation is performed inside.

Returns
Pointer to the physics world

Definition at line 70 of file PhysicsEngine.cpp.

References dynamicsWorld.

Referenced by EngineCore::PhysicsBodyComponent::processCollisions(), EngineCore::PhysicsBodyComponent::registerCollision(), and EngineCore::PhysicsBodyComponent::unregisterCollision().

Here is the caller graph for this function:

◆ onPhysicsComponentDestroyed()

void EngineCore::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

Definition at line 48 of file PhysicsEngine.cpp.

References dynamicsWorld.

◆ removeRigidBody()

void EngineCore::PhysicsEngine::removeRigidBody ( btRigidBody * body) const

Removes a rigid body from the physics simulation.

Parameters
bodyptr to the rigid body to remove

Definition at line 118 of file PhysicsEngine.cpp.

References dynamicsWorld.

Referenced by EngineCore::PhysicsBodyComponent::destroyRigidBody().

Here is the caller graph for this function:

◆ update()

void EngineCore::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

Definition at line 64 of file PhysicsEngine.cpp.

References dynamicsWorld, and TRACY_ZONE_SCOPED_NAMED.

Referenced by EngineCore::Engine::update().

Here is the caller graph for this function:

Member Data Documentation

◆ broadphase

btBroadphaseInterface* EngineCore::PhysicsEngine::broadphase
private

Definition at line 99 of file PhysicsEngine.h.

Referenced by PhysicsEngine(), and ~PhysicsEngine().

◆ collisionConfiguration

btCollisionConfiguration* EngineCore::PhysicsEngine::collisionConfiguration
private

Definition at line 100 of file PhysicsEngine.h.

Referenced by PhysicsEngine(), and ~PhysicsEngine().

◆ dispatcher

btCollisionDispatcher* EngineCore::PhysicsEngine::dispatcher
private

Definition at line 101 of file PhysicsEngine.h.

Referenced by PhysicsEngine(), and ~PhysicsEngine().

◆ dynamicsWorld

btDiscreteDynamicsWorld* EngineCore::PhysicsEngine::dynamicsWorld
private

◆ solver

btConstraintSolver* EngineCore::PhysicsEngine::solver
private

Definition at line 102 of file PhysicsEngine.h.

Referenced by PhysicsEngine(), and ~PhysicsEngine().


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