Initial commit.
This commit is contained in:
22
src/gen.c
Normal file
22
src/gen.c
Normal 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
18
src/include/col.h
Normal 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
6
src/include/gen.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef GEN_H
|
||||
#define GEN_H
|
||||
|
||||
void gen(void);
|
||||
|
||||
#endif
|
||||
0
src/include/main.h
Normal file
0
src/include/main.h
Normal file
16
src/include/vol.h
Normal file
16
src/include/vol.h
Normal 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
13
src/include/vox.h
Normal 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
21
src/main.c
Normal 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
12
src/vol.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user