1 |
#ifndef UTIL_H |
2 |
#define UTIL_H |
3 |
|
4 |
#include <GL/gl.h> |
5 |
|
6 |
#include <vector> |
7 |
|
8 |
using namespace std; |
9 |
|
10 |
typedef int soffs; // 32 bit |
11 |
typedef unsigned int uoffs; |
12 |
#define OFFS_BITS 31 |
13 |
#define SOFFS_MIN (soffs)-(1 << (OFFS_BITS - 1)) |
14 |
#define MAXEXTENT ((1UL << OFFS_BITS) - 1) |
15 |
|
16 |
#define GLFLOAT_MAX 1e30 |
17 |
#define GLFLOAT_MIN -1e30 |
18 |
|
19 |
struct sector { |
20 |
soffs x, y, z; |
21 |
|
22 |
void offset (int subindex, uoffs extent) |
23 |
{ |
24 |
if (subindex & 1) x += extent; |
25 |
if (subindex & 2) y += extent; |
26 |
if (subindex & 4) z += extent; |
27 |
} |
28 |
}; |
29 |
|
30 |
struct point { |
31 |
GLfloat x, y, z; |
32 |
|
33 |
point () { }; |
34 |
point (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; |
35 |
}; |
36 |
|
37 |
struct colour { |
38 |
GLfloat r, g, b, a; |
39 |
colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1., GLfloat a = 1.) : r(r), g(g), b(b), a(a) { }; |
40 |
}; |
41 |
|
42 |
struct vec3 { |
43 |
GLfloat x, y, z; |
44 |
vec3 () { }; |
45 |
vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; |
46 |
|
47 |
const vec3 operator -() const |
48 |
{ return vec3 (-x, -y, -z); } |
49 |
}; |
50 |
|
51 |
const vec3 normalize (const vec3 &v); |
52 |
const vec3 cross (const vec3 &a, const vec3 &b); |
53 |
GLfloat dot (const vec3 &a, const vec3 &b); |
54 |
|
55 |
struct texc { |
56 |
GLfloat s, t; |
57 |
texc () { }; |
58 |
texc (GLfloat s, GLfloat t) : s(s), t(t) { }; |
59 |
}; |
60 |
|
61 |
struct box { |
62 |
point a, b; |
63 |
|
64 |
void reset () |
65 |
{ |
66 |
a = point (GLFLOAT_MAX, GLFLOAT_MAX, GLFLOAT_MAX); |
67 |
b = point (GLFLOAT_MIN, GLFLOAT_MIN, GLFLOAT_MIN); |
68 |
} |
69 |
|
70 |
void add (const box &o); |
71 |
void add (const point &p); |
72 |
}; |
73 |
|
74 |
struct light { |
75 |
point p; |
76 |
colour c; |
77 |
GLfloat intensity; |
78 |
GLfloat radius; |
79 |
}; |
80 |
|
81 |
struct material { |
82 |
colour diffuse, specular, emission; |
83 |
GLfloat shininess; |
84 |
}; |
85 |
|
86 |
struct entity_base; |
87 |
struct draw_context; |
88 |
|
89 |
#endif |
90 |
|