Initial commit.

This commit is contained in:
2025-12-05 21:14:29 -05:00
commit 0984dec745
13 changed files with 190 additions and 0 deletions

22
src/gen.c Normal file
View File

@@ -0,0 +1,22 @@
#include "include/gen.h"
#include "include/col.h"
#include "include/vol.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void gen(void) {
srand((unsigned int)time(NULL));
for (int x = 0; x < VOL_WIDTH; x++) {
for (int y = 0; y < VOL_HEIGHT; y++) {
for (int z = 0; z < VOL_DEPTH; z++) {
if (rand() % 2 == 0) vol_set_vox(x, y, z, COL_WHT);
else vol_set_vox(x, y, z, COL_BLK);
}
}
}
printf("Volume initialized.\n");
}

18
src/include/col.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef COL_H
#define COL_H
#include <stdint.h>
// An RGB color.
typedef struct {
uint8_t r, g, b;
} Col;
#define COL_WHT (Col) {255, 255, 255}
#define COL_GRY (Col) {127, 127, 127}
#define COL_BLK (Col) {0, 0, 0}
#define COL_RED (Col) {255, 0, 0}
#define COL_GRN (Col) {0, 255, 0}
#define COL_BLU (Col) {0, 0, 255}
#endif

6
src/include/gen.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef GEN_H
#define GEN_H
void gen(void);
#endif

0
src/include/main.h Normal file
View File

16
src/include/vol.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef VOL_H
#define VOL_H
#include "vox.h"
#include "col.h"
#define VOL_WIDTH 128
#define VOL_HEIGHT 128
#define VOL_DEPTH 128
// The volume in which our voxels may be found.
extern Vox volume[VOL_WIDTH][VOL_HEIGHT][VOL_DEPTH];
void vol_set_vox(int x, int y, int z, Col col);
#endif

13
src/include/vox.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef VOX_H
#define VOX_H
#include "col.h"
#include <stdint.h>
// A voxel.
typedef struct {
Col col;
} Vox;
#endif

21
src/main.c Normal file
View File

@@ -0,0 +1,21 @@
#include "include/main.h"
#include "include/gen.h"
#include "include/vol.h"
#include "include/vox.h"
#include <stdio.h>
int main(int argc, char** argv) {
printf("Hello, world.\n");
gen();
Vox testvox = volume[10][5][20];
printf(
"Test voxel is (%d, %d, %d)\n", testvox.col.r, testvox.col.g,
testvox.col.b
);
return 0;
}

12
src/vol.c Normal file
View File

@@ -0,0 +1,12 @@
#include "include/vol.h"
#include <stdlib.h>
Vox volume[VOL_WIDTH][VOL_HEIGHT][VOL_DEPTH];
void vol_set_vox(int x, int y, int z, Col col) {
if (x >= 0 && x < VOL_WIDTH && y >= 0 && y < VOL_HEIGHT && z >= 0 &&
z < VOL_DEPTH)
volume[x][y][z].col = col;
else exit(1);
}