-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinalg.h
45 lines (31 loc) · 1.04 KB
/
linalg.h
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
#ifndef LINALG_H
#define LINALG_H
#define SCALE 12
#ifndef ONE
#define ONE (1 << SCALE)
#endif
#define HALF (ONE >> 1)
#define IntToFixed(x) ((x) << SCALE)
#define FixedToInt(x) ((x) >> SCALE)
#define FixedMulInt(x, y) ((x) * (y))
#define FixedMulFixed(x, y) (((x) * (y)) >> SCALE)
#define FixedDivInt(x, y) ((x) / (y))
#define FixedDivFixed(x, y) (((x) << SCALE) / (y))
enum { X = 0, Y, Z, W };
// TODO: define type to notify that a variable is actually fixed point?
typedef int vec2[2];
typedef int vec3[3];
typedef int quat[4];
void quat_rotate_point(const quat q, const vec3 in, vec3 out);
// trigonometry
#define M_PI 2048
int iSin(int x);
#define iCos(x) (iSin(x + 1024))
// clip
int tri_clip(RECT* clip, DVECTOR* v0, DVECTOR* v1, DVECTOR* v2);
int quad_clip(RECT* clip, DVECTOR* v0, DVECTOR* v1, DVECTOR* v2, DVECTOR* v3);
// normals
void crossProduct(SVECTOR* v0, SVECTOR* v1, VECTOR* out);
void surfaceNormal(SVECTOR* v1, SVECTOR* v2, SVECTOR* v3, SVECTOR* out);
void centroid(SVECTOR* v1, SVECTOR* v2, SVECTOR* v3, SVECTOR* out);
#endif