1 module matmul;
2 
3 import std.stdio;
4 
5 enum iter = 1_000_000;
6 
7 extern(C) int glm_matmul();
8 
9 int glmMatMul() {
10     return glm_matmul();
11 }
12 
13 int gfxMatMul() {
14     import gfx.math;
15     const axis = fvec(1, 2, 3);
16     const sc = fvec(0.5, 2, 0.5);
17     const tr = fvec(4, 5, 6);
18     const even = rotation(0.01, axis) * scale(sc) * translation(tr);
19     const odd = rotation(0.01, axis) * scale(1f / sc) * translation(-tr);
20     auto m = FMat4.identity;
21 
22     foreach (i; 0 .. iter) {
23         if (i % 2) {
24             m = odd * m;
25         }
26         else {
27             m = even * m;
28         }
29     }
30 
31     // writeln("gfx:", m);
32     if (m == FMat4.identity) {
33         writeln("only to make sure computation is not optimized away");
34     }
35 
36     return iter;
37 }
38 
39 
40 int gl3nMatMul() {
41     import gl3n.linalg;
42     const axis = vec3(1, 2, 3);
43     const sc = vec3(0.5, 2, 0.5);
44     const tr = vec3(4, 5, 6);
45     const r = quat.axis_rotation(0.01, axis.normalized).to_matrix!(4, 4);
46     const even = r * mat4.scaling(sc.x, sc.y, sc.z) * mat4.translation(tr);
47     const odd = r * mat4.scaling(1f/sc.x, 1f/sc.y, 1f/sc.z) * mat4.translation(-tr);
48     auto m = mat4.identity;
49 
50     foreach (i; 0 .. iter) {
51         if (i % 2) {
52             m = odd * m;
53         }
54         else {
55             m = even * m;
56         }
57     }
58 
59     //writeln("gl3n:", m);
60     if (m == mat4.identity) {
61         writeln("only to make sure computation is not optimized away");
62     }
63     return iter;
64 }
65