Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
PhysicsEngine.h
Go to the documentation of this file.
1#pragma once
2
3#include <btBulletDynamicsCommon.h>
4#include <glm/mat4x4.hpp>
5#include <glm/vec3.hpp>
6
7namespace Engine
8{
9 namespace Physics
10 {
12 {
13 glm::vec3 point{ 0.0f };
14 glm::vec3 normal{ 0.0f };
15 float fraction = 0.0f;
16 float distance = 0.0f;
17 const btCollisionObject* collisionObject = nullptr;
18 };
19
25 {
27 glm::mat4 transform {1.0f};
29 float mass = 1.0f;
31 btCollisionShape* shape = nullptr;
33 float friction = 0.5f;
35 float restitution = 0.0f;
36 };
37 }
38
39 namespace Core
40 {
45 {
46 public:
49
55 void onPhysicsComponentDestroyed( entt::registry & registry, entt::entity entity );
56
62 void update(float deltaTimeSeconds);
63
68 [[nodiscard]] btDiscreteDynamicsWorld * getDynamicsWorld() const;
69
78 [[nodiscard]] bool raycastClosest(
79 const glm::vec3& origin,
80 const glm::vec3& direction,
81 float maxDistance,
83 ) const;
84
90 static btCollisionShape * createBoxShape(const glm::vec3& halfExtents);
96 static btCollisionShape * createSphereShape(float radius);
103 static btCollisionShape * createCapsuleShape(float radius, float height);
110 static btCollisionShape * createPlaneShape(const glm::vec3& surfaceNormal, float distanceFromOrigin);
111
117 static btCollisionShape * createConvexHullShape(const std::vector<glm::vec3>& vertices);
118
128 static btCollisionShape * createTriangleMeshShape(
129 const std::vector<glm::vec3>& vertices,
130 const std::vector<uint32_t>& indices,
131 btTriangleMesh*& triangleMeshOut);
132
137 static btCompoundShape * createCompoundShape();
138
144 [[nodiscard]] btRigidBody * createRigidBody( const Physics::RigidBodyCreateInfo & info ) const;
145
150 void removeRigidBody(btRigidBody* body ) const;
151
158 void debugDrawAll() const;
159
160 private:
161 btBroadphaseInterface* broadphase;
162 btCollisionConfiguration* collisionConfiguration;
163 btCollisionDispatcher* dispatcher;
164 btConstraintSolver* solver;
165 btDiscreteDynamicsWorld* dynamicsWorld;
166 };
167 }
168}
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.
btCollisionDispatcher * dispatcher
void debugDrawAll() const
Draws debug visualization of all collision shapes in the world.
btConstraintSolver * solver
btRigidBody * createRigidBody(const Physics::RigidBodyCreateInfo &info) const
Creates a rigid body for the physics simulation.
static btCollisionShape * createConvexHullShape(const std::vector< glm::vec3 > &vertices)
Creates a convex hull collision shape from a set of vertices.
btDiscreteDynamicsWorld * getDynamicsWorld() const
Gets the world where the physics simulation is performed inside.
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.
btCollisionConfiguration * collisionConfiguration
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 ...
btBroadphaseInterface * broadphase
void removeRigidBody(btRigidBody *body) const
Removes a rigid body from the physics simulation.
static btCollisionShape * createBoxShape(const glm::vec3 &halfExtents)
Creates a collision box.
void onPhysicsComponentDestroyed(entt::registry &registry, entt::entity entity)
Cleans up the hit box pointers and motion state if applicable.
static btCompoundShape * createCompoundShape()
Creates an empty compound shape for combining multiple collision shapes.
static btCollisionShape * createSphereShape(float radius)
Creates a collision sphere.
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.
btDiscreteDynamicsWorld * dynamicsWorld
Core audio subsystem owning the miniaudio engine and managing playback.
Definition AudioConfig.h:9
const btCollisionObject * collisionObject
Rigid body create info is used to create a rigid body. It delivers all informations like the initial ...
btCollisionShape * shape
pointer to the collision shape
float friction
friction 0.0f - 1.0f. 0 is ice 0.3f - 0.5f wood or plastic. 0.7f - 1.0f High friction
float restitution
energy absorption 0.0f means full absorption on impact, 0.5f half of the energy is maintained after i...
glm::mat4 transform
initial location for the rigid body
float mass
mass in Kilograms. Mass of 0 is a static object --> immovable