Fixed a bug in the meshing
This commit is contained in:
parent
8f5c9cef39
commit
201f222083
|
@ -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,
|
||||||
-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,
|
||||||
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_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_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_X(view_matrix, view_matrix, tc_camera_rotation.x);
|
||||||
// mat4x4_rotate_Y(view_matrix, view_matrix, tc_camera_rotation.y);
|
mat4x4_rotate_Y(view_matrix, view_matrix, tc_camera_rotation.y);
|
||||||
// mat4x4_rotate_Z(view_matrix, view_matrix, tc_camera_rotation.z);
|
mat4x4_rotate_Z(view_matrix, view_matrix, tc_camera_rotation.z);
|
||||||
|
|
||||||
glUseProgram(tc_game_state_g.renderer.draw_shader.program_id);
|
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]);
|
glUniformMatrix4fv(view_uniform_location, 1, GL_FALSE, &view_matrix[0][0]);
|
||||||
// printf("%d\n", view_uniform_location);
|
// printf("%d\n", view_uniform_location);
|
||||||
|
|
||||||
// render_block(block);
|
render_block(block);
|
||||||
tc_draw_world(&tc_game_state_g.main_world);
|
tc_draw_world(&tc_game_state_g.main_world);
|
||||||
|
|
||||||
SDL_GL_SwapWindow(tc_game_state_g.renderer.window);
|
SDL_GL_SwapWindow(tc_game_state_g.renderer.window);
|
||||||
|
@ -135,6 +135,8 @@ bool go_left = false;
|
||||||
bool go_right = false;
|
bool go_right = false;
|
||||||
bool go_forward = false;
|
bool go_forward = false;
|
||||||
bool go_backwards = false;
|
bool go_backwards = false;
|
||||||
|
bool rotate_left = false;
|
||||||
|
bool rotate_right = false;
|
||||||
|
|
||||||
bool update()
|
bool update()
|
||||||
{
|
{
|
||||||
|
@ -158,6 +160,16 @@ bool update()
|
||||||
} break;
|
} break;
|
||||||
case SDL_KEYDOWN:
|
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)
|
if(event.key.keysym.scancode == SDL_SCANCODE_W)
|
||||||
{
|
{
|
||||||
go_forward = true;
|
go_forward = true;
|
||||||
|
@ -192,6 +204,16 @@ bool update()
|
||||||
|
|
||||||
case SDL_KEYUP:
|
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)
|
if(event.key.keysym.scancode == SDL_SCANCODE_W)
|
||||||
{
|
{
|
||||||
go_forward = false;
|
go_forward = false;
|
||||||
|
@ -255,6 +277,17 @@ bool update()
|
||||||
{
|
{
|
||||||
tc_camera_position.z -= 0.25;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
-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,
|
||||||
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,
|
||||||
0.5f, -0.5f, -0.5f
|
0.5f, -0.5f, -0.5f
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t tc_count_chunk_vertices(tc_chunk_s *chunk)
|
uint32_t tc_count_chunk_vertices(tc_chunk_s *chunk)
|
||||||
{
|
{
|
||||||
uint32_t num_vertices = 0;
|
uint32_t num_vertices = 0;
|
||||||
|
@ -131,7 +130,7 @@ void tc_meshize_chunk(tc_chunk_s *chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(
|
memcpy(
|
||||||
&chunk->vertex_positions[vertex_index],
|
&chunk->vertex_positions[vertex_index*3],
|
||||||
block_positions,
|
block_positions,
|
||||||
sizeof(float) * 36 * 3
|
sizeof(float) * 36 * 3
|
||||||
);
|
);
|
||||||
|
|
|
@ -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);
|
glBindBuffer(GL_ARRAY_BUFFER, chunk->vertex_data);
|
||||||
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, chunk->num_vertices * 3 * sizeof(float), chunk->vertex_positions, GL_STATIC_DRAW);
|
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);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
tc_add_chunk(world, chunk);
|
tc_add_chunk(world, chunk);
|
||||||
|
|
Loading…
Reference in New Issue