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
|
#ifndef MY_MATH_H
#define MY_MATH_H
#include "types.h"
typedef struct {f32 x, y;} v2;
typedef struct {f32 x, y, z;} v3;
typedef struct {f32 x, y, z, w;} v4;
typedef struct {v4 c0, c1, c2, c3;} mat;
typedef enum {direction_right, direction_up, direction_left, direction_down} direction_enum;
#define mat_identity { \
{1.0f, 0.0f, 0.0f, 0.0f}, \
{0.0f, 1.0f, 0.0f, 0.0f}, \
{0.0f, 0.0f, 1.0f, 0.0f}, \
{0.0f, 0.0f, 0.0f, 1.0f}}
#define f32pi 3.1415926535f
#define deg2rad(a) (a) * f32pi / 180.0f
#define rad2deg(a) (a) * 180.0f / f32pi
extern v2 v2a(f32 x);
extern v3 v3a(f32 x);
extern v2 scale_v2(v2 v, f32 x);
extern v2 add_v2(v2 a, v2 b);
extern v2 addf_v2(v2 a, f32 b);
extern v2 sub_v2(v2 a, v2 b);
extern v2 clamp_v2(v2 v, v2 min, v2 max);
extern f32 length_v2(v2 v);
extern f32 dot_v2(v2 a, v2 b);
extern v2 norm_v2(v2 a);
extern direction_enum direction_v2(v2 v);
extern mat mul_mat(mat l, mat r);
extern mat make_scale_mat(v3 v);
extern mat make_rotate_mat(v3 x, v3 y, v3 z);
extern mat make_translate_mat(v3 v);
extern mat scale_mat(mat m, v3 v);
extern mat rotate_mat(mat m, v3 angles);
extern mat translate_mat(mat m, v3 v);
extern mat ortho(f32 l, f32 r, f32 b, f32 t, f32 n, f32 f);
#endif
|