--- libgender/entity.h 2004/10/02 15:54:43 1.1 +++ libgender/entity.h 2004/10/17 09:43:07 1.25 @@ -1,146 +1,171 @@ #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; -typedef unsigned int soffs; // 32 bit -const soffs soffs_max = 1UL << 31; +struct geometry +{ + geometry *parent; + box bbox; -#define GLFLOAT_MAX 1e30 -#define GLFLOAT_MIN -1e30 + virtual void update () + { + if (parent) + parent->update (); + } -struct sector { - soffs x, y, z; + virtual void draw (view &ctx) = 0; + geometry (geometry *parent = 0) : parent(parent) { }; + virtual ~geometry (); }; -struct point { - GLfloat x, y, z; -}; +struct geometry_opengl : geometry +{ + GLuint list; // TODO: dynamic caching -struct colour { - GLfloat r, g, b; + geometry_opengl (); + ~geometry_opengl (); }; -struct vect { - GLfloat x, y, z; +template +struct geometry_opengl1d : geometry_opengl, vector +{ + void set (const vector &v); + void draw (view &ctx); }; -struct texc { - GLfloat u, v; +template +struct geometry_opengl2d : geometry_opengl +{ + material *m; + + geometry_opengl2d () : m(0) { }; + + void set (const vector &v); + void draw (view &ctx); }; -struct box { - point a, b; +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; - void reset () - { - a.x = a.y = a.z = GLFLOAT_MAX; - b.x = b.y = b.z = GLFLOAT_MIN; - } +struct geometry_nurbs : geometry, vector +{ + GLUnurbsObj *nurb; + GLUtesselator *tess; + GLfloat ctlpoints[4][4][3]; - void add (const box &o); + geometry_nurbs() : tess(0), nurb(0) { } + virtual void draw (view &ctx); + void set (); }; -struct entity_base { - struct entity_base *parent; - vector o; - box bbox; +struct geometry_sphere : geometry +{ + GLfloat radius; - virtual void update_bbox (); - virtual void show (const sector &sec) { }; - void hide (); - virtual void draw () = 0; - virtual ~entity_base () - { - hide (); - }; + void update (); + void draw (view &ctx); + geometry_sphere (GLfloat radius) : radius(radius) { update (); }; }; -struct entity_container : entity_base, protected vector { - void update_bbox (); - void show (const sector &sec); - void draw (); - ~entity_container (); -}; +///////////////////////////////////////////////////////////////////////////// -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 set (geometry *g); - void remove () - { - this->e->parent = 0; - this->e = 0; - } - - 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 v; // vertex - colour c; // colour +struct geometry_anim : geometry_transform +{ + GLfloat vx, vy, vz; + void draw (view &ctx); }; -struct vertex2d { - point v; // vertex - colour c; // colour - vect n; // normal - texc t; // texture +struct geometry_container : geometry, protected vector +{ + void update (); + + void add (geometry *g); + void draw (view &ctx); + ~geometry_container (); }; -template -struct entity_opengl1d : entity_base, vector { - void update_bbox (); - void show (const sector &sec); - void draw (); +///////////////////////////////////////////////////////////////////////////// + +struct entity : geometry_filter +{ + sector orig; + point p; + sector a, b; // bounding box corners + gl::vertex_buffer_object vb_bbox; + + vector o; + + void update (); + void draw (view &ctx); + + void move (const vec3 &v); + + virtual void show (); + virtual void hide (); + + entity (geometry *g = 0); + ~entity (); }; -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; +struct light : entity +{ + point p; + colour c; + GLfloat intensity; + GLfloat radius; +}; #endif