| 1 |
root |
1.1 |
#include <algorithm> |
| 2 |
|
|
|
| 3 |
|
|
using namespace std; |
| 4 |
|
|
|
| 5 |
|
|
#include "entity.h" |
| 6 |
root |
1.4 |
#include "oct.h" |
| 7 |
root |
1.13 |
#include "view.h" |
| 8 |
root |
1.1 |
|
| 9 |
|
|
void entity_base::update_bbox () |
| 10 |
|
|
{ |
| 11 |
|
|
if (parent) |
| 12 |
|
|
parent->update_bbox (); |
| 13 |
|
|
} |
| 14 |
|
|
|
| 15 |
|
|
void entity_base::hide () |
| 16 |
|
|
{ |
| 17 |
|
|
for (vector<octant *>::iterator i = o.end (); i-- != o.begin (); ) |
| 18 |
|
|
(*i)->remove (this); |
| 19 |
|
|
|
| 20 |
|
|
o.clear (); |
| 21 |
|
|
} |
| 22 |
|
|
|
| 23 |
|
|
void entity_filter::update_bbox () |
| 24 |
|
|
{ |
| 25 |
|
|
bbox = e->bbox; |
| 26 |
|
|
entity_base::update_bbox (); |
| 27 |
|
|
} |
| 28 |
|
|
|
| 29 |
|
|
void entity_filter::show (const sector &sec) |
| 30 |
|
|
{ |
| 31 |
root |
1.8 |
world.add (sec, this); |
| 32 |
|
|
|
| 33 |
root |
1.1 |
e->show (sec); |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
root |
1.13 |
void entity_filter::draw (draw_context &ctx) |
| 37 |
root |
1.1 |
{ |
| 38 |
root |
1.13 |
e->try_draw (ctx); |
| 39 |
root |
1.1 |
} |
| 40 |
|
|
|
| 41 |
|
|
entity_filter::~entity_filter () |
| 42 |
|
|
{ |
| 43 |
|
|
delete e; |
| 44 |
|
|
} |
| 45 |
|
|
|
| 46 |
|
|
void entity::show (const sector &sec) |
| 47 |
|
|
{ |
| 48 |
root |
1.2 |
show (); |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
|
|
void entity::show () |
| 52 |
|
|
{ |
| 53 |
root |
1.1 |
e->show (this->sec); |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
root |
1.13 |
void entity::draw (draw_context &ctx) |
| 57 |
root |
1.1 |
{ |
| 58 |
root |
1.2 |
glPushMatrix (); |
| 59 |
root |
1.4 |
glTranslated (-sec.x, -sec.y, -sec.z); |
| 60 |
root |
1.13 |
e->try_draw (ctx); |
| 61 |
root |
1.2 |
glPopMatrix (); |
| 62 |
root |
1.1 |
} |
| 63 |
|
|
|
| 64 |
|
|
void entity_container::update_bbox () |
| 65 |
|
|
{ |
| 66 |
|
|
bbox.reset (); |
| 67 |
|
|
|
| 68 |
|
|
for (iterator i = end (); i-- != begin (); ) |
| 69 |
|
|
{ |
| 70 |
|
|
(*i)->update_bbox (); |
| 71 |
|
|
bbox.add ((*i)->bbox); |
| 72 |
|
|
} |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
void entity_container::show (const sector &sec) |
| 76 |
|
|
{ |
| 77 |
root |
1.8 |
world.add (sec, this); |
| 78 |
|
|
|
| 79 |
root |
1.1 |
for (iterator i = end (); i-- != begin (); ) |
| 80 |
|
|
(*i)->show (sec); |
| 81 |
|
|
} |
| 82 |
|
|
|
| 83 |
root |
1.13 |
void entity_container::draw (draw_context &ctx) |
| 84 |
root |
1.1 |
{ |
| 85 |
|
|
for (iterator i = end (); i-- != begin (); ) |
| 86 |
root |
1.13 |
(*i)->try_draw (ctx); |
| 87 |
root |
1.1 |
} |
| 88 |
|
|
|
| 89 |
|
|
entity_container::~entity_container () |
| 90 |
|
|
{ |
| 91 |
|
|
hide (); |
| 92 |
|
|
|
| 93 |
|
|
for (iterator i = end (); i-- != begin (); ) |
| 94 |
|
|
delete *i; |
| 95 |
|
|
|
| 96 |
|
|
clear (); |
| 97 |
root |
1.2 |
} |
| 98 |
|
|
|
| 99 |
root |
1.12 |
template class entity_opengl1d<GL_POINTS>; |
| 100 |
|
|
template class entity_opengl1d<GL_LINES>; |
| 101 |
|
|
template class entity_opengl1d<GL_LINE_STRIP>; |
| 102 |
|
|
template class entity_opengl1d<GL_LINE_LOOP>; |
| 103 |
|
|
template class entity_opengl2d<GL_TRIANGLES>; |
| 104 |
|
|
template class entity_opengl2d<GL_TRIANGLE_STRIP>; |
| 105 |
|
|
template class entity_opengl2d<GL_TRIANGLE_FAN>; |
| 106 |
|
|
template class entity_opengl2d<GL_QUADS>; |
| 107 |
|
|
template class entity_opengl2d<GL_QUAD_STRIP>; |
| 108 |
|
|
template class entity_opengl2d<GL_POLYGON>; |
| 109 |
root |
1.2 |
|
| 110 |
|
|
template<GLenum type> |
| 111 |
|
|
void entity_opengl1d<type>::update_bbox () |
| 112 |
|
|
{ |
| 113 |
root |
1.6 |
bbox.reset (); |
| 114 |
|
|
|
| 115 |
|
|
for (vector<vertex1d>::iterator i = end (); i-- != begin (); ) |
| 116 |
|
|
bbox.add (i->p); |
| 117 |
|
|
|
| 118 |
root |
1.2 |
entity_base::update_bbox (); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
template<GLenum type> |
| 122 |
|
|
void entity_opengl2d<type>::update_bbox () |
| 123 |
|
|
{ |
| 124 |
root |
1.7 |
for (vector<vertex2d>::iterator i = end (); i-- != begin (); ) |
| 125 |
root |
1.6 |
bbox.add (i->p); |
| 126 |
|
|
|
| 127 |
root |
1.2 |
entity_base::update_bbox (); |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
template<GLenum type> |
| 131 |
root |
1.13 |
void entity_opengl1d<type>::draw (draw_context &ctx) |
| 132 |
root |
1.2 |
{ |
| 133 |
|
|
glBegin (type); |
| 134 |
|
|
|
| 135 |
|
|
for (iterator i = begin (); i < end (); ++i) |
| 136 |
|
|
{ |
| 137 |
root |
1.4 |
if (ctx.mode == draw_context::LIGHTED) |
| 138 |
|
|
glColor3fv ((GLfloat *)&i->c); |
| 139 |
|
|
|
| 140 |
root |
1.2 |
glVertex3fv ((GLfloat *)&i->p); |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
|
glEnd (); |
| 144 |
|
|
} |
| 145 |
|
|
|
| 146 |
|
|
template<GLenum type> |
| 147 |
root |
1.13 |
void entity_opengl2d<type>::draw (draw_context &ctx) |
| 148 |
root |
1.2 |
{ |
| 149 |
|
|
glBegin (type); |
| 150 |
|
|
|
| 151 |
root |
1.5 |
if (ctx.mode == draw_context::LIGHTED) |
| 152 |
|
|
{ |
| 153 |
|
|
glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *)&m.diffuse); |
| 154 |
|
|
glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *)&m.specular); |
| 155 |
|
|
glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *)&m.emission); |
| 156 |
root |
1.9 |
glMaterialf (GL_FRONT, GL_SHININESS, m.shininess); |
| 157 |
root |
1.5 |
} |
| 158 |
|
|
|
| 159 |
root |
1.2 |
for (iterator i = begin (); i < end (); ++i) |
| 160 |
|
|
{ |
| 161 |
root |
1.4 |
if (ctx.mode == draw_context::LIGHTED) |
| 162 |
|
|
{ |
| 163 |
|
|
glTexCoord2fv ((GLfloat *)&i->t); |
| 164 |
|
|
glNormal3fv ((GLfloat *)&i->n); |
| 165 |
|
|
} |
| 166 |
|
|
|
| 167 |
root |
1.2 |
glVertex3fv ((GLfloat *)&i->p); |
| 168 |
|
|
} |
| 169 |
|
|
|
| 170 |
|
|
glEnd (); |
| 171 |
|
|
} |
| 172 |
|
|
|
| 173 |
|
|
template<GLenum type> |
| 174 |
|
|
void entity_opengl1d<type>::show (const sector &sec) |
| 175 |
|
|
{ |
| 176 |
root |
1.8 |
world.add (sec, this); |
| 177 |
root |
1.2 |
} |
| 178 |
|
|
|
| 179 |
|
|
template<GLenum type> |
| 180 |
|
|
void entity_opengl2d<type>::show (const sector &sec) |
| 181 |
|
|
{ |
| 182 |
root |
1.8 |
world.add (sec, this); |
| 183 |
root |
1.1 |
} |
| 184 |
|
|
|
| 185 |
|
|
|