#ifndef UTIL_H #define UTIL_H #include #include using namespace std; typedef int soffs; // 32 bit typedef unsigned int uoffs; #define OFFS_BITS 31 #define SOFFS_MIN (soffs)-(1 << (OFFS_BITS - 1)) #define MAXEXTENT ((1UL << OFFS_BITS) - 1) #define GLFLOAT_MAX 1e30 #define GLFLOAT_MIN -1e30 struct sector { soffs x, y, z; void offset (int subindex, uoffs extent) { if (subindex & 1) x += extent; if (subindex & 2) y += extent; if (subindex & 4) z += extent; } }; struct point { GLfloat x, y, z; point () { }; point (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; }; struct colour { GLfloat r, g, b, a; colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1., GLfloat a = 1.) : r(r), g(g), b(b), a(a) { }; }; struct vec3 { GLfloat x, y, z; vec3 () { }; vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; const vec3 operator -() const { return vec3 (-x, -y, -z); } }; const vec3 normalize (const vec3 &v); const vec3 cross (const vec3 &a, const vec3 &b); GLfloat dot (const vec3 &a, const vec3 &b); struct texc { GLfloat s, t; texc () { }; texc (GLfloat s, GLfloat t) : s(s), t(t) { }; }; struct box { point a, b; void reset () { a = point (GLFLOAT_MAX, GLFLOAT_MAX, GLFLOAT_MAX); b = point (GLFLOAT_MIN, GLFLOAT_MIN, GLFLOAT_MIN); } void add (const box &o); void add (const point &p); }; struct light { point p; colour c; GLfloat intensity; GLfloat radius; }; struct material { colour diffuse, specular, emission; GLfloat shininess; }; struct entity_base; struct draw_context; #endif