Nimbin[12]?SDL & Graphics / sdl3_3d_oop_basic_game / src/entities/player.hpp

sdl3_3d_oop_basic_game git · main

SDL3 3D OOP basic game (entities, systems, CMake)

sdl3 3d c++ game cmake · first commit 2026-04-19 · last commit 2026-04-19 (7 months ago) · synced 1 hour ago · upstream: git.ide3.de/chfis005/sdl3_3d_oop_basic_game

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.gz
src/entities/player.hpp 906 B · 57 lines 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{};
};