#include #include "entities/camera.hpp" #include "floor_surface.hpp" namespace Nimbin { namespace Floor { void Mandelbrot::generate(float world_scale, float floor_y, double center_x, double center_y, double width) { _verts.clear(); _indices.clear(); // Single quad covering the floor. We use the existing 9-floats-per-vertex // layout: [pos(3) | normal(3) | color(3)], but here we *abuse* the color // slot to carry the complex-plane coordinate (cx, cy, 0). The shader // reads it from vColor when in Mandelbrot mode. const float ws = world_scale; const double half_w = width * 0.5; // Four corners of the floor in world space. // Match the layout so corners go around: BL, BR, TR, TL (looking down +Y). struct V { float x,y,z; double cx,cy; }; V corners[4] = { { -ws, floor_y, -ws, center_x - half_w, center_y - half_w }, // BL { ws, floor_y, -ws, center_x + half_w, center_y - half_w }, // BR { ws, floor_y, ws, center_x + half_w, center_y + half_w }, // TR { -ws, floor_y, ws, center_x - half_w, center_y + half_w }, // TL }; for (const V& v : corners) { _verts.push_back(v.x); _verts.push_back(v.y); _verts.push_back(v.z); // Normal — flat up. _verts.push_back(0.0f); _verts.push_back(1.0f); _verts.push_back(0.0f); // "Color" slot carries the complex-plane coord. _verts.push_back(static_cast(v.cx)); _verts.push_back(static_cast(v.cy)); _verts.push_back(0.0f); } // Two triangles: BL,BR,TR + BL,TR,TL _indices.push_back(0); _indices.push_back(1); _indices.push_back(2); _indices.push_back(0); _indices.push_back(2); _indices.push_back(3); } void Mandelbrot::draw(GlRenderer& gl, const Camera& cam, const Light& light) const { if (_verts.empty()) return; Mat4 view = buildViewMat4 (cam); Mat4 proj = gl.get_Projection(); Mat4 model = Mat4::identity (); 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.enable_MandelbrotMode(true); gl.set_ColorUseVertex (false); gl.draw_MeshColored (_verts.data(), static_cast(_verts.size() / 9), _indices.data(), static_cast(_indices.size())); gl.enable_MandelbrotMode(false); } } // namespace Floor } // namespace Nimbin