summaryrefslogtreecommitdiff
path: root/maths.h
blob: 6d33c6f0c2a380e2c9e5545b4e1a9e98fcfc98da (plain) (blame)
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
#ifndef maths_h
#define maths_h

#define mini(a_, b_) ((a_) < (b_) ? (a_) : (b_))
#define maxi(a_, b_) ((a_) > (b_) ? (a_) : (b_))
#define clamp(v_, min_, max_) (maxi(min_, mini(max_, v_)))
#define absolute(v_) ((v_) < 0? -(v_): (v_))

#define fbits 9
#define f1 (1 << fbits)

#define sin_table_count  0x100
#define sin_table_mask   0x0ff
#define sqrt_table_count 0x800
#define sqrt_table_mask  0x07f

extern int sin_table[sin_table_count];
extern int cos_table[sin_table_count];
extern int sqrt_table[sqrt_table_count];

void init_maths(void);

int fpow(int a, int p);

int* mtx_iden(int* m);
int* mtx_cpy(int* d, const int* s);
int* mtx_mul(int* d, const int* a, const int* b);
void mtx_push(const int* m);
void mtx_push_trans(int* v);
void mtx_push_rot_x(int a);
void mtx_push_rot_y(int a);
void mtx_push_rot_z(int a);
int* mtx_pop(void);
int* mtx_popn(int n);
int* mtx_peek(void);
int* mtx_trans(int* d, int* v);
int* mtx_rot_x(int* d, int a);
int* mtx_rot_y(int* d, int a);
int* mtx_rot_z(int* d, int a);
int* mtx_apply(const int* m, int* v);
int* vec_cpy(int* d, const int* s, int c);
int* vec_ref(int* d, const int* i, const int* n, int c);
int vec_dot(const int* a, const int* b, int d);
void persp(int* v, int asp);
void ndc2clip(int* c, int* p);

#endif