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