#include using namespace std; #include "entity.h" #include "oct.h" #include "view.h" void entity_base::update_bbox () { if (parent) parent->update_bbox (); } void entity_base::hide () { for (vector::iterator i = o.end (); i-- != o.begin (); ) (*i)->remove (this); o.clear (); } void entity_filter::update_bbox () { bbox = e->bbox; entity_base::update_bbox (); } void entity_filter::show (const sector &sec) { world.add (sec, this); e->show (sec); } void entity_filter::draw (draw_context &ctx) { e->try_draw (ctx); } entity_filter::~entity_filter () { delete e; } void entity::show (const sector &sec) { show (); } void entity::show () { e->show (this->sec); } void entity::draw (draw_context &ctx) { glPushMatrix (); glTranslated (-sec.x, -sec.y, -sec.z); e->try_draw (ctx); glPopMatrix (); } void entity_container::update_bbox () { bbox.reset (); for (iterator i = end (); i-- != begin (); ) { (*i)->update_bbox (); bbox.add ((*i)->bbox); } } void entity_container::show (const sector &sec) { world.add (sec, this); for (iterator i = end (); i-- != begin (); ) (*i)->show (sec); } void entity_container::draw (draw_context &ctx) { for (iterator i = end (); i-- != begin (); ) (*i)->try_draw (ctx); } entity_container::~entity_container () { hide (); for (iterator i = end (); i-- != begin (); ) delete *i; clear (); } template class entity_opengl1d; template class entity_opengl1d; template class entity_opengl1d; template class entity_opengl1d; template class entity_opengl2d; template class entity_opengl2d; template class entity_opengl2d; template class entity_opengl2d; template class entity_opengl2d; template class entity_opengl2d; template void entity_opengl1d::update_bbox () { bbox.reset (); for (vector::iterator i = end (); i-- != begin (); ) bbox.add (i->p); entity_base::update_bbox (); } template void entity_opengl2d::update_bbox () { for (vector::iterator i = end (); i-- != begin (); ) bbox.add (i->p); entity_base::update_bbox (); } template void entity_opengl1d::draw (draw_context &ctx) { glBegin (type); for (iterator i = begin (); i < end (); ++i) { if (ctx.mode == draw_context::LIGHTED) glColor3fv ((GLfloat *)&i->c); glVertex3fv ((GLfloat *)&i->p); } glEnd (); } template void entity_opengl2d::draw (draw_context &ctx) { if (!list) { if (0) list = glGenLists (1); if (0) glNewList (list, GL_COMPILE); glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *)&m.diffuse); glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *)&m.specular); glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *)&m.emission); glMaterialf (GL_FRONT, GL_SHININESS, m.shininess); glBegin (type); for (iterator i = begin (); i < end (); ++i) { glTexCoord2fv ((GLfloat *)&i->t); glNormal3fv ((GLfloat *)&i->n); glVertex3fv ((GLfloat *)&i->p); } glEnd (); if (0) glEndList (); } if (0) glCallList (list); } template void entity_opengl1d::show (const sector &sec) { world.add (sec, this); } template void entity_opengl2d::show (const sector &sec) { world.add (sec, this); }