ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.h
(Generate patch)

Comparing libgender/entity.h (file contents):
Revision 1.18 by root, Wed Oct 6 00:55:37 2004 UTC vs.
Revision 1.19 by root, Thu Oct 7 23:39:43 2004 UTC

9#include "oct.h" 9#include "oct.h"
10#include "view.h" 10#include "view.h"
11 11
12using namespace std; 12using namespace std;
13 13
14struct entity_base { 14struct geometry {
15 struct entity_base *parent; 15 geometry *parent;
16 sector orig;
17 vector<octant *> o;
18 box bbox; 16 box bbox;
19 17
20 virtual void update (); 18 virtual void update ()
21 virtual void show () { world.add (this); };
22 void hide ();
23 void display (view &ctx);
24 virtual void draw (view &ctx) = 0;
25
26 entity_base ();
27 virtual ~entity_base ();
28};
29
30struct entity_container : entity_base, protected vector<entity_base *> {
31 void add (entity_base *e)
32 { 19 {
33 push_back (e); 20 if (parent)
34 e->parent = this; 21 parent->update ();
35 update ();
36 } 22 }
37 23
38 void update ();
39 void show ();
40 void draw (view &ctx); 24 virtual void draw (view &ctx) = 0;
41 ~entity_container (); 25 geometry (geometry *parent = 0) : parent(parent) { };
42}; 26 virtual ~geometry ();
43
44struct entity_filter : entity_base {
45protected:
46 entity_base *e;
47public:
48
49 void set (entity_base *e)
50 {
51 this->e = e;
52 e->parent = this;
53 update ();
54 }
55
56 void remove ()
57 {
58 this->e->parent = 0;
59 this->e = 0;
60 }
61
62 entity_base *content () { return e; };
63
64 void update ();
65 void show ();
66 void draw (view &ctx);
67 ~entity_filter ();
68};
69
70struct entity : entity_filter {
71}; 27};
72 28
73struct vertex1d { 29struct vertex1d {
74 colour c; // colour 30 colour c; // colour
75 point p; // vertex 31 point p; // vertex
82 38
83 vertex2d () { }; 39 vertex2d () { };
84 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; 40 vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { };
85}; 41};
86 42
87struct entity_opengl : entity_base { 43struct geometry_opengl : geometry {
88 GLuint list; 44 GLuint list; // TODO: dynamic caching
89 45
90 entity_opengl (); 46 geometry_opengl ();
91 ~entity_opengl (); 47 ~geometry_opengl ();
92}; 48};
93 49
94template<GLenum type> 50template<GLenum type>
95struct entity_opengl1d : entity_opengl, vector<vertex1d> { 51struct geometry_opengl1d : geometry_opengl, vector<vertex1d> {
96 void update (); 52 void set (const vector<vertex1d> &v);
97 void draw (view &ctx); 53 void draw (view &ctx);
98}; 54};
99 55
100template<GLenum type> 56template<GLenum type>
101struct entity_opengl2d : entity_opengl { 57struct geometry_opengl2d : geometry_opengl {
102 material m; 58 material m;
103 59
104 void set (const vector<vertex2d> &v); 60 void set (const vector<vertex2d> &v);
105 void draw (view &ctx); 61 void draw (view &ctx);
106}; 62};
107 63
108typedef entity_opengl1d<GL_POINTS> entity_points; 64typedef geometry_opengl1d<GL_POINTS> geometry_points;
109typedef entity_opengl1d<GL_LINES> entity_lines; 65typedef geometry_opengl1d<GL_LINES> geometry_lines;
110typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; 66typedef geometry_opengl1d<GL_LINE_STRIP> geometry_line_strip;
111typedef entity_opengl1d<GL_LINE_LOOP> entity_line_loop; 67typedef geometry_opengl1d<GL_LINE_LOOP> geometry_line_loop;
112typedef entity_opengl2d<GL_TRIANGLES> entity_triangles; 68typedef geometry_opengl2d<GL_TRIANGLES> geometry_triangles;
113typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_triangle_strip; 69typedef geometry_opengl2d<GL_TRIANGLE_STRIP> geometry_triangle_strip;
114typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; 70typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan;
115typedef entity_opengl2d<GL_QUADS> entity_quads; 71typedef geometry_opengl2d<GL_QUADS> geometry_quads;
116typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; 72typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip;
117typedef entity_opengl2d<GL_POLYGON> entity_polygon; 73typedef geometry_opengl2d<GL_POLYGON> geometry_polygon;
118 74
119struct entity_transform : entity_filter { 75struct geometry_filter : geometry {
120protected: 76protected:
121 matrix m; 77 geometry *g;
122 void renormalize ();
123public: 78public:
124 79
125 entity_transform (); 80 void set (geometry *g);
81
82 geometry *content () { return g; };
126 83
127 void update (); 84 void update ();
128 void show (); 85 void show ();
129 void draw (view &ctx); 86 void draw (view &ctx);
87 geometry_filter (geometry *g = 0) { set (g); }
88 ~geometry_filter ();
89};
90
91struct geometry_transform : geometry_filter {
92protected:
93 matrix m;
94public:
95 void update ();
96
97 void show ();
98 void draw (view &ctx);
130 void set_matrix (const matrix &xfrm); 99 void set_matrix (const matrix &xfrm);
131 void update (const matrix &xfrm); 100 void update (const matrix &xfrm);
101
102 geometry_transform (geometry *g) : geometry_filter(g), m(1) { };
103 geometry_transform () : geometry_filter(0), m(1) { };
132}; 104};
133 105
134struct entity_anim : entity_transform { 106struct geometry_anim : geometry_transform {
135 GLfloat vx, vy, vz; 107 GLfloat vx, vy, vz;
136 void draw (view &ctx); 108 void draw (view &ctx);
109};
110
111struct geometry_container : geometry, protected vector<geometry *> {
112 void update ();
113
114 void add (geometry *g);
115 void draw (view &ctx);
116 ~geometry_container ();
117};
118
119/////////////////////////////////////////////////////////////////////////////
120
121struct entity : geometry_filter {
122 sector orig;
123 point p;
124 sector a, b; // bounding box corners
125
126 vector<octant *> o;
127
128 void update ();
129 void draw (view &ctx);
130
131 void move (const vec3 &v);
132
133 virtual void show () { if (!o.size ()) world.add (this); };
134 void hide ();
135 void display (view &ctx);
136
137 entity (geometry *g = 0);
138 ~entity ();
137}; 139};
138 140
139#endif 141#endif
140 142
141 143

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines