Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / src/entities/camera.hpp

sdl_runtime_compiler git · main

SDL3 game for running and compiling code at runtime

sdl3 c++ compiler dlopen cmake · first commit 2026-04-19 · last commit 2026-07-03 (3 months ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-runtime-compiler

C++ 72.3% C 26.2%
git clone https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler/archive/sdl_runtime_compiler.tar.gz
src/entities/camera.hpp 846 B · 46 lines raw
#pragma once

#include <SDL3/SDL.h>

#include "entities/player.hpp"
#include "utils/config.hpp"
#include "utils/globals.hpp"

namespace
Nimbin
{

struct Camera
{
    Vec3 pos  {};
    Vec3 fwd  {};
    Vec3 right{};

    double   yaw_r  {};
    double   pitch_r{};

    int32_t  pitch  {};
    uint32_t yaw    {};

    void sync_FromPlayer(const Player& player)
    {
        pos   = player.prev_pos;
        yaw   = player.yaw;
        pitch = player.pitch;

        yaw_r   = Config::Physics::binrad * yaw;
        pitch_r = Config::Physics::binrad * pitch;
        fwd = {
           -SDL_sin(yaw_r) * SDL_cos(pitch_r),
            SDL_sin(pitch_r),
           -SDL_cos(yaw_r) * SDL_cos(pitch_r)
        };
        right = {
             SDL_cos(yaw_r),
             0.0,
            -SDL_sin(yaw_r)
        };
    }
};

} // namespace Nimbin