From 201f222083d7eb2dd038343b52e7443e6da9182e Mon Sep 17 00:00:00 2001 From: Eric-Paul Ickhorn Date: Wed, 11 Oct 2023 10:41:58 +0200 Subject: [PATCH] Fixed a bug in the meshing --- code/source-c/main.c | 45 +++++++++++++++++++++++++++++++++++------ code/source-c/meshize.c | 7 +++---- code/source-c/world.c | 3 --- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/code/source-c/main.c b/code/source-c/main.c index ed97023..47ff023 100644 --- a/code/source-c/main.c +++ b/code/source-c/main.c @@ -34,7 +34,7 @@ float triangle_vertices[108] = -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, - -0.5f, -0.5f, -0.5f, + -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, @@ -43,7 +43,7 @@ float triangle_vertices[108] = 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, - 0.5f, -0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, @@ -110,9 +110,9 @@ void render() mat4x4_perspective(projection_matrix, 120, 1200 / 800, 0.0001f, 1000.0f); mat4x4_translate(view_matrix, -tc_camera_position.x, -tc_camera_position.y, tc_camera_position.z); - // mat4x4_rotate_X(view_matrix, view_matrix, tc_camera_rotation.x); - // mat4x4_rotate_Y(view_matrix, view_matrix, tc_camera_rotation.y); - // mat4x4_rotate_Z(view_matrix, view_matrix, tc_camera_rotation.z); + mat4x4_rotate_X(view_matrix, view_matrix, tc_camera_rotation.x); + mat4x4_rotate_Y(view_matrix, view_matrix, tc_camera_rotation.y); + mat4x4_rotate_Z(view_matrix, view_matrix, tc_camera_rotation.z); glUseProgram(tc_game_state_g.renderer.draw_shader.program_id); @@ -123,7 +123,7 @@ void render() glUniformMatrix4fv(view_uniform_location, 1, GL_FALSE, &view_matrix[0][0]); // printf("%d\n", view_uniform_location); - // render_block(block); + render_block(block); tc_draw_world(&tc_game_state_g.main_world); SDL_GL_SwapWindow(tc_game_state_g.renderer.window); @@ -135,6 +135,8 @@ bool go_left = false; bool go_right = false; bool go_forward = false; bool go_backwards = false; +bool rotate_left = false; +bool rotate_right = false; bool update() { @@ -158,6 +160,16 @@ bool update() } break; case SDL_KEYDOWN: + if(event.key.keysym.scancode == SDL_SCANCODE_Q) + { + rotate_left = true; + } + + if(event.key.keysym.scancode == SDL_SCANCODE_E) + { + rotate_right = true; + } + if(event.key.keysym.scancode == SDL_SCANCODE_W) { go_forward = true; @@ -192,6 +204,16 @@ bool update() case SDL_KEYUP: + if(event.key.keysym.scancode == SDL_SCANCODE_Q) + { + rotate_left = false; + } + + if(event.key.keysym.scancode == SDL_SCANCODE_E) + { + rotate_right = false; + } + if(event.key.keysym.scancode == SDL_SCANCODE_W) { go_forward = false; @@ -255,6 +277,17 @@ bool update() { tc_camera_position.z -= 0.25; } + + if(rotate_left) + { + tc_camera_rotation.y += 1.0f / (3.1415 * 2); + } + + if(rotate_right) + { + tc_camera_rotation.y -= 1.0f / (3.1415 * 2); + } + return true; } diff --git a/code/source-c/meshize.c b/code/source-c/meshize.c index e701f46..f2cc574 100644 --- a/code/source-c/meshize.c +++ b/code/source-c/meshize.c @@ -28,7 +28,7 @@ float tc_block_vertices[108] = -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, - -0.5f, -0.5f, -0.5f, + -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, @@ -37,7 +37,7 @@ float tc_block_vertices[108] = 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, - 0.5f, -0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, @@ -59,7 +59,6 @@ float tc_block_vertices[108] = -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f }; - uint32_t tc_count_chunk_vertices(tc_chunk_s *chunk) { uint32_t num_vertices = 0; @@ -131,7 +130,7 @@ void tc_meshize_chunk(tc_chunk_s *chunk) } memcpy( - &chunk->vertex_positions[vertex_index], + &chunk->vertex_positions[vertex_index*3], block_positions, sizeof(float) * 36 * 3 ); diff --git a/code/source-c/world.c b/code/source-c/world.c index 3390c66..6e1d833 100644 --- a/code/source-c/world.c +++ b/code/source-c/world.c @@ -94,9 +94,6 @@ tc_chunk_s * tc_new_chunk(tc_world_s *world, float x, float y, float z) glBindBuffer(GL_ARRAY_BUFFER, chunk->vertex_data); glBufferData(GL_ARRAY_BUFFER, chunk->num_vertices * 3 * sizeof(float), chunk->vertex_positions, GL_STATIC_DRAW); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *) 0); - glEnableVertexAttribArray(0); - glBindVertexArray(0); tc_add_chunk(world, chunk);