diff options
author | Marc Sunet <msunet@shellblade.net> | 2022-12-26 08:46:34 -0800 |
---|---|---|
committer | Marc Sunet <msunet@shellblade.net> | 2022-12-26 08:46:34 -0800 |
commit | 3a040b8b2edd66888a75447e7da69654950b9775 (patch) | |
tree | cecd0c3ac5683edf06379e63e23426c3445239ed | |
parent | 722dda8ff3e91567dbaf83e141699fd34d4889c4 (diff) |
Change mat4_make() to a more intuitive row-by-row construction.
-rw-r--r-- | include/math/mat4.h | 37 | ||||
-rw-r--r-- | include/math/vec2.h | 2 |
2 files changed, 23 insertions, 16 deletions
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 { | |||
13 | } mat4; | 13 | } mat4; |
14 | 14 | ||
15 | /// Construct a matrix from 16 values. | 15 | /// Construct a matrix from 16 values. |
16 | static inline mat4 mat4_make(R m00, R m10, R m20, R m30, R m01, R m11, R m21, | 16 | /// |
17 | R m31, R m02, R m12, R m22, R m32, R m03, R m13, | 17 | /// The values are given row by row: |
18 | R m23, R m33) { | 18 | /// |
19 | /// [ m00 m01 m02 m03 ] | ||
20 | /// [ m10 m11 m12 m13 ] | ||
21 | /// [ m20 m21 m22 m23 ] | ||
22 | /// [ m30 m31 m32 m33 ] | ||
23 | static inline mat4 mat4_make(R m00, R m01, R m02, R m03, R m10, R m11, R m12, | ||
24 | R m13, R m20, R m21, R m22, R m23, R m30, R m31, | ||
25 | R m32, R m33) { | ||
19 | mat4 m; | 26 | mat4 m; |
20 | m.val[0][0] = m00; | 27 | m.val[0][0] = m00; |
21 | m.val[0][1] = m01; | 28 | m.val[0][1] = m10; |
22 | m.val[0][2] = m02; | 29 | m.val[0][2] = m20; |
23 | m.val[0][3] = m03; | 30 | m.val[0][3] = m30; |
24 | 31 | ||
25 | m.val[1][0] = m10; | 32 | m.val[1][0] = m01; |
26 | m.val[1][1] = m11; | 33 | m.val[1][1] = m11; |
27 | m.val[1][2] = m12; | 34 | m.val[1][2] = m21; |
28 | m.val[1][3] = m13; | 35 | m.val[1][3] = m31; |
29 | 36 | ||
30 | m.val[2][0] = m20; | 37 | m.val[2][0] = m02; |
31 | m.val[2][1] = m21; | 38 | m.val[2][1] = m12; |
32 | m.val[2][2] = m22; | 39 | m.val[2][2] = m22; |
33 | m.val[2][3] = m23; | 40 | m.val[2][3] = m32; |
34 | 41 | ||
35 | m.val[3][0] = m30; | 42 | m.val[3][0] = m03; |
36 | m.val[3][1] = m31; | 43 | m.val[3][1] = m13; |
37 | m.val[3][2] = m32; | 44 | m.val[3][2] = m23; |
38 | m.val[3][3] = m33; | 45 | m.val[3][3] = m33; |
39 | return m; | 46 | return m; |
40 | } | 47 | } |
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}; } | |||
15 | 15 | ||
16 | /// Construct a vector from an array. | 16 | /// Construct a vector from an array. |
17 | static inline vec2 vec2_from_array(const R xy[2]) { | 17 | static inline vec2 vec2_from_array(const R xy[2]) { |
18 | return (vec2){xy[0], xy[1] }; | 18 | return (vec2){xy[0], xy[1]}; |
19 | } | 19 | } |
20 | 20 | ||
21 | /// Construct a vector from a single scalar value. | 21 | /// Construct a vector from a single scalar value. |