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/entities/player.hpp raw
#pragma once
#include <SDL3/SDL.h>
#include "utils/math.hpp"
struct PlayerInputState
{
bool forward{};
bool left{};
bool backward{};
bool right{};
};
struct PlayerCollision
{
Vec3 pos{};
Vec3 vel{};
bool hit_x{};
bool hit_y{};
bool hit_z{};
};
struct Player
{
public:
Player();
Vec3 pos{};
Vec3 prev_pos{};
Vec3 vel{};
uint32_t yaw{};
int32_t pitch{};
float radius{0.5f};
float height{1.5f};
bool on_ground{false};
bool jump_pressed{false};
void computeMovement(const PlayerInputState& input);
void addLook(int dx, int dy);
void applyCollision(const PlayerCollision& col);
Vec3 interpolatedPos(double alpha) const;
double getAccX() const { return acc_x; }
double getAccZ() const { return acc_z; }
void respawn(const Vec3& spawn_pos);
private:
double acc_x{};
double acc_z{};
};