collision changes, world generation fine tuning
This commit is contained in:
parent
4a1070a588
commit
1a3b5090a6
@ -52,7 +52,7 @@ typedef struct {
|
|||||||
Chunk *chunks;
|
Chunk *chunks;
|
||||||
} App;
|
} App;
|
||||||
|
|
||||||
void app_generate_world(App *app, int x);
|
void app_generate_world(App *app, int a);
|
||||||
bool chunk_is_block_neighboring_block(Chunk* chunk, vec3i pos);
|
bool chunk_is_block_neighboring_block(Chunk* chunk, vec3i pos);
|
||||||
void chunk_set_blocks_visibility(Chunk* chunk);
|
void chunk_set_blocks_visibility(Chunk* chunk);
|
||||||
void chunk_create_displayl(App *app, Chunk *chunk);
|
void chunk_create_displayl(App *app, Chunk *chunk);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "app.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GLSL-like three dimensional vector
|
* GLSL-like three dimensional vector
|
||||||
@ -53,4 +54,6 @@ bool matrix_inverse(const float m[16], float invOut[16]);
|
|||||||
void vec3f_normalize(vec3f *v);
|
void vec3f_normalize(vec3f *v);
|
||||||
|
|
||||||
int irand_range(int min, int max);
|
int irand_range(int min, int max);
|
||||||
|
|
||||||
|
bool check_index(int x, int y, int z);
|
||||||
#endif /* UTILS_H */
|
#endif /* UTILS_H */
|
||||||
|
29
src/app.c
29
src/app.c
@ -269,12 +269,16 @@ void app_generate_world(App *app, int a)
|
|||||||
c.start_pos.z = 0;
|
c.start_pos.z = 0;
|
||||||
for (int x = 0; x < CHUNK_MAX_X; x++) {
|
for (int x = 0; x < CHUNK_MAX_X; x++) {
|
||||||
for (int y = 0; y < CHUNK_MAX_Y; y++) {
|
for (int y = 0; y < CHUNK_MAX_Y; y++) {
|
||||||
printf("x: %d y:%d noise: %f\n",
|
//printf("x: %d y:%d noise: %f\n", x, y, round((noise_noise2(ptable,
|
||||||
x, y, (noise_noise2(ptable, x*0.005, y*0.005) + 1) * 0.5 * 60);
|
// (c.start_pos.x+x)*0.03, (c.start_pos.y+y)*0.03) + 1) * 0.5 * 15);
|
||||||
int mz = round((noise_noise2(ptable, x*0.005, y*0.005) + 1) * 0.5 * 60);
|
int mz = round((noise_noise2(ptable, (c.start_pos.x+x)*0.03, (c.start_pos.y+y)*0.03) + 1) * 0.5 * 15);
|
||||||
|
if (mz < 0)
|
||||||
|
mz = 0;
|
||||||
|
else if (mz > CHUNK_MAX_Z)
|
||||||
|
mz = CHUNK_MAX_Z-1;
|
||||||
for (int z = 0; z < mz; z++)
|
for (int z = 0; z < mz; z++)
|
||||||
c.blocks[x][y][z].type = BLOCKTYPE_STONE;
|
c.blocks[x][y][z].type = BLOCKTYPE_STONE;
|
||||||
for (int z = mz; i < CHUNK_MAX_Z; i++)
|
for (int z = mz; z < CHUNK_MAX_Z; z++)
|
||||||
c.blocks[x][y][z].type = BLOCKTYPE_AIR;
|
c.blocks[x][y][z].type = BLOCKTYPE_AIR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,16 +324,21 @@ bool app_check_collision(App *app)
|
|||||||
if (i < 0)
|
if (i < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int x = 0; x < CHUNK_MAX_X; x++) {
|
vec3f c_pos = app->camera.position;
|
||||||
for (int y = 0; y < CHUNK_MAX_Y; y++) {
|
vec3i c_index = { floor(c_pos.x), floor(c_pos.y), floor(c_pos.z) };
|
||||||
for (int z = 0; z < CHUNK_MAX_Z; z++) {
|
|
||||||
if (!is_block(app->chunks[i].blocks[x][y][z]))
|
for (int x = c_index.x-1; x < c_index.x+1; x++) {
|
||||||
|
for (int y = c_index.y-1; y < c_index.y+1; y++) {
|
||||||
|
for (int z = c_index.z-1; y < c_index.z+1; z++) {
|
||||||
|
if(!check_index(x, y, z))
|
||||||
continue;
|
continue;
|
||||||
if (app->camera.position.z <= z+3)
|
if(is_block(app->chunks[i].blocks[x][y][z])) {
|
||||||
return true;
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
App app;
|
App app;
|
||||||
init_app(&app, 1280, 720);
|
init_app(&app, 1600, 900);
|
||||||
|
|
||||||
//Chunk *chunks = malloc(25*sizeof(Chunk));
|
//Chunk *chunks = malloc(25*sizeof(Chunk));
|
||||||
//memset(chunks, 0, 25*sizeof(Chunk));
|
//memset(chunks, 0, 25*sizeof(Chunk));
|
||||||
@ -37,7 +37,7 @@ int main()
|
|||||||
//app.chunks = chunks;
|
//app.chunks = chunks;
|
||||||
//app.chunk_count = 25;
|
//app.chunk_count = 25;
|
||||||
|
|
||||||
app_generate_world(&app, 5);
|
app_generate_world(&app, 10);
|
||||||
|
|
||||||
while(app.is_running) {
|
while(app.is_running) {
|
||||||
struct timespec start;
|
struct timespec start;
|
||||||
@ -53,7 +53,7 @@ int main()
|
|||||||
|
|
||||||
for (int i = 0; i < app.chunk_count; i++) {
|
for (int i = 0; i < app.chunk_count; i++) {
|
||||||
chunk_render(&app.chunks[i]);
|
chunk_render(&app.chunks[i]);
|
||||||
printf("c sp: %f\n", app.chunks[i].start_pos.x);
|
//printf("c sp: %f\n", app.chunks[i].start_pos.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// vec3f pos = app.camera.position;
|
// vec3f pos = app.camera.position;
|
||||||
@ -67,7 +67,7 @@ int main()
|
|||||||
|
|
||||||
app.frame_time = calc_frame_time(&start, &end);
|
app.frame_time = calc_frame_time(&start, &end);
|
||||||
|
|
||||||
//printf("fps: %f\n", 1000/app.frame_time);
|
printf("fps: %f\n", 1000/app.frame_time);
|
||||||
//printf("lkat pos x: %f y: %f z: %f\n", pos.x+5*dir.x, pos.y+5*dir.y, pos.z+5*dir.z);
|
//printf("lkat pos x: %f y: %f z: %f\n", pos.x+5*dir.x, pos.y+5*dir.y, pos.z+5*dir.z);
|
||||||
//printf("camera x: %f y: %f z: %f\n", pos.x, pos.y, pos.z);
|
//printf("camera x: %f y: %f z: %f\n", pos.x, pos.y, pos.z);
|
||||||
//printf("dir x: %f y: %f z: %f\n", dir.x, dir.y, dir.z);
|
//printf("dir x: %f y: %f z: %f\n", dir.x, dir.y, dir.z);
|
||||||
|
11
src/utils.c
11
src/utils.c
@ -173,3 +173,14 @@ int irand_range(int min, int max)
|
|||||||
{
|
{
|
||||||
return rand() % (max - min + 1) + min;
|
return rand() % (max - min + 1) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool check_index(int x, int y, int z)
|
||||||
|
{
|
||||||
|
if (x < 0 || x >= CHUNK_MAX_X)
|
||||||
|
return false;
|
||||||
|
if (y < 0 || y >= CHUNK_MAX_Y)
|
||||||
|
return false;
|
||||||
|
if (z < 0 || z >= CHUNK_MAX_Z)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user