From 8abe9ef507aa1c6ea3585f26139c1f5668f95b47 Mon Sep 17 00:00:00 2001 From: Lipid Date: Sun, 13 May 2018 20:05:55 +0200 Subject: [PATCH 1/2] Add mat3_mul and generic transpose to math.odin --- core/math/math.odin | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/core/math/math.odin b/core/math/math.odin index 9a6799a7e..c31521daf 100644 --- a/core/math/math.odin +++ b/core/math/math.odin @@ -149,6 +149,7 @@ to_degrees :: proc(radians: f32) -> f32 { return radians * 360 / TAU; } mul :: proc[ + mat3_mul, mat4_mul, mat4_mul_vec4, quat_mul, quat_mulf, ]; @@ -197,15 +198,27 @@ identity :: proc(T: type/[$N][N]$E) -> T { return m; } -transpose :: proc(m: Mat4) -> Mat4 { - for j in 0..4 { - for i in 0..4 { +transpose :: proc(m: $M/[$N][N]f32) -> M { + for j in 0..N { + for i in 0..N { m[i][j], m[j][i] = m[j][i], m[i][j]; } } return m; } +mat3_mul :: proc(a, b: Mat3) -> Mat3 { + c: Mat3; + for j in 0..3 { + for i in 0..3 { + c[j][i] = a[0][i]*b[j][0] + + a[1][i]*b[j][1] + + a[2][i]*b[j][2]; + } + } + return c; +} + mat4_mul :: proc(a, b: Mat4) -> Mat4 { c: Mat4; for j in 0..4 { @@ -228,7 +241,6 @@ mat4_mul_vec4 :: proc(m: Mat4, v: Vec4) -> Vec4 { }; } - mat4_inverse :: proc(m: Mat4) -> Mat4 { o: Mat4; From 92ce02dab0ab189bb8d92b7c917a13d78224675f Mon Sep 17 00:00:00 2001 From: Lipid Date: Mon, 16 Jul 2018 20:30:49 +0200 Subject: [PATCH 2/2] Fix indent characters --- core/math/math.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/math/math.odin b/core/math/math.odin index c31521daf..d85a1f300 100644 --- a/core/math/math.odin +++ b/core/math/math.odin @@ -149,7 +149,7 @@ to_degrees :: proc(radians: f32) -> f32 { return radians * 360 / TAU; } mul :: proc[ - mat3_mul, + mat3_mul, mat4_mul, mat4_mul_vec4, quat_mul, quat_mulf, ];