5#include "glm/gtc/type_ptr.inl"
16 solver =
new btSequentialImpulseConstraintSolver();
21 registry.on_destroy<
Ecs::SimulatesPhysics>( ).connect<&PhysicsEngine::onPhysicsComponentDestroyed>(
this);
26 for (
int i = 0; i <
dynamicsWorld->getNumCollisionObjects(); i++ )
28 btCollisionObject *
object =
dynamicsWorld->getCollisionObjectArray()[i];
29 if (
object !=
nullptr )
31 btRigidBody * body = btRigidBody::upcast(
object );
32 if ( body && body->getMotionState() )
34 delete body->getMotionState();
51 if (physics.rigidBody)
54 delete physics.rigidBody->getMotionState();
55 delete physics.rigidBody;
58 if (physics.collisionShape)
60 delete physics.collisionShape;
67 dynamicsWorld->stepSimulation( deltaTimeSeconds, 10, 1.0f/120.0f);
82 return new btSphereShape( radius );
87 return new btCapsuleShape( radius, height );
92 return new btStaticPlaneShape(
bt::getVec3(surfaceNormal), distanceFromOrigin);
97 btTransform startTransform;
98 startTransform.setIdentity();
99 startTransform.setFromOpenGLMatrix(glm::value_ptr(info.
transform));
101 btVector3 localInertia(0, 0, 0);
102 if (info.
mass != 0.0f)
104 info.
shape->calculateLocalInertia(info.
mass, localInertia);
107 auto* motionState =
new btDefaultMotionState(startTransform);
108 btRigidBody::btRigidBodyConstructionInfo rbInfo(info.
mass, motionState, info.
shape, localInertia);
112 auto* body =
new btRigidBody(rbInfo);
123 if (body->getMotionState())
125 delete body->getMotionState();
#define TRACY_ZONE_SCOPED_NAMED(name)
static entt::registry & get()
Gets the registry for all components.
btCollisionDispatcher * dispatcher
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 ...
void onPhysicsComponentDestroyed(entt::registry ®istry, entt::entity entity)
Cleans up the hit box pointers and motion state if applicable.
static btCollisionShape * createBoxShape(const glm::vec3 &halfExtents)
Creates a collision box.
btCollisionConfiguration * collisionConfiguration
btBroadphaseInterface * broadphase
static btCollisionShape * createSphereShape(float radius)
Creates a collision sphere.
btRigidBody * createRigidBody(const RigidBodyCreateInfo &info) const
Creates a rigid body for the physics simulation.
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.
btConstraintSolver * solver
void removeRigidBody(btRigidBody *body) const
Removes a rigid body from the physics simulation.
btDiscreteDynamicsWorld * dynamicsWorld
Log category system implementation.
btVector3 getVec3(glm::vec3 v)
Tag for EnTT which tags entities which should simulate physics.
Rigid body create info is used to create a rigid body. It delivers all informations like the initial ...
glm::mat4 transform
initial location for the rigid body
float restitution
energy absorption 0.0f means full absorption on impact, 0.5f half of the energy is maintained after i...
float friction
friction 0.0f - 1.0f. 0 is ice 0.3f - 0.5f wood or plastic. 0.7f - 1.0f High friction
btCollisionShape * shape
pointer to the collision shape
float mass
mass in Kilograms. Mass of 0 is a static object --> immovable