rev |
line source |
nuclear@15
|
1 #ifndef VMATH_H_
|
nuclear@15
|
2 #define VMATH_H_
|
nuclear@15
|
3
|
nuclear@21
|
4 #include <math.h>
|
nuclear@26
|
5 #include "fixedp.h"
|
nuclear@21
|
6
|
nuclear@21
|
7 #ifndef M_PI
|
nuclear@21
|
8 #define M_PI 3.1415926536
|
nuclear@21
|
9 #endif
|
nuclear@21
|
10
|
nuclear@15
|
11 typedef struct {
|
nuclear@15
|
12 float x, y, z, w;
|
nuclear@15
|
13 } vec4_t;
|
nuclear@15
|
14
|
nuclear@15
|
15 typedef struct {
|
nuclear@15
|
16 float x, y, z;
|
nuclear@15
|
17 } vec3_t;
|
nuclear@15
|
18
|
nuclear@15
|
19 typedef struct {
|
nuclear@15
|
20 float x, y;
|
nuclear@15
|
21 } vec2_t;
|
nuclear@15
|
22
|
nuclear@25
|
23 typedef struct {
|
nuclear@25
|
24 fixed x, y, z, w;
|
nuclear@25
|
25 } vec4x_t;
|
nuclear@25
|
26
|
nuclear@25
|
27 typedef struct {
|
nuclear@25
|
28 fixed x, y, z;
|
nuclear@25
|
29 } vec3x_t;
|
nuclear@25
|
30
|
nuclear@25
|
31 typedef struct {
|
nuclear@25
|
32 fixed x, y;
|
nuclear@25
|
33 } vec2x_t;
|
nuclear@25
|
34
|
nuclear@28
|
35 typedef struct {
|
nuclear@28
|
36 vec3_t origin, dir;
|
nuclear@28
|
37 } ray3_t;
|
nuclear@28
|
38
|
nuclear@28
|
39 #define vec3_dot(a, b) ((a).x * (b).x + (a).y * (b).y + (a).z * (b).z)
|
nuclear@28
|
40
|
nuclear@28
|
41 #define vec2_lerp(res, a, b, t) \
|
nuclear@28
|
42 do { \
|
nuclear@28
|
43 (res).x = (a).x + ((b).x - (a).x) * (t); \
|
nuclear@28
|
44 (res).y = (a).y + ((b).y - (a).y) * (t); \
|
nuclear@28
|
45 } while(0)
|
nuclear@28
|
46
|
nuclear@28
|
47 #define vec3_lerp(res, a, b, t) \
|
nuclear@28
|
48 do { \
|
nuclear@28
|
49 (res).x = (a).x + ((b).x - (a).x) * (t); \
|
nuclear@28
|
50 (res).y = (a).y + ((b).y - (a).y) * (t); \
|
nuclear@28
|
51 (res).z = (a).z + ((b).z - (a).z) * (t); \
|
nuclear@28
|
52 } while(0)
|
nuclear@28
|
53
|
nuclear@28
|
54 #define ray3_point(res, ray, t) \
|
nuclear@28
|
55 do { \
|
nuclear@28
|
56 (res).x = (ray).origin.x + (ray).dir.x * (t); \
|
nuclear@28
|
57 (res).y = (ray).origin.y + (ray).dir.y * (t); \
|
nuclear@28
|
58 (res).z = (ray).origin.z + (ray).dir.z * (t); \
|
nuclear@28
|
59 } while(0)
|
nuclear@25
|
60
|
nuclear@25
|
61 #define vec2_to_fixed2(v, f) \
|
nuclear@25
|
62 do { \
|
nuclear@28
|
63 (f).x = fixedf((v).x); \
|
nuclear@28
|
64 (f).y = fixedf((v).y); \
|
nuclear@25
|
65 } while(0)
|
nuclear@25
|
66
|
nuclear@25
|
67 #define vec3_to_fixed3(v, f) \
|
nuclear@25
|
68 do { \
|
nuclear@28
|
69 (f).x = fixedf((v).x); \
|
nuclear@28
|
70 (f).y = fixedf((v).y); \
|
nuclear@28
|
71 (f).z = fixedf((v).z); \
|
nuclear@25
|
72 } while(0)
|
nuclear@25
|
73
|
nuclear@25
|
74 #define vec4_to_fixed4(v, f) \
|
nuclear@25
|
75 do { \
|
nuclear@28
|
76 (f).x = fixedf((v).x); \
|
nuclear@28
|
77 (f).y = fixedf((v).y); \
|
nuclear@28
|
78 (f).z = fixedf((v).z); \
|
nuclear@28
|
79 (f).w = fixedf((v).w); \
|
nuclear@25
|
80 } while(0)
|
nuclear@25
|
81
|
nuclear@25
|
82
|
nuclear@25
|
83 #define fixed2_to_vec2(f, v) \
|
nuclear@25
|
84 do { \
|
nuclear@28
|
85 (v).x = fixed_float((f).x); \
|
nuclear@28
|
86 (v).y = fixed_float((f).y); \
|
nuclear@25
|
87 } while(0)
|
nuclear@25
|
88
|
nuclear@25
|
89 #define fixed3_to_vec3(f, v) \
|
nuclear@25
|
90 do { \
|
nuclear@28
|
91 (v).x = fixed_float((f).x); \
|
nuclear@28
|
92 (v).y = fixed_float((f).y); \
|
nuclear@28
|
93 (v).z = fixed_float((f).z); \
|
nuclear@25
|
94 } while(0)
|
nuclear@25
|
95
|
nuclear@25
|
96 #define fixed4_to_vec4(f, v) \
|
nuclear@25
|
97 do { \
|
nuclear@28
|
98 (v).x = fixed_float((f).x); \
|
nuclear@28
|
99 (v).y = fixed_float((f).y); \
|
nuclear@28
|
100 (v).z = fixed_float((f).z); \
|
nuclear@28
|
101 (v).w = fixed_float((f).w); \
|
nuclear@25
|
102 } while(0)
|
nuclear@25
|
103
|
nuclear@15
|
104
|
nuclear@15
|
105 #endif /* VMATH_H_ */
|