-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
88 lines (67 loc) · 1.69 KB
/
test.c
File metadata and controls
88 lines (67 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <assert.h>
#include "vec.h"
#include "mat4.h"
#include "transform.h"
# define M_PI 3.14159265358979323846 /* pi */
# define M_PI_2 1.57079632679489661923 /* pi/2 */
# define M_PI_4 0.78539816339744830962 /* pi/4 */
void test_projectOnPlane()
{
assert(vec3_equal(projectOnPlane(vec3_add(vec3_right, vec3_up), vec3_right), vec3_right));
}
void test_mat4mul()
{
assert(mat4_equal(mat4mul(mat4_identity, mat4_identity), mat4_identity));
}
void test_transpose()
{
assert(mat4_equal(mat4_Transpose(mat4_identity), mat4_identity));
}
void test_transform()
{
{
struct transform_t t;
t.position = vec3_forward;
t.rotation = vec3_zero;
t.scale = vec3_one;
assert(vec3_equal(Transform(t, vec3_zero), vec3_forward));
}
{
struct transform_t t;
t.position = vec3_zero;
t.rotation = vec3_zero;
t.scale = vec3_mul(vec3_one, 2);
assert(vec3_equal(Transform(t, vec3_forward), vec3_mul(vec3_forward, 2)));
}
{
struct transform_t t;
t.position = vec3_zero;
t.rotation = vec3_mul(vec3_forward, 90);
t.scale = vec3_one;
assert(vec3_angle(Transform(t, vec3_up), vec3_right) < 0.1f);
}
}
void test_inv_transform()
{
{
struct transform_t t;
t.position = vec3_forward;
t.rotation = vec3_zero;
t.scale = vec3_one;
assert(vec3_equal(InverseTransform(t, vec3_forward), vec3_zero));
}
{
struct transform_t t;
t.position = vec3_zero;
t.rotation = vec3_zero;
t.scale = vec3_mul(vec3_one, 2);
assert(vec3_equal(InverseTransform(t, vec3_mul(vec3_forward, 2)), vec3_forward));
}
{
struct transform_t t;
t.position = vec3_zero;
t.rotation = vec3_mul(vec3_forward, 90);
t.scale = vec3_one;
assert(vec3_angle(InverseTransform(t, vec3_right), vec3_up) < 0.1f);
}
}