matrix: optimize the creation of the `gamnit_rotation_matrix`
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 17 Oct 2017 00:27:22 +0000 (20:27 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 21 Nov 2017 19:40:26 +0000 (14:40 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/matrix/projection.nit

index 368ef11..d42fa2a 100644 (file)
@@ -178,11 +178,13 @@ redef class Matrix
                var s2 = yaw.sin
                var c3 = roll.cos
                var s3 = roll.sin
-               var rot = new Matrix.from(
-                       [[          c2*c3,          -c2*s3,   -s2, 0.0],
-                        [ c1*s3+c3*s1*s2,  c1*c3-s1*s2*s3, c2*s1, 0.0],
-                        [-s1*s3+c1*c3*s2, -c3*s1-c1*s2*s3, c1*c2, 0.0],
-                        [            0.0,             0.0,   0.0, 1.0]])
+
+               var rot = new Matrix(4, 4)
+               rot.items.mat4_set(
+                                 c2*c3,          -c2*s3,   -s2, 0.0,
+                        c1*s3+c3*s1*s2,  c1*c3-s1*s2*s3, c2*s1, 0.0,
+                       -s1*s3+c1*c3*s2, -c3*s1-c1*s2*s3, c1*c2, 0.0,
+                                   0.0,             0.0,   0.0, 1.0)
 
                rotation_matrix_cache = rot
                rotation_pitch = pitch
@@ -192,6 +194,30 @@ redef class Matrix
        end
 end
 
+redef class NativeDoubleArray
+       fun mat4_set(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15: Float) `{
+               self[ 0] =  f0;
+               self[ 1] =  f1;
+               self[ 2] =  f2;
+               self[ 3] =  f3;
+
+               self[ 4] =  f4;
+               self[ 5] =  f5;
+               self[ 6] =  f6;
+               self[ 7] =  f7;
+
+               self[ 8] =  f8;
+               self[ 9] =  f9;
+               self[10] = f10;
+               self[11] = f11;
+
+               self[12] = f12;
+               self[13] = f13;
+               self[14] = f14;
+               self[15] = f15;
+       `}
+end
+
 redef class Sys
 
        private var rotation_matrix_cache: nullable Matrix = null