--- libgender/entity.h 2004/10/05 03:39:47 1.17 +++ libgender/entity.h 2004/10/16 23:23:21 1.24 @@ -1,139 +1,170 @@ #ifndef ENTITY_H #define ENTITY_H -#include - #include +#include "opengl.h" + #include "util.h" #include "oct.h" #include "view.h" +#include "material.h" using namespace std; +using namespace gl; -struct entity_base { - struct entity_base *parent; - sector orig; - vector o; +struct geometry +{ + geometry *parent; box bbox; - virtual void update (); - virtual void show () { world.add (this); }; - void hide (); - void display (draw_context &ctx); - virtual void draw (draw_context &ctx) = 0; + virtual void update () + { + if (parent) + parent->update (); + } - entity_base (); - virtual ~entity_base (); + virtual void draw (view &ctx) = 0; + geometry (geometry *parent = 0) : parent(parent) { }; + virtual ~geometry (); }; -struct entity_container : entity_base, protected vector { - void add (entity_base *e) - { - push_back (e); - e->parent = this; - update (); - } +struct geometry_opengl : geometry +{ + GLuint list; // TODO: dynamic caching + + geometry_opengl (); + ~geometry_opengl (); +}; + +template +struct geometry_opengl1d : geometry_opengl, vector +{ + void set (const vector &v); + void draw (view &ctx); +}; + +template +struct geometry_opengl2d : geometry_opengl +{ + material *m; + + geometry_opengl2d () : m(0) { }; + + void set (const vector &v); + void draw (view &ctx); +}; + +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; + GLUtesselator *tess; + GLfloat ctlpoints[4][4][3]; + + geometry_nurbs() : tess(0), nurb(0) { } + virtual void draw (view &ctx); + void set (); +}; + +struct geometry_sphere : geometry +{ + GLfloat radius; void update (); - void show (); - void draw (draw_context &ctx); - ~entity_container (); + void draw (view &ctx); + geometry_sphere (GLfloat radius) : radius(radius) { update (); }; }; -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; - update (); - } - - void remove () - { - this->e->parent = 0; - this->e = 0; - } + void set (geometry *g); - entity_base *content () { return e; }; + geometry *content () { return g; }; void update (); void show (); - void draw (draw_context &ctx); - ~entity_filter (); + void draw (view &ctx); + geometry_filter (geometry *g = 0) { set (g); } + ~geometry_filter (); }; -struct entity : entity_filter { -}; - -struct vertex1d { - colour c; // colour - point p; // vertex -}; +struct geometry_transform : geometry_filter +{ +protected: + matrix m; +public: + void update (); -struct vertex2d { - point p; // vertex - vec3 n; // normal - texc t; // texture + void show (); + void draw (view &ctx); + void set_matrix (const matrix &xfrm); + void update (const matrix &xfrm); - vertex2d () { }; - vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; + geometry_transform (geometry *g) : geometry_filter(g), m(1) { }; + geometry_transform () : geometry_filter(0), m(1) { }; }; -struct entity_opengl : entity_base { - GLuint list; - - entity_opengl (); - ~entity_opengl (); +struct geometry_anim : geometry_transform +{ + GLfloat vx, vy, vz; + void draw (view &ctx); }; -template -struct entity_opengl1d : entity_opengl, vector { +struct geometry_container : geometry, protected vector +{ void update (); - void draw (draw_context &ctx); -}; - -template -struct entity_opengl2d : entity_opengl { - material m; - void set (const vector &v); - void draw (draw_context &ctx); + void add (geometry *g); + void draw (view &ctx); + ~geometry_container (); }; -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 entity_transform : entity_filter { -protected: - matrix m; - void renormalize (); -public: +struct entity : geometry_filter +{ + sector orig; + point p; + sector a, b; // bounding box corners - entity_transform (); + vector o; void update (); - void show (); - void draw (draw_context &ctx); - void set_matrix (const matrix &xfrm); - void update (const matrix &xfrm); + void draw (view &ctx); + + void move (const vec3 &v); + + virtual void show (); + virtual void hide (); + void display (view &ctx); + + entity (geometry *g = 0); + ~entity (); }; -struct entity_anim : entity_transform { - GLfloat vx, vy, vz; - void draw (draw_context &ctx); +struct light : entity +{ + point p; + colour c; + GLfloat intensity; + GLfloat radius; }; #endif