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/camera.hpp 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;
}