Nimbin[12]?SDL & Graphics / sdl3_3d_oop_basic_game / src/entities/camera.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/camera.hpp 826 B · 43 lines raw
#pragma once

#include <SDL3/SDL.h>

#include "utils/math.hpp"
#include "entities/player.hpp"

struct Camera {
    Vec3 pos{};
    uint32_t yaw{};
    int32_t pitch{};
    void syncFromPlayer(const Player& player, double alpha)
    {
        pos = player.interpolatedPos(alpha);
        yaw = player.yaw;
        pitch = player.pitch;
    }
};

inline void buildViewMatrix(const Camera& cam, double out[9])
{
    double bin = SDL_PI_D / 2147483648.0;

    double yaw   = bin * cam.yaw;
    double pitch = bin * cam.pitch;

    double cy = SDL_cos(yaw);
    double sy = SDL_sin(yaw);
    double cp = SDL_cos(pitch);
    double sp = SDL_sin(pitch);

    out[0] = cy;
    out[1] = 0;
    out[2] = -sy;

    out[3] = sy * sp;
    out[4] = cp;
    out[5] = cy * sp;

    out[6] = sy * cp;
    out[7] = -sp;
    out[8] = cy * cp;
}