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

Comparing libgender/entity.C (file contents):
Revision 1.27 by root, Mon Oct 4 10:18:13 2004 UTC vs.
Revision 1.28 by root, Mon Oct 4 23:44:53 2004 UTC

1#include <algorithm> 1#include <algorithm>
2 2
3using namespace std; 3using namespace std;
4 4
5#include "util.h"
5#include "entity.h" 6#include "entity.h"
6#include "oct.h" 7#include "oct.h"
7#include "view.h" 8#include "view.h"
8 9
9entity_base::entity_base () 10entity_base::entity_base ()
14entity_base::~entity_base () 15entity_base::~entity_base ()
15{ 16{
16 hide (); 17 hide ();
17} 18}
18 19
19void entity_base::update_bbox () 20void entity_base::update ()
20{ 21{
21 if (parent) 22 if (parent)
22 parent->update_bbox (); 23 parent->update ();
23} 24}
24 25
25void entity_base::hide () 26void entity_base::hide ()
26{ 27{
27 for (vector<octant *>::iterator i = o.end (); i-- != o.begin (); ) 28 for (vector<octant *>::iterator i = o.end (); i-- != o.begin (); )
36 draw (ctx); 37 draw (ctx);
37} 38}
38 39
39///////////////////////////////////////////////////////////////////////////// 40/////////////////////////////////////////////////////////////////////////////
40 41
41void entity_filter::update_bbox () 42void entity_filter::update ()
42{ 43{
43 bbox = translate (e->bbox, e->orig, orig); 44 bbox = translate (e->bbox, e->orig, orig);
44 45
45 entity_base::update_bbox (); 46 entity_base::update ();
46} 47}
47 48
48void entity_filter::show () 49void entity_filter::show ()
49{ 50{
50 entity_base::show (); 51 entity_base::show ();
62 delete e; 63 delete e;
63} 64}
64 65
65///////////////////////////////////////////////////////////////////////////// 66/////////////////////////////////////////////////////////////////////////////
66 67
67void entity_container::update_bbox () 68void entity_container::update ()
68{ 69{
69 bbox.reset (); 70 bbox.reset ();
70 71
71 for (iterator i = end (); i-- != begin (); ) 72 for (iterator i = end (); i-- != begin (); )
72 bbox.add ((*i)->bbox); 73 bbox.add ((*i)->bbox);
73 74
74 entity_base::update_bbox (); 75 entity_base::update ();
75} 76}
76 77
77void entity_container::show () 78void entity_container::show ()
78{ 79{
79 entity_base::show (); 80 entity_base::show ();
120template class entity_opengl2d<GL_QUADS>; 121template class entity_opengl2d<GL_QUADS>;
121template class entity_opengl2d<GL_QUAD_STRIP>; 122template class entity_opengl2d<GL_QUAD_STRIP>;
122template class entity_opengl2d<GL_POLYGON>; 123template class entity_opengl2d<GL_POLYGON>;
123 124
124template<GLenum type> 125template<GLenum type>
125void entity_opengl1d<type>::update_bbox () 126void entity_opengl1d<type>::update ()
126{ 127{
127 bbox.reset (); 128 bbox.reset ();
128 129
129 for (vector<vertex1d>::iterator i = end (); i-- != begin (); ) 130 for (vector<vertex1d>::iterator i = end (); i-- != begin (); )
130 bbox.add (i->p); 131 bbox.add (i->p);
131 132
132 entity_base::update_bbox (); 133 entity_base::update ();
133} 134}
134 135
135template<GLenum type> 136template<GLenum type>
136void entity_opengl1d<type>::draw (draw_context &ctx) 137void entity_opengl1d<type>::draw (draw_context &ctx)
137{ 138{
152 bbox.reset (); 153 bbox.reset ();
153 154
154 for (vector<vertex2d>::const_iterator i = v.end (); i-- != v.begin (); ) 155 for (vector<vertex2d>::const_iterator i = v.end (); i-- != v.begin (); )
155 bbox.add (i->p); 156 bbox.add (i->p);
156 157
157 update_bbox (); 158 update ();
158 159
159 glNewList (list, GL_COMPILE); 160 glNewList (list, GL_COMPILE);
160 161
161 glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *)&m.diffuse); 162 glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *)&m.diffuse);
162 glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *)&m.specular); 163 glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *)&m.specular);
203entity_transform::entity_transform () 204entity_transform::entity_transform ()
204{ 205{
205 m.identity (); 206 m.identity ();
206} 207}
207 208
208void entity_transform::update_bbox () 209void entity_transform::update ()
209{ 210{
210 box sub = translate (e->bbox, e->orig, orig); 211 box sub = translate (e->bbox, e->orig, orig);
211 212
212 bbox.reset (); 213 bbox.reset ();
213 bbox.add (m * vec3 (sub.a.x, sub.a.y, sub.a.z)); 214 bbox.add (m * vec3 (sub.a.x, sub.a.y, sub.a.z));
217 bbox.add (m * vec3 (sub.a.x, sub.a.y, sub.b.z)); 218 bbox.add (m * vec3 (sub.a.x, sub.a.y, sub.b.z));
218 bbox.add (m * vec3 (sub.b.x, sub.a.y, sub.b.z)); 219 bbox.add (m * vec3 (sub.b.x, sub.a.y, sub.b.z));
219 bbox.add (m * vec3 (sub.a.x, sub.b.y, sub.b.z)); 220 bbox.add (m * vec3 (sub.a.x, sub.b.y, sub.b.z));
220 bbox.add (m * vec3 (sub.b.x, sub.b.y, sub.b.z)); 221 bbox.add (m * vec3 (sub.b.x, sub.b.y, sub.b.z));
221 222
222 entity_base::update_bbox (); 223 entity_base::update ();
224}
225
226void entity_transform::renormalize ()
227{
228#if 0
229 point trans(m(0,0), m(1,0), m(2,0));
230 ::renormalize (orig, trans);
231 m(0,0) = trans.x; m(1,0) = trans.y; m(2,0) = trans.z;
232#endif
233}
234
235void entity_transform::update (const gl_matrix &xfrm)
236{
237 m = m * xfrm;
238
239 renormalize ();
240 update ();
241}
242
243void entity_transform::set_matrix (const gl_matrix &xfrm)
244{
245 m = xfrm;
246
247 renormalize ();
248 update ();
223} 249}
224 250
225void entity_transform::show () 251void entity_transform::show ()
226{ 252{
227 entity_base::show (); 253 entity_base::show ();
229 255
230void entity_transform::draw (draw_context &ctx) 256void entity_transform::draw (draw_context &ctx)
231{ 257{
232 glPushMatrix (); 258 glPushMatrix ();
233 glMultMatrixf ((GLfloat *)&m); 259 glMultMatrixf ((GLfloat *)&m);
260#if 0
261 const sector &corig = ctx.v.orig;
262 glTranslatef (orig.x - corig.x, orig.y - corig.y, orig.z - corig.z);
263#endif
234 e->draw (ctx); 264 e->draw (ctx);
235 glPopMatrix (); 265 glPopMatrix ();
236} 266}
237 267
238void entity_anim::draw (draw_context &ctx) 268void entity_anim::draw (draw_context &ctx)
239{ 269{
240 gl_matrix save_m = m; 270 gl_matrix save_m = m;
241 271
242 m.rotate (vx * timer.now, vec3 (1, 0, 0)); 272 update (gl_matrix::rotation (vx * timer.now, vec3 (1, 0, 0))
243 m.rotate (vy * timer.now, vec3 (0, 1, 0)); 273 * gl_matrix::rotation (vy * timer.now, vec3 (0, 1, 0))
244 m.rotate (vz * timer.now, vec3 (0, 0, 1)); 274 * gl_matrix::rotation (vz * timer.now, vec3 (0, 0, 1)));
275
245 entity_transform::draw (ctx); 276 entity_transform::draw (ctx);
246 277
247 m = save_m; 278 m = save_m;
248} 279}
249 280

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines