… | |
… | |
28 | #define OFFS_BITS 31 |
28 | #define OFFS_BITS 31 |
29 | #define SOFFS_MIN (soffs)-(1 << (OFFS_BITS - 2)) |
29 | #define SOFFS_MIN (soffs)-(1 << (OFFS_BITS - 2)) |
30 | #define SOFFS_MAX (soffs)+(1 << (OFFS_BITS - 2)) |
30 | #define SOFFS_MAX (soffs)+(1 << (OFFS_BITS - 2)) |
31 | #define MAXEXTENT (1UL << (OFFS_BITS - 1)) |
31 | #define MAXEXTENT (1UL << (OFFS_BITS - 1)) |
32 | |
32 | |
33 | #define GLFLOAT_MAX 1e30 |
|
|
34 | #define GLFLOAT_MIN -1e30 |
|
|
35 | |
|
|
36 | struct vec3 { |
|
|
37 | GLfloat x, y, z; |
|
|
38 | vec3 () { }; |
|
|
39 | vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; |
|
|
40 | |
|
|
41 | const vec3 operator -() const |
|
|
42 | { return vec3 (-x, -y, -z); } |
|
|
43 | }; |
|
|
44 | |
|
|
45 | const vec3 normalize (const vec3 &v); |
|
|
46 | const vec3 cross (const vec3 &a, const vec3 &b); |
|
|
47 | |
|
|
48 | inline const vec3 operator *(const vec3 &a, GLfloat s) |
|
|
49 | { |
|
|
50 | return vec3 (a.x * s, a.y * s, a.z * s); |
|
|
51 | } |
|
|
52 | |
|
|
53 | inline const vec3 operator +(const vec3 &a, const vec3 &b) |
|
|
54 | { |
|
|
55 | return vec3 (a.x + b.x, a.y + b.y, a.z + b.z); |
|
|
56 | } |
|
|
57 | |
|
|
58 | inline const vec3 operator -(const vec3 &a, const vec3 &b) |
|
|
59 | { |
|
|
60 | return vec3 (a.x - b.x, a.y - b.y, a.z - b.z); |
|
|
61 | } |
|
|
62 | |
|
|
63 | inline GLfloat dot (const vec3 &a, const vec3 &b) |
|
|
64 | { |
|
|
65 | return a.x * b.x + a.y * b.y + a.z * b.z; |
|
|
66 | } |
|
|
67 | |
|
|
68 | inline const GLfloat abs (const vec3 &v) |
|
|
69 | { |
|
|
70 | return sqrtf (dot (v, v)); |
|
|
71 | } |
|
|
72 | |
|
|
73 | struct matrix { |
|
|
74 | GLfloat data[4][4]; |
|
|
75 | |
|
|
76 | const GLfloat operator ()(int i, int j) const { return data[j][i]; }; |
|
|
77 | GLfloat &operator ()(int i, int j) { return data[j][i]; }; |
|
|
78 | |
|
|
79 | void diagonal (GLfloat v); |
|
|
80 | void clear () { diagonal (0.); }; |
|
|
81 | void identity () { diagonal (1.); }; |
|
|
82 | |
|
|
83 | void print (); // ugly |
|
|
84 | |
|
|
85 | static const matrix translation (const vec3 &v); |
|
|
86 | static const matrix rotation (GLfloat degrees, const vec3 &axis); |
|
|
87 | |
|
|
88 | matrix () { }; |
|
|
89 | matrix (GLfloat diag) { diagonal (diag); }; |
|
|
90 | }; |
|
|
91 | |
|
|
92 | const matrix operator *(const matrix &a, const matrix &b); |
|
|
93 | const vec3 operator *(const matrix &a, const vec3 &v); |
|
|
94 | |
|
|
95 | typedef vec3 point; |
|
|
96 | |
|
|
97 | // a generic plane |
|
|
98 | struct plane { |
|
|
99 | vec3 n; |
|
|
100 | GLfloat d; |
|
|
101 | |
|
|
102 | GLfloat distance (const point &p) const |
|
|
103 | { |
|
|
104 | return dot (n, p) + d; |
|
|
105 | } |
|
|
106 | |
|
|
107 | plane () { }; |
|
|
108 | plane (GLfloat a, GLfloat b, GLfloat c, GLfloat d); |
|
|
109 | }; |
|
|
110 | |
|
|
111 | struct sector { |
33 | struct sector { |
112 | soffs x, y, z; |
34 | soffs x, y, z; |
113 | |
35 | |
114 | sector (soffs x, soffs y, soffs z) : x(x), y(y), z(z) { }; |
36 | sector (soffs x, soffs y, soffs z) : x(x), y(y), z(z) { }; |
115 | sector (soffs xyz = 0) : x(xyz), y(xyz), z(xyz) { }; |
37 | sector (soffs xyz = 0) : x(xyz), y(xyz), z(xyz) { }; |
… | |
… | |
154 | |
76 | |
155 | inline sector abs (const sector &s) |
77 | inline sector abs (const sector &s) |
156 | { |
78 | { |
157 | return sector (abs (s.x), abs (s.y), abs (s.z)); |
79 | return sector (abs (s.x), abs (s.y), abs (s.z)); |
158 | } |
80 | } |
|
|
81 | |
|
|
82 | struct vec3 { |
|
|
83 | GLfloat x, y, z; |
|
|
84 | vec3 () { }; |
|
|
85 | vec3 (GLfloat s) : x(s), y(s), z(s) { }; |
|
|
86 | vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; |
|
|
87 | vec3 (const sector &s) : x(s.x), y(s.y), z(s.z) { }; |
|
|
88 | |
|
|
89 | const vec3 operator -() const |
|
|
90 | { return vec3 (-x, -y, -z); } |
|
|
91 | }; |
|
|
92 | |
|
|
93 | const vec3 normalize (const vec3 &v); |
|
|
94 | const vec3 cross (const vec3 &a, const vec3 &b); |
|
|
95 | |
|
|
96 | inline const vec3 operator *(const vec3 &a, GLfloat s) |
|
|
97 | { |
|
|
98 | return vec3 (a.x * s, a.y * s, a.z * s); |
|
|
99 | } |
|
|
100 | |
|
|
101 | inline const vec3 operator +(const vec3 &a, const vec3 &b) |
|
|
102 | { |
|
|
103 | return vec3 (a.x + b.x, a.y + b.y, a.z + b.z); |
|
|
104 | } |
|
|
105 | |
|
|
106 | inline const vec3 operator -(const vec3 &a, const vec3 &b) |
|
|
107 | { |
|
|
108 | return vec3 (a.x - b.x, a.y - b.y, a.z - b.z); |
|
|
109 | } |
|
|
110 | |
|
|
111 | inline GLfloat dot (const vec3 &a, const vec3 &b) |
|
|
112 | { |
|
|
113 | return a.x * b.x + a.y * b.y + a.z * b.z; |
|
|
114 | } |
|
|
115 | |
|
|
116 | inline const GLfloat abs (const vec3 &v) |
|
|
117 | { |
|
|
118 | return sqrtf (dot (v, v)); |
|
|
119 | } |
|
|
120 | |
|
|
121 | struct matrix { |
|
|
122 | GLfloat data[4][4]; |
|
|
123 | |
|
|
124 | const GLfloat operator ()(int i, int j) const { return data[j][i]; }; |
|
|
125 | GLfloat &operator ()(int i, int j) { return data[j][i]; }; |
|
|
126 | |
|
|
127 | void diagonal (GLfloat v); |
|
|
128 | void clear () { diagonal (0.F); }; |
|
|
129 | void identity () { diagonal (1.F); }; |
|
|
130 | |
|
|
131 | void print (); // ugly |
|
|
132 | |
|
|
133 | static const matrix translation (const vec3 &v); |
|
|
134 | static const matrix rotation (GLfloat degrees, const vec3 &axis); |
|
|
135 | |
|
|
136 | matrix () { }; |
|
|
137 | matrix (GLfloat diag) { diagonal (diag); }; |
|
|
138 | }; |
|
|
139 | |
|
|
140 | const matrix operator *(const matrix &a, const matrix &b); |
|
|
141 | const vec3 operator *(const matrix &a, const vec3 &v); |
|
|
142 | |
|
|
143 | typedef vec3 point; |
|
|
144 | |
|
|
145 | // a generic plane |
|
|
146 | struct plane { |
|
|
147 | vec3 n; |
|
|
148 | GLfloat d; |
|
|
149 | |
|
|
150 | GLfloat distance (const point &p) const |
|
|
151 | { |
|
|
152 | return dot (n, p) + d; |
|
|
153 | } |
|
|
154 | |
|
|
155 | plane () { }; |
|
|
156 | plane (GLfloat a, GLfloat b, GLfloat c, GLfloat d); |
|
|
157 | }; |
159 | |
158 | |
160 | void renormalize (sector &s, point &p); |
159 | void renormalize (sector &s, point &p); |
161 | |
160 | |
162 | struct colour { |
161 | struct colour { |
163 | GLfloat r, g, b, a; |
162 | GLfloat r, g, b, a; |
… | |
… | |
206 | }; |
205 | }; |
207 | |
206 | |
208 | struct entity; |
207 | struct entity; |
209 | struct geometry; |
208 | struct geometry; |
210 | struct view; |
209 | struct view; |
|
|
210 | struct octant; |
211 | |
211 | |
212 | extern struct timer { |
212 | extern struct timer { |
213 | static double now; |
213 | static double now; |
214 | static double diff; |
214 | static double diff; |
215 | |
215 | |