--- libgender/entity.h 2004/10/02 16:16:03 1.2 +++ libgender/entity.h 2004/10/08 16:52:49 1.20 @@ -2,166 +2,150 @@ #define ENTITY_H #include +#include #include +#include "util.h" #include "oct.h" +#include "view.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 geometry { + geometry *parent; + box bbox; -struct sector { - soffs x, y, z; -}; + virtual void update () + { + if (parent) + parent->update (); + } -struct point { - GLfloat x, y, z; + virtual void draw (view &ctx) = 0; + geometry (geometry *parent = 0) : parent(parent) { }; + virtual ~geometry (); }; -struct colour { - GLfloat r, g, b; +struct vertex1d { + colour c; // colour + point p; // vertex }; -struct vect { - GLfloat x, y, z; -}; +struct vertex2d { + point p; // vertex + vec3 n; // normal + texc t; // texture -struct texc { - GLfloat u, v; + vertex2d () { }; + vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; }; -struct box { - point a, b; +struct geometry_opengl : geometry { + GLuint list; // TODO: dynamic caching - void reset () - { - a.x = a.y = a.z = GLFLOAT_MAX; - b.x = b.y = b.z = GLFLOAT_MIN; - } + geometry_opengl (); + ~geometry_opengl (); +}; - void add (const box &o); +template +struct geometry_opengl1d : geometry_opengl, vector { + void set (const vector &v); + void draw (view &ctx); }; -struct entity_base { - struct entity_base *parent; - vector o; - box bbox; +template +struct geometry_opengl2d : geometry_opengl { + material m; - virtual void update_bbox (); - virtual void show (const sector &sec) { }; - void hide (); - virtual void draw () = 0; - virtual ~entity_base () - { - hide (); - }; + void set (const vector &v); + void draw (view &ctx); }; -struct entity_container : entity_base, protected vector { - void update_bbox (); - void show (const sector &sec); - void draw (); - ~entity_container (); +typedef geometry_opengl1d geometry_points; +typedef geometry_opengl1d geometry_lines; +typedef geometry_opengl1d geometry_line_strip; +typedef geometry_opengl1d geometry_line_loop; +typedef geometry_opengl2d geometry_triangles; +typedef geometry_opengl2d geometry_triangle_strip; +typedef geometry_opengl2d geometry_triangle_fan; +typedef geometry_opengl2d geometry_quads; +typedef geometry_opengl2d geometry_quad_strip; +typedef geometry_opengl2d geometry_polygon; + +struct geometry_nurbs : geometry, vector { + GLUnurbsObj *nurb; + GLfloat ctlpoints[4][4][3]; + + geometry_nurbs() : nurb(0) { } + virtual void draw (view &ctx); + void set (); }; -struct entity_filter : entity_base { +struct geometry_filter : geometry { protected: - entity_base *e; + geometry *g; public: - void set (entity_base *e) - { - this->e = e; - e->parent = this; - } - - void remove () - { - this->e->parent = 0; - this->e = 0; - } + void set (geometry *g); - entity_base *content () { return e; }; + geometry *content () { return g; }; - void update_bbox (); - void show (const sector &sec); - void draw (); - ~entity_filter (); + void update (); + void show (); + void draw (view &ctx); + geometry_filter (geometry *g = 0) { set (g); } + ~geometry_filter (); }; -struct entity : entity_filter { - sector sec; +struct geometry_transform : geometry_filter { +protected: + matrix m; +public: + void update (); - void show (const sector &sec); - void draw (); -}; + void show (); + void draw (view &ctx); + void set_matrix (const matrix &xfrm); + void update (const matrix &xfrm); -struct entity_affine : entity_filter { - //matrix m; + geometry_transform (geometry *g) : geometry_filter(g), m(1) { }; + geometry_transform () : geometry_filter(0), m(1) { }; }; -struct vertex1d { - point p; // vertex - colour c; // colour +struct geometry_anim : geometry_transform { + GLfloat vx, vy, vz; + void draw (view &ctx); }; -struct vertex2d { - point p; // vertex - colour c; // colour - vect n; // normal - texc t; // texture -}; +struct geometry_container : geometry, protected vector { + void update (); -template -struct entity_opengl1d : entity_base, vector { - void update_bbox (); - void show (const sector &sec); - void draw (); + void add (geometry *g); + void draw (view &ctx); + ~geometry_container (); }; -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_line_strip; -typedef entity_opengl1d entity_line_loop; -typedef entity_opengl2d entity_triangles; -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 light { +struct entity : geometry_filter { + sector orig; point p; - colour c; - GLfloat intensity; - GLfloat radius; -}; + sector a, b; // bounding box corners -struct draw_context { - enum { DEPTH, AMBIENT, LIGHTED } mode; - light *l; -}; + vector o; -struct view { - point p; - vect d; - float fov; + void update (); + void draw (view &ctx); - int width, height; + void move (const vec3 &v); + + virtual void show () { if (!o.size ()) world.add (this); }; + void hide (); + void display (view &ctx); - void draw (const draw_context &c); + entity (geometry *g = 0); + ~entity (); }; #endif