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