]> git.lizzy.rs Git - nothing.git/blob - src/mat3x3.c
(#118) Typo
[nothing.git] / src / mat3x3.c
1 #include <math.h>
2 #include "./mat3x3.h"
3
4 mat3x3 mat3x3_product(mat3x3 m1, mat3x3 m2)
5 {
6     mat3x3 result;
7
8     for (int i = 0; i < 3; ++i) {
9         for (int j = 0; j < 3; ++j) {
10             result.M[i][j] = 0;
11             for (int k = 0; k < 3; ++k) {
12                 result.M[i][j] += m1.M[i][k] * m2.M[k][j];
13             }
14         }
15     }
16
17     return result;
18 }
19
20 mat3x3 mat3x3_product2(mat3x3 m1, mat3x3 m2, mat3x3 m3)
21 {
22     return mat3x3_product(m1, mat3x3_product(m2, m3));
23 }
24
25 mat3x3 trans_mat(float x, float y)
26 {
27     const mat3x3 m = {
28         .M = {
29             {1.0f, 0.0f, x},
30             {0.0f, 1.0f, y},
31             {0.0f, 0.0f, 1.0f}
32         }
33     };
34
35     return m;
36 }
37
38 mat3x3 rot_mat(float angle)
39 {
40     const mat3x3 m = {
41         .M = {
42             {cosf(angle), -sinf(angle), 0.0f},
43             {sinf(angle), cosf(angle), 0.0f},
44             {0.0f, 0.0f, 1.0f}
45         }
46     };
47
48     return m;
49 }
50
51 mat3x3 scale_mat(float factor)
52 {
53     const mat3x3 m = {
54         .M = {
55             {factor, 0.0f, 0.0f},
56             {0.0f, factor, 0.0f},
57             {0.0f, 0.0f, 1.0f}
58         }
59     };
60
61     return m;
62 }