changed matrix ops to be by pointer
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 19 Oct 2020 01:35:23 +0000 (20:35 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 19 Oct 2020 01:35:23 +0000 (20:35 -0500)
include/vecmath.h
src/sim.c
src/vecmath.c

index cf40c7e1f8138a9d015ff39883834392e13ee4e5..be7d4362c67c25e372fad0092de7d60d432ab612 100644 (file)
@@ -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
index 4929b5ccf43eaa7e7bcd31cd0011f5f81e218f5e..c0170671942c0b1196b3d121dbf801c01bd7da3f 100644 (file)
--- 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);
index a523fa3ce3994ba6c3cc05f9ecce2d6c72a3c398..01b4a38f22407e120f7628c9a387c3e01e5d4f70 100644 (file)
@@ -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);
 }