Physics (WIP)

This commit is contained in:
MrLetsplay 2022-11-09 13:46:19 +01:00
parent 8acf6ec363
commit 8738f94768
3 changed files with 19 additions and 2 deletions

View File

@ -180,6 +180,8 @@ int start() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, kekData.screenWidth, kekData.screenHeight); glViewport(0, 0, kekData.screenWidth, kekData.screenHeight);
Physics::step(kekData.lastFrameTime);
for(auto cb : kekData.input->periodicCallbacks) { for(auto cb : kekData.input->periodicCallbacks) {
cb.second(kekData.window); cb.second(kekData.window);
} }

View File

@ -12,12 +12,25 @@ void init() {
btCollisionDispatcher *dispatcher = new btCollisionDispatcher(collisionConf); btCollisionDispatcher *dispatcher = new btCollisionDispatcher(collisionConf);
btBroadphaseInterface *overlappingPairCache = new btDbvtBroadphase(); btBroadphaseInterface *overlappingPairCache = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver *solver = new btSequentialImpulseConstraintSolver(); btSequentialImpulseConstraintSolver *solver = new btSequentialImpulseConstraintSolver();
btDiscreteDynamicsWorld *world = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConf); kekData.physics->world = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConf);
world->setGravity(btVector3(0, -10, 0)); kekData.physics->world->setGravity(btVector3(0, -10, 0));
btCollisionShape *shape = new btBoxShape(btVector3(1, 1, 1));
btDefaultMotionState *state = new btDefaultMotionState();
btRigidBody *body = new btRigidBody(1, state, shape);
kekData.physics->world->addRigidBody(body);
} }
void destroy() { void destroy() {
delete kekData.physics; delete kekData.physics;
} }
void step(float deltaT) {
kekData.physics->world->stepSimulation(deltaT, 100);
//btRigidBody *body = btRigidBody::upcast(kekData.physics->world->getCollisionObjectArray()[0]);
//btTransform &t = body->getWorldTransform();
//btVector3 &vec = t.getOrigin();
}
} }

View File

@ -5,4 +5,6 @@ namespace kek::Physics {
void init(); void init();
void destroy(); void destroy();
void step(float deltaT);
} }