sdl3_3d_oop_basic_game git · main
SDL3 3D OOP basic game (entities, systems, CMake)
C++ 99%git clone https://git.christianimmanuel.de/sdl-graphics/sdl3_3d_oop_basic_game.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl3_3d_oop_basic_game/archive/sdl3_3d_oop_basic_game.tar.gzsrc/systems/physics_system.cpp raw
#include "systems/physics_system.hpp"
#include <SDL3/SDL.h>
void PhysicsSystem::update(Player& p, double acc_x, double acc_z, double dt) {
dt = SDL_min(dt, 1.0 / 30.0);
double rate = 6.0;
double drag = SDL_exp(-dt * rate);
double diff = 1.0 - drag;
double grav = 25.0;
double vx = p.vel.x;
double vy = p.vel.y;
double vz = p.vel.z;
p.vel.x -= vx * diff;
p.vel.y -= grav * dt;
p.vel.z -= vz * diff;
p.vel.x += diff * acc_x / rate;
p.vel.z += diff * acc_z / rate;
p.pos.x += (dt - diff/rate) * acc_x / rate + diff * vx / rate;
p.pos.y += -0.5 * grav * dt * dt + vy * dt;
p.pos.z += (dt - diff/rate) * acc_z / rate + diff * vz / rate;
}