From 3a040b8b2edd66888a75447e7da69654950b9775 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Mon, 26 Dec 2022 08:46:34 -0800 Subject: Change mat4_make() to a more intuitive row-by-row construction. --- include/math/mat4.h | 37 ++++++++++++++++++++++--------------- include/math/vec2.h | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/math/mat4.h b/include/math/mat4.h index e6c707a..3ceb75b 100644 --- a/include/math/mat4.h +++ b/include/math/mat4.h @@ -13,28 +13,35 @@ typedef struct mat4 { } mat4; /// Construct a matrix from 16 values. -static inline mat4 mat4_make(R m00, R m10, R m20, R m30, R m01, R m11, R m21, - R m31, R m02, R m12, R m22, R m32, R m03, R m13, - R m23, R m33) { +/// +/// The values are given row by row: +/// +/// [ m00 m01 m02 m03 ] +/// [ m10 m11 m12 m13 ] +/// [ m20 m21 m22 m23 ] +/// [ m30 m31 m32 m33 ] +static inline mat4 mat4_make(R m00, R m01, R m02, R m03, R m10, R m11, R m12, + R m13, R m20, R m21, R m22, R m23, R m30, R m31, + R m32, R m33) { mat4 m; m.val[0][0] = m00; - m.val[0][1] = m01; - m.val[0][2] = m02; - m.val[0][3] = m03; + m.val[0][1] = m10; + m.val[0][2] = m20; + m.val[0][3] = m30; - m.val[1][0] = m10; + m.val[1][0] = m01; m.val[1][1] = m11; - m.val[1][2] = m12; - m.val[1][3] = m13; + m.val[1][2] = m21; + m.val[1][3] = m31; - m.val[2][0] = m20; - m.val[2][1] = m21; + m.val[2][0] = m02; + m.val[2][1] = m12; m.val[2][2] = m22; - m.val[2][3] = m23; + m.val[2][3] = m32; - m.val[3][0] = m30; - m.val[3][1] = m31; - m.val[3][2] = m32; + m.val[3][0] = m03; + m.val[3][1] = m13; + m.val[3][2] = m23; m.val[3][3] = m33; return m; } diff --git a/include/math/vec2.h b/include/math/vec2.h index ebf0d78..dc51c17 100644 --- a/include/math/vec2.h +++ b/include/math/vec2.h @@ -15,7 +15,7 @@ static inline vec2 vec2_make(R x, R y) { return (vec2){x, y}; } /// Construct a vector from an array. static inline vec2 vec2_from_array(const R xy[2]) { - return (vec2){xy[0], xy[1] }; + return (vec2){xy[0], xy[1]}; } /// Construct a vector from a single scalar value. -- cgit v1.2.3