diff options
author | 3gg <3gg@shellblade.net> | 2021-12-04 18:39:11 -0800 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2021-12-04 18:39:11 -0800 |
commit | a10d28667d734dfc27b0eaac5444ff944d046b94 (patch) | |
tree | 20cba40a010882aee60f9c6502ce569d9fbe81e9 /test/mat4_test.c | |
parent | f144bda46d7445d1cedaf84a1b6d13f2a2258ca5 (diff) |
Initial commit.
Diffstat (limited to 'test/mat4_test.c')
-rw-r--r-- | test/mat4_test.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/test/mat4_test.c b/test/mat4_test.c new file mode 100644 index 0000000..d4f61bc --- /dev/null +++ b/test/mat4_test.c | |||
@@ -0,0 +1,111 @@ | |||
1 | #include <math/mat4.h> | ||
2 | |||
3 | #include <math/float.h> | ||
4 | |||
5 | #include "test.h" | ||
6 | |||
7 | #include <stdio.h> | ||
8 | |||
9 | static const float eps = 1e-9; | ||
10 | |||
11 | static inline void print_mat4(mat4 m) { | ||
12 | printf("\n"); | ||
13 | for (int i = 0; i < 4; ++i) { | ||
14 | for (int j = 0; j < 4; ++j) { | ||
15 | printf("%6.3f ", mat4_at(m, i, j)); | ||
16 | } | ||
17 | printf("\n"); | ||
18 | } | ||
19 | } | ||
20 | |||
21 | TEST_CASE(lookat_right) { | ||
22 | const mat4 m = mat4_lookat(/*position=*/vec3_make(0, 0, 0), | ||
23 | /*target=*/vec3_make(1, 0, 0), | ||
24 | /*up=*/vec3_make(0, 1, 0)); | ||
25 | |||
26 | const mat4 expected = mat4_from_array((const float*)(float[4][4]){ | ||
27 | {0, 0, 1, 0}, | ||
28 | {0, 1, 0, 0}, | ||
29 | {1, 0, 0, 0}, | ||
30 | {0, 0, 0, 1}, | ||
31 | }); | ||
32 | |||
33 | TEST_TRUE(mat4_eq(m, expected, eps)); | ||
34 | } | ||
35 | |||
36 | TEST_CASE(lookat_left) { | ||
37 | const mat4 m = mat4_lookat(/*position=*/vec3_make(0, 0, 0), | ||
38 | /*target=*/vec3_make(-1, 0, 0), | ||
39 | /*up=*/vec3_make(0, 1, 0)); | ||
40 | |||
41 | const mat4 expected = mat4_from_array((const float*)(float[4][4]){ | ||
42 | {0, 0, -1, 0}, | ||
43 | {0, 1, 0, 0}, | ||
44 | {-1, 0, 0, 0}, | ||
45 | {0, 0, 0, 1}, | ||
46 | }); | ||
47 | |||
48 | TEST_TRUE(mat4_eq(m, expected, eps)); | ||
49 | } | ||
50 | |||
51 | TEST_CASE(lookat_up) { | ||
52 | const mat4 m = mat4_lookat(/*position=*/vec3_make(0, 0, 0), | ||
53 | /*target=*/vec3_make(0, 1, 0), | ||
54 | /*up=*/vec3_make(0, 0, 1)); | ||
55 | |||
56 | const mat4 expected = mat4_from_array((const float*)(float[4][4]){ | ||
57 | {1, 0, 0, 0}, | ||
58 | {0, 0, 1, 0}, | ||
59 | {0, 1, 0, 0}, | ||
60 | {0, 0, 0, 1}, | ||
61 | }); | ||
62 | |||
63 | TEST_TRUE(mat4_eq(m, expected, eps)); | ||
64 | } | ||
65 | |||
66 | TEST_CASE(lookat_down) { | ||
67 | const mat4 m = mat4_lookat(/*position=*/vec3_make(0, 0, 0), | ||
68 | /*target=*/vec3_make(0, -1, 0), | ||
69 | /*up=*/vec3_make(0, 0, -1)); | ||
70 | |||
71 | const mat4 expected = mat4_from_array((const float*)(float[4][4]){ | ||
72 | {1, 0, 0, 0}, | ||
73 | {0, 0, -1, 0}, | ||
74 | {0, -1, 0, 0}, | ||
75 | {0, 0, 0, 1}, | ||
76 | }); | ||
77 | |||
78 | TEST_TRUE(mat4_eq(m, expected, eps)); | ||
79 | } | ||
80 | |||
81 | TEST_CASE(lookat_forward) { | ||
82 | const mat4 m = mat4_lookat(/*position=*/vec3_make(0, 0, 0), | ||
83 | /*target=*/vec3_make(0, 0, -1), | ||
84 | /*up=*/vec3_make(0, 1, 0)); | ||
85 | |||
86 | const mat4 expected = mat4_from_array((const float*)(float[4][4]){ | ||
87 | {1, 0, 0, 0}, | ||
88 | {0, 1, 0, 0}, | ||
89 | {0, 0, -1, 0}, | ||
90 | {0, 0, 0, 1}, | ||
91 | }); | ||
92 | |||
93 | TEST_TRUE(mat4_eq(m, expected, eps)); | ||
94 | } | ||
95 | |||
96 | TEST_CASE(lookat_back) { | ||
97 | const mat4 m = mat4_lookat(/*position=*/vec3_make(0, 0, 0), | ||
98 | /*target=*/vec3_make(0, 0, 1), | ||
99 | /*up=*/vec3_make(0, 1, 0)); | ||
100 | |||
101 | const mat4 expected = mat4_from_array((const float*)(float[4][4]){ | ||
102 | {-1, 0, 0, 0}, | ||
103 | {0, 1, 0, 0}, | ||
104 | {0, 0, 1, 0}, | ||
105 | {0, 0, 0, 1}, | ||
106 | }); | ||
107 | |||
108 | TEST_TRUE(mat4_eq(m, expected, eps)); | ||
109 | } | ||
110 | |||
111 | int main() { return 0; } | ||