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