Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / src/entities/solid_box.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/solid_box.hpp 1.6 KB · 51 lines raw
#pragma once

#include "entities/camera.hpp"
#include "entities/game_object.hpp"
#include "rendering/gl_renderer.hpp"
#include "utils/light.hpp"

namespace
Nimbin
{

struct SolidBox : public GameObject
{
    SDL_FColor fill_color { 0.55f, 0.55f, 0.75f, 1.0f };
    SDL_FColor wire_color { 0.75f, 0.75f, 0.95f, 1.0f };

    SolidBox(Vec3       centre,
             Vec3       half_extents,
             SDL_FColor fill          = {0.55f, 0.55f, 0.75f, 1.0f},
             SDL_FColor wire          = {0.75f, 0.75f, 0.95f, 1.0f},
             bool       interactable_ = false)
        : GameObject(
              centre,
              ObjectType::Prop,
              CollisionShape{ half_extents },
              RigidBody{ PhysicsMode::Static },
              false, interactable_, true)
        , fill_color(fill) , wire_color(wire)
    {}

    void draw(GlRenderer& gl, const Camera& cam, const Light& light) const override
    {
        const float hx = static_cast<float>(shape.half_extents.x);
        const float hy = static_cast<float>(shape.half_extents.y);
        const float hz = static_cast<float>(shape.half_extents.z);

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

        gl.set_Wireframe(false);
        gl.set_MVP      (model, mvp);
        gl.set_NormalMat(model);
        gl.set_Light    (light);
        gl.set_Color    (fill_color.r, fill_color.g, fill_color.b);
        gl.draw_Box     (hx, hy, hz);
    }
};

} // namespace Nimbin