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

Comparing libgender/entity.h (file contents):
Revision 1.9 by root, Sun Oct 3 05:53:09 2004 UTC vs.
Revision 1.17 by root, Tue Oct 5 03:39:47 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines