From 5542e4861c3da114b8aebea0bd4a46b2c29c1b66 Mon Sep 17 00:00:00 2001 From: Akos Horvath Date: Mon, 14 Nov 2022 18:38:00 +0100 Subject: [PATCH] fix block breaking --- src/app.c | 11 +++++++++-- src/camera.c | 42 ------------------------------------------ src/main1.c | 32 ++++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 52 deletions(-) diff --git a/src/app.c b/src/app.c index 2bbfda3..b56ed07 100644 --- a/src/app.c +++ b/src/app.c @@ -369,6 +369,7 @@ int check_intersection_block(App *app, vec3i *retv, int *chunk_index) void app_draw_particles(App *app, vec3i b) { + printf("%s\n", __func__); unsigned char index = app->particle_count; if (index >= MAX_PARTICLE_GROUPS) @@ -388,7 +389,8 @@ void app_draw_particles(App *app, vec3i b) void app_update_particles(App *app) { - unsigned char particles = app->particle_count; + unsigned char particles = app->particle_count; + printf("particle count %d\n", particles); for (int i = 0; i < particles; i++) { unsigned int time = SDL_GetTicks(); if (time - app->particles[i].time > 1000) { @@ -396,10 +398,15 @@ void app_update_particles(App *app) app->particle_count--; } else { for (int j = 0; j < PARTICLES_PER_GROUP; j++) { + printf("particle pos: %f %f %f\n", + app->particles[i].pos[j].x, + app->particles[i].pos[j].y, + app->particles[i].pos[j].z + ); app->particles[i].pos[j].z -= GRAVITY * app->frame_time/1000; draw_cube(app->cm, 0, app->particles[i].pos[j].x, app->particles[i].pos[j].y, - app->particles[i].pos[j].z, 0.1); + app->particles[i].pos[j].z, 0.5); } } } diff --git a/src/camera.c b/src/camera.c index e0d7c3c..18def19 100644 --- a/src/camera.c +++ b/src/camera.c @@ -18,48 +18,6 @@ void init_camera(Camera* camera) camera->speed.z = 0.0; } -vec3f handle_collision(vec3f camera_pos, ChunkManager *cm) -{ - vec3f c_max = { camera_pos.x + 0.25, camera_pos.y + 0.25, camera_pos.z + 0.25 }; - vec3f c_min = { camera_pos.x - 0.25, camera_pos.y - 0.25, camera_pos.z - 0.25 }; - vec3f b_max; - vec3f b_min; - - int i = chunk_get_current_chunk_index(cm, camera_pos); - - for (int x = floor(camera_pos.x-1); x < floor(camera_pos.x+1); x++) { - for (int y = floor(camera_pos.y-1); y < floor(camera_pos.y+1); y++) { - int z = floor(camera_pos.z+1); - if (!check_index(x, y, z)) - continue; - if(cm->chunks[i].blocks[x][y][z].visible) { - b_min = (vec3f) {x+1, y+1, z}; - b_max = (vec3f) {x+2, y+2, z+1}; - if (c_max.z > b_min.z && - c_min.z < b_max.z) { - return (vec3f) {0, 0, 1}; - } - } - } - } - - //int x = floor(camera_pos.x); - //int y = floor(camera_pos.y); - //int z = floor(camera_pos.z); - - //b_min = (vec3f) {x, y, z}; - //b_max = (vec3f) {x+1, y+1, z+1}; - // - //print_vec3f(c_max, "c_max"); - //print_vec3f(c_max, "c_min"); - //print_vec3f(c_max, "b_max"); - //print_vec3f(c_max, "b_max"); - //if (c_max.z > b_min.z && - // c_min.z < b_max.z) { - // return (vec3f) {0, 0, 1}; - //} - return (vec3f) {0, 0, 0}; -} void update_camera(Camera* camera, double time) { double angle; diff --git a/src/main1.c b/src/main1.c index 431a094..9531fc2 100644 --- a/src/main1.c +++ b/src/main1.c @@ -4,7 +4,16 @@ #include #include -#define SHADOWMAP_SIZE 2048 +#define SHADOWMAP_SIZE 4096 + +void set_light_pos(const vec3f p, float matrix[16]) +{ + glLoadIdentity(); + gluLookAt(p.x, p.y, p.z, + 4.0, 4.0, 10.0, + 0.0, 0.0, 1.0); + glGetFloatv(GL_MODELVIEW_MATRIX, matrix); +} int main() { struct timespec start; @@ -15,6 +24,7 @@ int main() init_app(&app, 1600, 900); ///// + vec3f light_pos = { .x = 40, .y = 40, .z = 80}; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -51,8 +61,8 @@ int main() glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); - //GLfloat materialColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; - //glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor); + GLfloat materialColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; + glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor); glMaterialf(GL_FRONT, GL_SHININESS, 64.0f); @@ -67,20 +77,24 @@ int main() glLoadIdentity(); - gluPerspective(45.0, 1.0, 2.0, 10000.0); + gluPerspective(80.0, 1.0, 2.0, 10000.0); glGetFloatv(GL_MODELVIEW_MATRIX, light_proj_matrix); glLoadIdentity(); - gluLookAt(80, 80, 90, - 20.0, 20.0, 10.0, - 0.0, 0.0, 1.0); - glGetFloatv(GL_MODELVIEW_MATRIX, light_view_matrix); + set_light_pos(light_pos, light_view_matrix); glPopMatrix(); ///// while(app.is_running) { clock_gettime(CLOCK_MONOTONIC_RAW, &start); + light_pos.x += 5*(app.frame_time/1000); + set_light_pos(light_pos, light_view_matrix); + app.camera.position.x = light_pos.x; + app.camera.position.y = light_pos.y; + app.camera.position.z = light_pos.z; + printf("light pos: %f %f %f\n", light_pos.x, light_pos.y, light_pos.z); + vec3f cd = get_camera_dir_vec3f(&app.camera); vec3f cp = app.camera.position; @@ -146,6 +160,8 @@ int main() //set_view(&app.camera); for (int i = 0; i < app.cm->chunk_count; i++) { + GLuint t = get_texture(app.cm, BLOCKTYPE_DIRT); + glBindTexture(t, GL_TEXTURE_2D); chunk_render(&app.cm->chunks[i]); //printf("c sp: %f\n", app.chunks[i].start_pos.x); }