--- libgender/entity.h 2004/10/02 15:54:43 1.1 +++ libgender/entity.h 2004/10/03 02:38:33 1.5 @@ -5,48 +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; -}; - -struct colour { - GLfloat r, g, b; -}; - -struct vect { - GLfloat x, y, z; -}; - -struct texc { - GLfloat u, v; -}; - -struct box { - point a, b; - - void reset () - { - a.x = a.y = a.z = GLFLOAT_MAX; - b.x = b.y = b.z = GLFLOAT_MIN; - } - - void add (const box &o); -}; - struct entity_base { struct entity_base *parent; vector o; @@ -55,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 (); @@ -63,9 +26,10 @@ }; struct entity_container : entity_base, protected vector { + 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 (); }; @@ -90,7 +54,7 @@ void update_bbox (); void show (const sector &sec); - void draw (); + void draw (const draw_context &ctx); ~entity_filter (); }; @@ -98,7 +62,8 @@ sector sec; void show (const sector &sec); - void draw (); + void show (); + void draw (const draw_context &ctx); }; struct entity_affine : entity_filter { @@ -106,42 +71,54 @@ }; struct vertex1d { - point v; // vertex colour c; // colour + point p; // vertex }; struct vertex2d { - point v; // vertex colour c; // colour - vect n; // normal + 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) { }; }; template struct entity_opengl1d : entity_base, vector { void update_bbox (); void show (const sector &sec); - void draw (); + void draw (const draw_context &ctx); }; template struct entity_opengl2d : entity_base, vector { void update_bbox (); void show (const sector &sec); - void draw (); + void draw (const draw_context &ctx); }; typedef entity_opengl1d entity_points; typedef entity_opengl1d entity_lines; -typedef entity_opengl1d entity_linestrip; -typedef entity_opengl1d entity_lineloop; +typedef entity_opengl1d entity_line_strip; +typedef entity_opengl1d entity_line_loop; typedef entity_opengl2d entity_triangles; -typedef entity_opengl2d entity_trianglestrip; -typedef entity_opengl2d entity_trianglefan; +typedef entity_opengl2d entity_triangle_strip; +typedef entity_opengl2d entity_triangle_fan; typedef entity_opengl2d entity_quads; typedef entity_opengl2d entity_quad_strip; typedef entity_opengl2d entity_polygon; +struct view { + point p; + vec3 d, u; + float fov; + int w, h; + + void draw (const draw_context &ctx); +}; + #endif