Marching cubes.

This commit is contained in:
2025-12-06 00:00:19 -05:00
parent c82e918a1e
commit d671b124b0
7 changed files with 387 additions and 0 deletions

51
src/render.c Normal file
View File

@@ -0,0 +1,51 @@
#include "include/render.h"
#include "include/vol.h"
#include <raylib.h>
void render(void) {
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Terrin");
Camera3D cam = {0};
cam.position =
(Vector3){VOL_WIDTH / 2.f, VOL_HEIGHT * .75f, VOL_DEPTH / 2.f};
cam.target = (Vector3){0, 0, 0};
cam.up = (Vector3){0.0f, 1.0f, 0.0f};
cam.fovy = 70.f;
cam.projection = CAMERA_PERSPECTIVE;
SetTargetFPS(110);
while (!WindowShouldClose()) {
UpdateCamera(&cam, CAMERA_FREE);
BeginDrawing();
ClearBackground((Color){0, 0, 0, 0});
BeginMode3D(cam);
for (int x = 0; x < VOL_WIDTH; x++) {
for (int y = 0; y < VOL_HEIGHT; y++) {
for (int z = 0; z < VOL_DEPTH; z++) {
Pt v = volume[x][y][z];
DrawSphere(
(Vector3){(float)x, (float)y, (float)z}, 0.2f,
(Color){v.col.r, v.col.g, v.col.b, 255}
);
}
}
}
EndMode3D();
DrawFPS(10, 10);
EndDrawing();
}
CloseWindow();
}