deepstone

view src/vmath.h @ 25:5ff8ce78059a

first pass at converting the rasterizer to fixed point
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 22 Sep 2013 02:21:30 +0300
parents 00d84ab1ef26
children 61d97b17cd2b
line source
1 #ifndef VMATH_H_
2 #define VMATH_H_
4 #include <math.h>
5 #include "fixed_point.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;
36 #define vec2_to_fixed2(v, f) \
37 do { \
38 f.x = fixedf(v.x); \
39 f.y = fixedf(v.y); \
40 } while(0)
42 #define vec3_to_fixed3(v, f) \
43 do { \
44 f.x = fixedf(v.x); \
45 f.y = fixedf(v.y); \
46 f.z = fixedf(v.z); \
47 } while(0)
49 #define vec4_to_fixed4(v, f) \
50 do { \
51 f.x = fixedf(v.x); \
52 f.y = fixedf(v.y); \
53 f.z = fixedf(v.z); \
54 f.w = fixedf(v.w); \
55 } while(0)
58 #define fixed2_to_vec2(f, v) \
59 do { \
60 v.x = fixed_float(f.x); \
61 v.y = fixed_float(f.y); \
62 } while(0)
64 #define fixed3_to_vec3(f, v) \
65 do { \
66 v.x = fixed_float(f.x); \
67 v.y = fixed_float(f.y); \
68 v.z = fixed_float(f.z); \
69 } while(0)
71 #define fixed4_to_vec4(f, v) \
72 do { \
73 v.x = fixed_float(f.x); \
74 v.y = fixed_float(f.y); \
75 v.z = fixed_float(f.z); \
76 v.w = fixed_float(f.w); \
77 } while(0)
80 #endif /* VMATH_H_ */