--- libgender/entity.h 2004/10/03 02:37:55 1.4 +++ libgender/entity.h 2004/10/03 03:17:09 1.6 @@ -5,62 +5,11 @@ #include +#include "util.h" #include "oct.h" using namespace std; -typedef unsigned int soffs; // 32 bit -const soffs soffs_max = 1UL << 31; - -#define GLFLOAT_MAX 1e30 -#define GLFLOAT_MIN -1e30 - -struct sector { - soffs x, y, z; -}; - -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; - colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1.) : r(r), g(g), b(b) { }; -}; - -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 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); -}; - struct entity_base { struct entity_base *parent; vector o; @@ -69,7 +18,7 @@ virtual void update_bbox (); virtual void show (const sector &sec) { }; void hide (); - virtual void draw () = 0; + virtual void draw (const draw_context &ctx) = 0; virtual ~entity_base () { hide (); @@ -80,7 +29,7 @@ void add (entity_base *e) { push_back (e); e->parent = this; } void update_bbox (); void show (const sector &sec); - void draw (); + void draw (const draw_context &ctx); ~entity_container (); }; @@ -105,7 +54,7 @@ void update_bbox (); void show (const sector &sec); - void draw (); + void draw (const draw_context &ctx); ~entity_filter (); }; @@ -114,7 +63,7 @@ void show (const sector &sec); void show (); - void draw (); + void draw (const draw_context &ctx); }; struct entity_affine : entity_filter { @@ -127,27 +76,31 @@ }; struct vertex2d { - colour c; // colour - point p; // vertex - vec3 n; // normal - texc t; // texture + point p; // vertex + vec3 n; // normal + texc t; // texture vertex2d () { }; - vertex2d (colour c, point p, vec3 n, texc t = texc()) : c(c), p(p), n(n), t(t) { }; + vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; +}; + +struct entity_opengl : entity_base { }; template -struct entity_opengl1d : entity_base, vector { +struct entity_opengl1d : entity_opengl, vector { void update_bbox (); void show (const sector &sec); - void draw (); + void draw (const draw_context &ctx); }; template -struct entity_opengl2d : entity_base, vector { +struct entity_opengl2d : entity_opengl, vector { + material m; + void update_bbox (); void show (const sector &sec); - void draw (); + void draw (const draw_context &ctx); }; typedef entity_opengl1d entity_points; @@ -161,25 +114,13 @@ typedef entity_opengl2d entity_quad_strip; typedef entity_opengl2d entity_polygon; -struct light { - point p; - colour c; - GLfloat intensity; - GLfloat radius; -}; - -struct draw_context { - enum { DEPTH, AMBIENT, LIGHTED } mode; - light *l; -}; - struct view { point p; vec3 d, u; float fov; int w, h; - void draw (const draw_context &c); + void draw (const draw_context &ctx); }; #endif