Compare commits
No commits in common. "bdcffa97f6590fd3c4fcd50eee4b16539de302b5" and "2b23476c4050dec1fd38a5d0b062dd19846acf04" have entirely different histories.
bdcffa97f6
...
2b23476c40
15 changed files with 30 additions and 45 deletions
Binary file not shown.
BIN
.vs/samcraft/v17/.suo
Normal file
BIN
.vs/samcraft/v17/.suo
Normal file
Binary file not shown.
BIN
.vs/samcraft/v17/Browse.VC.db
Normal file
BIN
.vs/samcraft/v17/Browse.VC.db
Normal file
Binary file not shown.
BIN
.vs/samcraft/v17/Solution.VC.db
Normal file
BIN
.vs/samcraft/v17/Solution.VC.db
Normal file
Binary file not shown.
BIN
.vs/samcraft/v17/ipch/AutoPCH/15b5053cee312fd9/MAIN.ipch
Normal file
BIN
.vs/samcraft/v17/ipch/AutoPCH/15b5053cee312fd9/MAIN.ipch
Normal file
Binary file not shown.
BIN
.vs/samcraft/v17/ipch/AutoPCH/66ac3c548eeaaf67/RMODELS.ipch
Normal file
BIN
.vs/samcraft/v17/ipch/AutoPCH/66ac3c548eeaaf67/RMODELS.ipch
Normal file
Binary file not shown.
BIN
.vs/samcraft/v17/ipch/AutoPCH/6b6ca287a604beb4/RMODELS.ipch
Normal file
BIN
.vs/samcraft/v17/ipch/AutoPCH/6b6ca287a604beb4/RMODELS.ipch
Normal file
Binary file not shown.
BIN
.vs/samcraft/v17/ipch/AutoPCH/6ea97bae9f8c79cb/RMODELS.ipch
Normal file
BIN
.vs/samcraft/v17/ipch/AutoPCH/6ea97bae9f8c79cb/RMODELS.ipch
Normal file
Binary file not shown.
BIN
.vs/samcraft/v17/ipch/AutoPCH/eb046027442056c7/CHUNK.ipch
Normal file
BIN
.vs/samcraft/v17/ipch/AutoPCH/eb046027442056c7/CHUNK.ipch
Normal file
Binary file not shown.
BIN
.vs/samcraft/v17/ipch/AutoPCH/fdcae648f8fe8f9b/MAIN.ipch
Normal file
BIN
.vs/samcraft/v17/ipch/AutoPCH/fdcae648f8fe8f9b/MAIN.ipch
Normal file
Binary file not shown.
|
@ -14,7 +14,7 @@ int coord_to_index(vector3 coord) {
|
|||
return index;
|
||||
}
|
||||
|
||||
int get_block_at(Chunk chunk, vector3 pos) {
|
||||
if (pos.x < 0 || pos.x >= WIDTH || pos.z < 0 || pos.z >= WIDTH || pos.y < 0 || pos.y >= HEIGHT) return 0;
|
||||
return chunk[coord_to_index(pos)];
|
||||
int get_block_at(int chunk[WIDTH][HEIGHT][WIDTH], int x, int y, int z) {
|
||||
if (x < 0 || x >= WIDTH || z < 0 || z >= WIDTH || y < 0 || y >= HEIGHT) return 0;
|
||||
return chunk[x][y][z];
|
||||
}
|
||||
|
|
|
@ -2,15 +2,12 @@
|
|||
#define __CHUNK_H__
|
||||
|
||||
#include "vector.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define WIDTH 16
|
||||
#define WIDTH 1024
|
||||
#define HEIGHT 256
|
||||
|
||||
typedef uint8_t Chunk[HEIGHT * WIDTH * WIDTH];
|
||||
|
||||
vector3 index_to_coord(int i);
|
||||
int coord_to_index(vector3 pos);
|
||||
int get_block_at(Chunk chunk, vector3 pos);
|
||||
int get_block_at(int chunk[WIDTH][HEIGHT][WIDTH], int x, int y, int z);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <threads.h>
|
||||
|
||||
#include "faces.h"
|
||||
#include "chunk.h"
|
||||
|
@ -11,7 +10,7 @@
|
|||
#define STB_PERLIN_IMPLEMENTATION
|
||||
#include "stb_perlin.h"
|
||||
|
||||
Mesh gen_mesh(Chunk chunk) {
|
||||
Mesh gen_mesh(int chunk[WIDTH][HEIGHT][WIDTH]) {
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vertices = malloc(0);
|
||||
mesh.vertexCount = 0;
|
||||
|
@ -20,26 +19,27 @@ Mesh gen_mesh(Chunk chunk) {
|
|||
for(int x = 0; x < WIDTH; x++) {
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int z = 0; z < WIDTH; z++) {
|
||||
vector3 pos = vec3(x, y, z);
|
||||
int block_id = get_block_at(chunk, pos);
|
||||
int block_id = chunk[x][y][z];
|
||||
if (block_id == 0) continue;
|
||||
vector3 pos = { x, y, z };
|
||||
//vector3 pos = index_to_coord(i);
|
||||
|
||||
if (get_block_at(chunk, vec3(x, y - 1, z)) == 0)
|
||||
if (get_block_at(chunk, x, y - 1, z) == 0)
|
||||
add_face(&mesh, bottom, bottom_tex, block_id, pos);
|
||||
|
||||
if (get_block_at(chunk, vec3(x, y + 1, z)) == 0)
|
||||
if (get_block_at(chunk, x, y + 1, z) == 0)
|
||||
add_face(&mesh, top, top_tex, block_id == 1 ? 4 : block_id, pos);
|
||||
|
||||
if (get_block_at(chunk, vec3(x - 1, y, z)) == 0)
|
||||
if (get_block_at(chunk, x - 1, y, z) == 0)
|
||||
add_face(&mesh, left, left_tex, block_id, pos);
|
||||
|
||||
if (get_block_at(chunk, vec3(x + 1, y, z)) == 0)
|
||||
if (get_block_at(chunk, x + 1, y, z) == 0)
|
||||
add_face(&mesh, right, right_tex, block_id, pos);
|
||||
|
||||
if (get_block_at(chunk, vec3(x, y, z - 1)) == 0)
|
||||
if (get_block_at(chunk, x, y, z - 1) == 0)
|
||||
add_face(&mesh, back, back_tex, block_id, pos);
|
||||
|
||||
if (get_block_at(chunk, vec3(x, y, z + 1)) == 0)
|
||||
if (get_block_at(chunk, x, y, z + 1) == 0)
|
||||
add_face(&mesh, front, front_tex, block_id, pos);
|
||||
}
|
||||
}
|
||||
|
@ -56,29 +56,25 @@ int main() {
|
|||
InitWindow(800, 600, "samcraft");
|
||||
|
||||
//SetTargetFPS(60);
|
||||
int (*chunk)[HEIGHT][WIDTH] = calloc(WIDTH * HEIGHT * WIDTH, sizeof(int));
|
||||
|
||||
Chunk* chunks = calloc(2, sizeof(Chunk));
|
||||
Mesh* chunk_meshes = calloc(2, sizeof(Mesh));
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int z = 0; z < WIDTH; z++) {
|
||||
int height = (90 + stb_perlin_fbm_noise3(((i * WIDTH) + x) / 40.0f, x / 40.0f, z / 40.0f, 2.0f, 0.5f, 6) * 10.0f);
|
||||
int height = (90 + stb_perlin_fbm_noise3(x / 40.0f, x / 40.0f, z / 40.0f, 2.0f, 0.5f, 6) * 10.0f);
|
||||
for (int y = 0; y < height; y++) {
|
||||
int id = 2;
|
||||
if (height - y == 1) id = 1;
|
||||
if (height - y == 2) id = 3;
|
||||
chunks[i][coord_to_index((vector3){x, y, z})] = id;
|
||||
chunk[x][y][z] = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mesh mesh = gen_mesh(chunks[i]);
|
||||
chunk_meshes[i] = mesh;
|
||||
}
|
||||
Mesh chunk_mesh = gen_mesh(chunk);
|
||||
Material mat = LoadMaterialDefault();
|
||||
Matrix matrix = MatrixIdentity();
|
||||
|
||||
Texture atlas = LoadTexture("atlas.png");
|
||||
Material mat = LoadMaterialDefault();
|
||||
mat.maps[MATERIAL_MAP_DIFFUSE].texture = atlas;
|
||||
|
||||
Camera camera = { 0 };
|
||||
|
@ -99,9 +95,7 @@ int main() {
|
|||
|
||||
BeginMode3D(camera);
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
DrawMesh(chunk_meshes[i], mat, MatrixTranslate(i * WIDTH, 0.0f, 0.0f));
|
||||
}
|
||||
DrawMesh(chunk_mesh, mat, matrix);
|
||||
DrawGrid(10, 10);
|
||||
}
|
||||
EndMode3D();
|
||||
|
|
|
@ -76,7 +76,6 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -91,7 +90,6 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -106,7 +104,6 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -121,7 +118,6 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
|
|
@ -12,6 +12,4 @@ typedef struct {
|
|||
float y;
|
||||
} vector2;
|
||||
|
||||
#define vec3(x, y, z) (vector3){ x, y, z }
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue