-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatlib.h
More file actions
190 lines (133 loc) · 3.26 KB
/
matlib.h
File metadata and controls
190 lines (133 loc) · 3.26 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#pragma once
#include <math.h>
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
typedef struct Vec Vec;
typedef struct Mat Mat;
typedef struct Qtr Qtr;
/*******************************************************************************
* Matrix type and matrix operations.
*******************************************************************************/
/**
* Mat - 4x4 matrix.
*/
struct Mat {
float data[16];
};
void
mat_mul(const Mat *a, const Mat *b, Mat *r_m);
void
mat_imul(Mat *m, const Mat *other);
void
mat_mulv(const Mat *m, const Vec *v, Vec *r_v);
void
mat_rotate(Mat *m, float x, float y, float z, float angle);
void
mat_rotatev(Mat *m, const Vec *v, float angle);
void
mat_rotateq(Mat *m, const Qtr *q);
Qtr
mat_get_rotation(const Mat *m);
void
mat_scale(Mat *m, float sx, float sy, float sz);
void
mat_scalev(Mat *m, const Vec *sv);
Vec
mat_get_scale(const Mat *m);
void
mat_translate(Mat *m, float tx, float ty, float tz);
void
mat_translatev(Mat *m, const Vec *tv);
Vec
mat_get_translation(const Mat *m);
void
mat_lookat(
Mat *m,
float eye_x, float eye_y, float eye_z,
float center_x, float center_y, float center_z,
float up_x, float up_y, float up_z
);
void
mat_lookatv(Mat *m, const Vec *eye, const Vec *center, const Vec *up);
void
mat_ortho(Mat *m, float l, float r, float t, float b, float n, float f);
void
mat_persp(Mat *m, float fovy, float aspect, float n, float f);
void
mat_ident(Mat *m);
int
mat_inverse(Mat *m, Mat *out_m);
void
mat_transpose(Mat *m, Mat *out_m);
/*******************************************************************************
* Vector type and vector operations.
*******************************************************************************/
/**
* Vec - 4D vector.
*/
struct Vec {
float data[4];
};
Vec
vec(float x, float y, float z, float w);
void
vec_mulf(const Vec *v, float scalar, Vec *r_v);
void
vec_imulf(Vec *v, float scalar);
void
vec_add(const Vec *a, const Vec *b, Vec *r_v);
void
vec_iadd(Vec *v, const Vec *other);
void
vec_addf(const Vec *v, float scalar, Vec *r_v);
void
vec_iaddf(Vec *v, float scalar);
void
vec_sub(const Vec *a, const Vec *b, Vec *r_v);
void
vec_isub(Vec *v, const Vec *b);
void
vec_subf(const Vec *v, float scalar, Vec *r_v);
void
vec_isubf(Vec *v, float scalar);
float
vec_dot(const Vec *a, const Vec *b);
float
vec_mag(const Vec *v);
void
vec_cross(const Vec *a, const Vec *b, Vec *r_v);
void
vec_norm(Vec *v);
void
vec_clamp(Vec *v, float value);
void
vec_lerp(const Vec *a, const Vec *b, float t, Vec *r_v);
/*******************************************************************************
* Quaternion type and quaternion operations
*******************************************************************************/
struct Qtr {
float data[4];
};
Qtr
qtr(float w, float x, float y, float z);
void
qtr_rotate(Qtr *q, float x, float y, float z, float angle);
void
qtr_rotatev(Qtr *q, const Vec *axis, float angle);
void
qtr_add(const Qtr *a, const Qtr *b, Qtr *r_q);
void
qtr_iadd(Qtr *q, const Qtr *other);
void
qtr_mul(const Qtr *a, const Qtr *b, Qtr *r_q);
void
qtr_imul(Qtr *q, const Qtr *other);
void
qtr_mulf(const Qtr *a, float scalar, Qtr *r_q);
void
qtr_imulf(Qtr *q, float scalar);
void
qtr_norm(Qtr *a);
void
qtr_lerp(const Qtr *a, const Qtr *b, float t, Qtr *r_q);