… | |
… | |
15 | #define SOFFS_MAX (soffs)+(1 << (OFFS_BITS - 2)) |
15 | #define SOFFS_MAX (soffs)+(1 << (OFFS_BITS - 2)) |
16 | #define MAXEXTENT (1UL << (OFFS_BITS - 1)) |
16 | #define MAXEXTENT (1UL << (OFFS_BITS - 1)) |
17 | |
17 | |
18 | #define GLFLOAT_MAX 1e30 |
18 | #define GLFLOAT_MAX 1e30 |
19 | #define GLFLOAT_MIN -1e30 |
19 | #define GLFLOAT_MIN -1e30 |
20 | |
|
|
21 | struct sector { |
|
|
22 | soffs x, y, z; |
|
|
23 | |
|
|
24 | sector (soffs x = 0, soffs y = 0, soffs z = 0) : x(x), y(y), z(z) { }; |
|
|
25 | |
|
|
26 | void offset (int subindex, uoffs extent) |
|
|
27 | { |
|
|
28 | if (subindex & 1) x += extent; |
|
|
29 | if (subindex & 2) y += extent; |
|
|
30 | if (subindex & 4) z += extent; |
|
|
31 | } |
|
|
32 | }; |
|
|
33 | |
|
|
34 | struct point { |
|
|
35 | GLfloat x, y, z; |
|
|
36 | |
|
|
37 | point () { }; |
|
|
38 | point (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; |
|
|
39 | }; |
|
|
40 | |
|
|
41 | inline const sector translate (const sector &p, const sector &src, const sector &dst) |
|
|
42 | { |
|
|
43 | sector r; |
|
|
44 | |
|
|
45 | r.x = p.x + (dst.x - src.x); |
|
|
46 | r.y = p.y + (dst.y - src.y); |
|
|
47 | r.z = p.z + (dst.z - src.z); |
|
|
48 | |
|
|
49 | return r; |
|
|
50 | } |
|
|
51 | |
|
|
52 | void renormalize (sector &s, point &p); |
|
|
53 | |
|
|
54 | struct colour { |
|
|
55 | GLfloat r, g, b, a; |
|
|
56 | colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1., GLfloat a = 1.) : r(r), g(g), b(b), a(a) { }; |
|
|
57 | }; |
|
|
58 | |
20 | |
59 | struct vec3 { |
21 | struct vec3 { |
60 | GLfloat x, y, z; |
22 | GLfloat x, y, z; |
61 | vec3 () { }; |
23 | vec3 () { }; |
62 | vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; |
24 | vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; |
… | |
… | |
102 | gl_matrix (GLfloat diag) { diagonal (diag); }; |
64 | gl_matrix (GLfloat diag) { diagonal (diag); }; |
103 | }; |
65 | }; |
104 | |
66 | |
105 | const gl_matrix operator *(const gl_matrix &a, const gl_matrix &b); |
67 | const gl_matrix operator *(const gl_matrix &a, const gl_matrix &b); |
106 | const vec3 operator *(const gl_matrix &a, const vec3 &v); |
68 | const vec3 operator *(const gl_matrix &a, const vec3 &v); |
|
|
69 | |
|
|
70 | typedef vec3 point; |
|
|
71 | |
|
|
72 | // a generic plane |
|
|
73 | class plane { |
|
|
74 | vec3 n; |
|
|
75 | GLfloat d; |
|
|
76 | public: |
|
|
77 | |
|
|
78 | GLfloat distance (const point &p) const |
|
|
79 | { |
|
|
80 | return dot (n, p) + d; |
|
|
81 | } |
|
|
82 | |
|
|
83 | plane () { }; |
|
|
84 | plane (GLfloat a, GLfloat b, GLfloat c, GLfloat d); |
|
|
85 | }; |
|
|
86 | |
|
|
87 | struct sector { |
|
|
88 | soffs x, y, z; |
|
|
89 | |
|
|
90 | sector (soffs x = 0, soffs y = 0, soffs z = 0) : x(x), y(y), z(z) { }; |
|
|
91 | |
|
|
92 | void offset (int subindex, uoffs extent) |
|
|
93 | { |
|
|
94 | if (subindex & 1) x += extent; |
|
|
95 | if (subindex & 2) y += extent; |
|
|
96 | if (subindex & 4) z += extent; |
|
|
97 | } |
|
|
98 | }; |
|
|
99 | |
|
|
100 | inline const sector translate (const sector &p, const sector &src, const sector &dst) |
|
|
101 | { |
|
|
102 | sector r; |
|
|
103 | |
|
|
104 | r.x = p.x + (dst.x - src.x); |
|
|
105 | r.y = p.y + (dst.y - src.y); |
|
|
106 | r.z = p.z + (dst.z - src.z); |
|
|
107 | |
|
|
108 | return r; |
|
|
109 | } |
|
|
110 | |
|
|
111 | void renormalize (sector &s, point &p); |
|
|
112 | |
|
|
113 | struct colour { |
|
|
114 | GLfloat r, g, b, a; |
|
|
115 | colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1., GLfloat a = 1.) : r(r), g(g), b(b), a(a) { }; |
|
|
116 | }; |
107 | |
117 | |
108 | struct texc { |
118 | struct texc { |
109 | GLfloat s, t; |
119 | GLfloat s, t; |
110 | texc () { }; |
120 | texc () { }; |
111 | texc (GLfloat s, GLfloat t) : s(s), t(t) { }; |
121 | texc (GLfloat s, GLfloat t) : s(s), t(t) { }; |