-
Notifications
You must be signed in to change notification settings - Fork 17
/
ol3d_matrix.h
70 lines (59 loc) · 1.99 KB
/
ol3d_matrix.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
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
#ifndef _OL3D_MATRIX_H_
#define _OL3D_MATRIX_H_
// 4x4 matrix
typedef float ol3d_matrix_t[16];
#define PI 3.1415926535898
#define R(angle) ((angle) * PI/180)
#define MATRIX_UNIT {\
1, 0, 0, 0,\
0, 1, 0, 0,\
0, 0, 1, 0,\
0, 0, 0, 1 \
}
#define MATRIX_TRANSLATE(x, y, z) {\
1, 0, 0, 0,\
0, 1, 0, 0,\
0, 0, 1, 0,\
(x), (y), (z), 1 \
}
#define MATRIX_SCALE(x, y, z) {\
(x), 0, 0, 0,\
0, (y), 0, 0,\
0, 0, (z), 0,\
0, 0, 0, 1 \
}
#define MATRIX_ROTATE_X(a) {\
1, 0, 0, 0,\
0, cos(R(a)), sin(R(a)), 0,\
0, -sin(R(a)), cos(R(a)), 0,\
0, 0, 0, 1 \
}
#define MATRIX_ROTATE_Y(a) {\
cos(R(a)), 0, sin(R(a)), 0,\
0, 1, 0, 0,\
-sin(R(a)), 0, cos(R(a)), 0,\
0, 0, 0, 1 \
}
#define MATRIX_ROTATE_Z(a) {\
cos(R(a)), sin(R(a)), 0, 0,\
-sin(R(a)), cos(R(a)), 0, 0,\
0, 0, 1, 0,\
0, 0, 0, 1 \
}
#define M_AXIS_X 0x0001
#define M_AXIS_Y 0x0002
#define M_AXIS_Z 0x0004
extern void ol3d_matrix_setUnit(ol3d_matrix_t a);
extern void ol3d_matrix_setTranslate(ol3d_matrix_t a, float x, float y, float z);
extern void ol3d_matrix_setScale(ol3d_matrix_t a, float x, float y, float z);
extern void ol3d_matrix_setRotate(ol3d_matrix_t a, float angle, unsigned char axis);
extern void ol3d_matrix_setPerspective(ol3d_matrix_t a, double fov, double aspect, double near, double far);
extern void ol3d_matrix_copy(ol3d_matrix_t a, ol3d_matrix_t b);
extern void ol3d_matrix_transpose(ol3d_matrix_t a);
extern float ol3d_matrix_multi_chunk(ol3d_matrix_t a, ol3d_matrix_t b, unsigned char pos);
extern void ol3d_matrix_multiply(ol3d_matrix_t a, ol3d_matrix_t b, ol3d_matrix_t c);
extern void ol3d_matrix_translate(ol3d_matrix_t a, float x, float y, float z);
extern void ol3d_matrix_scale(ol3d_matrix_t a, float x, float y, float z);
extern void ol3d_matrix_rotate(ol3d_matrix_t a, float angle, unsigned char axis);
extern void ol3d_matrix_multi_v3(ol3d_Vector3_t *a, ol3d_matrix_t b);
#endif