the_Foundation [release-1.0]

Math: Fixed Mat4 scale and scalef methods

=> 6e175a9f1b61f6152122988eb2c3801964473e9f

diff --git a/include/the_Foundation/math_generic.h b/include/the_Foundation/math_generic.h
index ab89d96..0d81a4b 100644
--- a/include/the_Foundation/math_generic.h
+++ b/include/the_Foundation/math_generic.h
@@ -634,9 +634,17 @@ iLocalDef void initScale_Mat4(iMat4 *d, iFloat3 v) {
 }
 
 iLocalDef void scale_Mat4(iMat4 *d, iFloat3 v) {
-    d->col[0].value.x *= v.value.x;
-    d->col[1].value.y *= v.value.y;
-    d->col[2].value.z *= v.value.z;
+    iMat4 s; initScale_Mat4(&s, v);
+    mul_Mat4(d, &s);
+}
+
+iLocalDef void scalef_Mat4(iMat4 *d, float v) {
+    iMat4 s;
+    s.col[0] = init_F4(v, 0, 0, 0);
+    s.col[1] = init_F4(0, v, 0, 0);
+    s.col[2] = init_F4(0, 0, v, 0);
+    s.col[3] = init_F4(0, 0, 0, 1);
+    mul_Mat4(d, &s);
 }
 
 void initRotate_Mat4(iMat4 *d, iFloat3 axis, float degrees);
@@ -646,12 +654,6 @@ iLocalDef void rotate_Mat4(iMat4 *d, iFloat3 axis, float degrees) {
     mul_Mat4(d, &rot);
 }
 
-iLocalDef void scalef_Mat4(iMat4 *d, float v) {
-    d->col[0].value.x *= v;
-    d->col[1].value.y *= v;
-    d->col[2].value.z *= v;
-}
-
 iLocalDef iFloat4 mulF4_Mat4(const iMat4 *d, const iFloat4 v) {
     return init_F4(dot_F4(row_Mat4(d, 0), v),
                    dot_F4(row_Mat4(d, 1), v),
diff --git a/include/the_Foundation/math_sse.h b/include/the_Foundation/math_sse.h
index 37b7bb0..8980aff 100644
--- a/include/the_Foundation/math_sse.h
+++ b/include/the_Foundation/math_sse.h
@@ -407,15 +407,17 @@ iLocalDef void initScale_Mat4(iMat4 *d, iFloat3 v) {
 }
 
 iLocalDef void scale_Mat4(iMat4 *d, iFloat3 v) {
-    d->col[0] = _mm_mul_ps(d->col[0], _mm_set_ps(1, 1, x_F3(v), 1));
-    d->col[1] = _mm_mul_ps(d->col[1], _mm_set_ps(1, y_F3(v), 1, 1));
-    d->col[2] = _mm_mul_ps(d->col[2], _mm_set_ps(z_F3(v), 1, 1, 1));
+    iMat4 s; initScale_Mat4(&s, v);
+    mul_Mat4(d, &s);
 }
 
 iLocalDef void scalef_Mat4(iMat4 *d, float v) {
-    d->col[0] = _mm_mul_ps(d->col[0], _mm_set_ps(1, 1, v, 1));
-    d->col[1] = _mm_mul_ps(d->col[1], _mm_set_ps(1, v, 1, 1));
-    d->col[2] = _mm_mul_ps(d->col[2], _mm_set_ps(v, 1, 1, 1));
+    iMat4 s;
+    s.col[0] = _mm_set_ps(0, 0, v, 0);
+    s.col[1] = _mm_set_ps(0, v, 0, 0);
+    s.col[2] = _mm_set_ps(v, 0, 0, 0);
+    s.col[3] = _mm_set_ps(0, 0, 0, 1);
+    mul_Mat4(d, &s);
 }
 
 void initRotate_Mat4(iMat4 *d, iFloat3 axis, float degrees);
Proxy Information
Original URL
gemini://git.skyjake.fi/the_Foundation/release-1.0/cdiff/6e175a9f1b61f6152122988eb2c3801964473e9f
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
28.636768 milliseconds
Gemini-to-HTML Time
0.392203 milliseconds

This content has been proxied by September (3851b).