diff --git a/code/source-c/main.c b/code/source-c/main.c index 760a469..4d9475e 100644 --- a/code/source-c/main.c +++ b/code/source-c/main.c @@ -30,6 +30,8 @@ typedef struct tc_object { int vbo; int vao; + tc_vec3_s position; + tc_vec3_s rotation; } tc_object_s; @@ -44,6 +46,15 @@ tc_block_s block; void render_block(tc_block_s block) { + mat4x4 model_matrix; + mat4x4_translate(model_matrix, block.position.x, block.position.y, block.position.z); + // mat4x4_rotate_X(view_matrix, model_matrix, block.rotation.x); + // mat4x4_rotate_Y(view_matrix, model_matrix, block.rotation.y); + // mat4x4_rotate_Z(view_matrix, model_matrix, block.rotation.z); + + int model_matrix_uniform_location = glGetUniformLocation(main_shader, "model_matrix"); + glUniformMatrix4fv(model_matrix_uniform_location, 1, GL_FALSE, &model_matrix[0][0]); + glBindBuffer(GL_ARRAY_BUFFER, block.drawing.vbo); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *) 0); glEnableVertexAttribArray(0); @@ -155,6 +166,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); glUseProgram(main_shader); @@ -165,10 +179,6 @@ void render() glUniformMatrix4fv(view_uniform_location, 1, GL_FALSE, &view_matrix[0][0]); // printf("%d\n", view_uniform_location); - // 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); - render_block(block); SDL_GL_SwapWindow(window); @@ -338,6 +348,8 @@ int main(int argc, char **argv) SDL_ShowWindow(window); } + block.position.x += 0.1f; + ++frame_index; SDL_Delay(1000/60); } diff --git a/vertex_shader.glsl b/vertex_shader.glsl index 1768f9a..cd5de9c 100644 --- a/vertex_shader.glsl +++ b/vertex_shader.glsl @@ -8,6 +8,6 @@ uniform mat4 model_matrix; void main() { - gl_Position = projection_matrix * view_matrix * vec4(pos, 1.0); + gl_Position = projection_matrix * view_matrix * model_matrix * vec4(pos, 1.0); }