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