From: Brendan Hansen Date: Mon, 19 Oct 2020 01:35:23 +0000 (-0500) Subject: changed matrix ops to be by pointer X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=f0e3ff51d76d4bbacef8a59817121f1a8d48f58c;p=csc718.git changed matrix ops to be by pointer --- diff --git a/include/vecmath.h b/include/vecmath.h index cf40c7e..be7d436 100644 --- a/include/vecmath.h +++ b/include/vecmath.h @@ -16,12 +16,12 @@ V2f v2f_proj(V2f a, V2f onto); typedef float mat4[16]; -void mat4_identity(mat4 mat); -void mat4_ortho(mat4 mat, +void mat4_identity(mat4 *mat); +void mat4_ortho(mat4 *mat, f32 left, f32 right, f32 top, f32 bottom, f32 near, f32 far); -void mat4_proj(mat4 mat); +void mat4_proj(mat4 *mat); #endif //VECMATH_H diff --git a/src/sim.c b/src/sim.c index 4929b5c..c017067 100644 --- a/src/sim.c +++ b/src/sim.c @@ -224,7 +224,7 @@ main(i32 argc, char* argv[]) { glUseProgram(program); mat4 ortho_mat; - mat4_ortho(ortho_mat, 0, 800, 0, 600, 0.0f, 100.0f); + mat4_ortho(&ortho_mat, 0, 800, 0, 800, 0.0f, 100.0f); GLuint ortho_mat_loc = glGetUniformLocation(program, "u_proj"); glUniformMatrix4fv(ortho_mat_loc, 1, false, (f32 *) ortho_mat); diff --git a/src/vecmath.c b/src/vecmath.c index a523fa3..01b4a38 100644 --- a/src/vecmath.c +++ b/src/vecmath.c @@ -48,29 +48,29 @@ v2f_proj(V2f a, V2f onto) { void -mat4_identity(mat4 mat) +mat4_identity(mat4 *mat) { - foreach(i, 0, 16) mat[i] = 0.0f; - mat[0 * 4 + 0] = 1.0f; - mat[1 * 4 + 1] = 1.0f; - mat[2 * 4 + 2] = 1.0f; - mat[3 * 4 + 3] = 1.0f; + foreach(i, 0, 16) (*mat)[i] = 0.0f; + (*mat)[0 * 4 + 0] = 1.0f; + (*mat)[1 * 4 + 1] = 1.0f; + (*mat)[2 * 4 + 2] = 1.0f; + (*mat)[3 * 4 + 3] = 1.0f; } void -mat4_ortho(mat4 mat, +mat4_ortho(mat4 *mat, f32 left, f32 right, f32 top, f32 bottom, f32 near, f32 far) { - foreach(i, 0, 16) mat[i] = 0.0; + foreach(i, 0, 16) (*mat)[i] = 0.0; - mat[0 * 4 + 0] = 2.0f / (right - left); - mat[1 * 4 + 1] = 2.0f / (top - bottom); - mat[2 * 4 + 2] = -2.0f / (far - near); - mat[3 * 4 + 3] = 1.0f; + (*mat)[0 * 4 + 0] = 2.0f / (right - left); + (*mat)[1 * 4 + 1] = 2.0f / (top - bottom); + (*mat)[2 * 4 + 2] = -2.0f / (far - near); + (*mat)[3 * 4 + 3] = 1.0f; - mat[3 * 4 + 0] = -(right + left) / (right - left); - mat[3 * 4 + 1] = -(top + bottom) / (top - bottom); - mat[3 * 4 + 2] = -(far + near) / (far - near); + (*mat)[3 * 4 + 0] = -(right + left) / (right - left); + (*mat)[3 * 4 + 1] = -(top + bottom) / (top - bottom); + (*mat)[3 * 4 + 2] = -(far + near) / (far - near); }