deepstone

view src/vmath.h @ 37:e5e01cd2c995

changed the VC project file to use the non-dll versions of msvcrt
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Sep 2013 08:06:04 +0300
parents 61d97b17cd2b
children
line source
1 #ifndef VMATH_H_
2 #define VMATH_H_
4 #include <math.h>
5 #include "fixedp.h"
7 #ifndef M_PI
8 #define M_PI 3.1415926536
9 #endif
11 typedef struct {
12 float x, y, z, w;
13 } vec4_t;
15 typedef struct {
16 float x, y, z;
17 } vec3_t;
19 typedef struct {
20 float x, y;
21 } vec2_t;
23 typedef struct {
24 fixed x, y, z, w;
25 } vec4x_t;
27 typedef struct {
28 fixed x, y, z;
29 } vec3x_t;
31 typedef struct {
32 fixed x, y;
33 } vec2x_t;
35 typedef struct {
36 vec3_t origin, dir;
37 } ray3_t;
39 #define vec3_dot(a, b) ((a).x * (b).x + (a).y * (b).y + (a).z * (b).z)
41 #define vec2_lerp(res, a, b, t) \
42 do { \
43 (res).x = (a).x + ((b).x - (a).x) * (t); \
44 (res).y = (a).y + ((b).y - (a).y) * (t); \
45 } while(0)
47 #define vec3_lerp(res, a, b, t) \
48 do { \
49 (res).x = (a).x + ((b).x - (a).x) * (t); \
50 (res).y = (a).y + ((b).y - (a).y) * (t); \
51 (res).z = (a).z + ((b).z - (a).z) * (t); \
52 } while(0)
54 #define ray3_point(res, ray, t) \
55 do { \
56 (res).x = (ray).origin.x + (ray).dir.x * (t); \
57 (res).y = (ray).origin.y + (ray).dir.y * (t); \
58 (res).z = (ray).origin.z + (ray).dir.z * (t); \
59 } while(0)
61 #define vec2_to_fixed2(v, f) \
62 do { \
63 (f).x = fixedf((v).x); \
64 (f).y = fixedf((v).y); \
65 } while(0)
67 #define vec3_to_fixed3(v, f) \
68 do { \
69 (f).x = fixedf((v).x); \
70 (f).y = fixedf((v).y); \
71 (f).z = fixedf((v).z); \
72 } while(0)
74 #define vec4_to_fixed4(v, f) \
75 do { \
76 (f).x = fixedf((v).x); \
77 (f).y = fixedf((v).y); \
78 (f).z = fixedf((v).z); \
79 (f).w = fixedf((v).w); \
80 } while(0)
83 #define fixed2_to_vec2(f, v) \
84 do { \
85 (v).x = fixed_float((f).x); \
86 (v).y = fixed_float((f).y); \
87 } while(0)
89 #define fixed3_to_vec3(f, v) \
90 do { \
91 (v).x = fixed_float((f).x); \
92 (v).y = fixed_float((f).y); \
93 (v).z = fixed_float((f).z); \
94 } while(0)
96 #define fixed4_to_vec4(f, v) \
97 do { \
98 (v).x = fixed_float((f).x); \
99 (v).y = fixed_float((f).y); \
100 (v).z = fixed_float((f).z); \
101 (v).w = fixed_float((f).w); \
102 } while(0)
105 #endif /* VMATH_H_ */