From 699d0e2e87c227fabcc6022e5324d0ec44d032bc Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 18 Oct 2020 21:42:59 -0500 Subject: [PATCH] added mat4_mul --- include/vecmath.h | 1 + res/shaders/planet_vert.glsl | 2 +- src/sim.c | 25 ++++++++++++++----------- src/vecmath.c | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/vecmath.h b/include/vecmath.h index be7d436..0916674 100644 --- a/include/vecmath.h +++ b/include/vecmath.h @@ -22,6 +22,7 @@ void mat4_ortho(mat4 *mat, f32 top, f32 bottom, f32 near, f32 far); void mat4_proj(mat4 *mat); +void mat4_mul(mat4 a, mat4 b, mat4* out); #endif //VECMATH_H diff --git a/res/shaders/planet_vert.glsl b/res/shaders/planet_vert.glsl index 67afc25..4c306ce 100644 --- a/res/shaders/planet_vert.glsl +++ b/res/shaders/planet_vert.glsl @@ -9,5 +9,5 @@ layout(location = 2) in float a_mass; uniform mat4 u_proj; void main() { - gl_Position = u_proj * vec4(a_shape_pos, 0, 1); + gl_Position = u_proj * vec4(a_shape_pos * a_mass + a_obj_pos, 0, 1); } \ No newline at end of file diff --git a/src/sim.c b/src/sim.c index c017067..d091e1f 100644 --- a/src/sim.c +++ b/src/sim.c @@ -56,9 +56,16 @@ init_glfw() { glfwSetKeyCallback(window, glfw_key_handler); glfwSetFramebufferSizeCallback(window, glfw_resize_handler); - //glEnable(GL_CULL_FACE); - //glFrontFace(GL_CW); - //glCullFace(GL_BACK); + // NOTE(Brendan): This may need to be changed if the screen orientation changes. + glEnable(GL_CULL_FACE); + glFrontFace(GL_CW); + glCullFace(GL_BACK); +} + +internal void +deinit_glfw() { + glfwDestroyWindow(window); + glfwTerminate(); } internal GLuint @@ -144,8 +151,8 @@ create_circle_mesh() { V2f circle_points[CIRCLE_POINT_COUNT] = {}; foreach (i, 0, CIRCLE_POINT_COUNT) { f32 t = (f32) i / (f32) CIRCLE_POINT_COUNT; - circle_points[i].x = cos(t * 2 * PI) * 100.0f + 400.0f; - circle_points[i].y = sin(t * 2 * PI) * 100.0f + 200.0f; + circle_points[i].x = cos(t * 2 * PI) / 2.0f + 400.0f; + circle_points[i].y = sin(t * 2 * PI) / 2.0f + 200.0f; } GLsizei vertex_buffer; @@ -169,11 +176,7 @@ create_circle_mesh() { return vao; } -internal void -deinit_opengl() { - glfwDestroyWindow(window); - glfwTerminate(); -} + // NOTE(Brendan): dt is expected to be in units of "per second". internal void @@ -231,7 +234,7 @@ main(i32 argc, char* argv[]) { loop(); - deinit_opengl(); + deinit_glfw(); return 0; } \ No newline at end of file diff --git a/src/vecmath.c b/src/vecmath.c index 01b4a38..25af422 100644 --- a/src/vecmath.c +++ b/src/vecmath.c @@ -74,3 +74,18 @@ mat4_ortho(mat4 *mat, (*mat)[3 * 4 + 1] = -(top + bottom) / (top - bottom); (*mat)[3 * 4 + 2] = -(far + near) / (far - near); } + + +void +mat4_mul(mat4 a, mat4 b, mat4* out) +{ + foreach(row, 0, 4) { + foreach(col, 0, 4) { + (*out)[row * 4 + col] = 0.0f; + + foreach(i, 0, 4) { + (*out)[row * 4 + col] += a[row * 4 + i] + b[i * 4 + col]; + } + } + } +} \ No newline at end of file -- 2.25.1