#ifndef ENTITY_H #define ENTITY_H #include #include #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; box bbox; virtual void update_bbox (); virtual void show (const sector &sec) { }; void hide (); virtual void draw () = 0; virtual ~entity_base () { hide (); }; }; struct entity_container : entity_base, protected vector { void update_bbox (); void show (const sector &sec); void draw (); ~entity_container (); }; struct entity_filter : entity_base { protected: entity_base *e; public: void set (entity_base *e) { this->e = e; e->parent = this; } void remove () { this->e->parent = 0; this->e = 0; } entity_base *content () { return e; }; void update_bbox (); void show (const sector &sec); void draw (); ~entity_filter (); }; struct entity : entity_filter { sector sec; void show (const sector &sec); void draw (); }; struct entity_affine : entity_filter { //matrix m; }; struct vertex1d { point v; // vertex colour c; // colour }; struct vertex2d { point v; // vertex colour c; // colour vect n; // normal texc t; // texture }; template struct entity_opengl1d : entity_base, vector { void update_bbox (); void show (const sector &sec); void draw (); }; template struct entity_opengl2d : entity_base, vector { void update_bbox (); void show (const sector &sec); void draw (); }; typedef entity_opengl1d entity_points; typedef entity_opengl1d entity_lines; typedef entity_opengl1d entity_linestrip; typedef entity_opengl1d entity_lineloop; typedef entity_opengl2d entity_triangles; typedef entity_opengl2d entity_trianglestrip; typedef entity_opengl2d entity_trianglefan; typedef entity_opengl2d entity_quads; typedef entity_opengl2d entity_quad_strip; typedef entity_opengl2d entity_polygon; #endif