Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / src/entities/plate.cpp

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/plate.cpp 1.6 KB · 61 lines raw
#include <SDL3/SDL.h>

#include "entities/camera.hpp"
#include "plate.hpp"
#include "rendering/gl_renderer.hpp"

namespace
Nimbin
{

void
Plate::tick(double dt)
{
    hover_phase += dt * 2.0;
    pos.y = base_pos.y + SDL_sin(hover_phase) * 0.05;

    if (pulse > 0.0) {
        pulse -= dt * 1.5;
        if (pulse < 0.0) pulse = 0.0;
    }

    was_active = active;
}


void
Plate::draw(GlRenderer& gl, const Camera& cam, const Light& light) const
{
    const float half_x = static_cast<float>(shape.half_extents.x);
    const float half_y = static_cast<float>(shape.half_extents.y);
    const float half_z = static_cast<float>(shape.half_extents.z);

    Mat4 view  = buildViewMat4(cam);
    Mat4 proj  = gl.get_Projection();
    Mat4 model = buildModelMat4(pos, yaw);
    Mat4 mvp   = Mat4::mul(proj, Mat4::mul(view, model));

    float boost = static_cast<float>(active ? 1.0 : 0.6) +
                  static_cast<float>(pulse) * 0.4f;
    if (boost > 1.0f) boost = 1.0f;

    const float color_r = fill_color.r * boost;
    const float color_g = fill_color.g * boost;
    const float color_b = fill_color.b * boost;

    gl.set_Wireframe(false);
    gl.set_MVP      (model, mvp);
    gl.set_NormalMat(model);
    gl.set_Light    (light);
    gl.set_Color    (color_r, color_g, color_b);
    gl.set_Emissive (color_r, color_g, color_b, boost);
    gl.draw_Box     (half_x, half_y, half_z);
    gl.set_Emissive (0.0f, 0.0f, 0.0f, 0.0f);

    gl.set_Wireframe(false);
    gl.set_MVP      (model, mvp);
    gl.set_Color    (wire_color.r, wire_color.g, wire_color.b);
    gl.draw_Box     (half_x, half_y, half_z);
}

} // namespace Nimbin