1 | #include <algorithm> |
1 | #include <algorithm> |
2 | |
2 | |
3 | using namespace std; |
3 | using 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 | |
9 | entity_base::entity_base () |
10 | entity_base::entity_base () |
… | |
… | |
14 | entity_base::~entity_base () |
15 | entity_base::~entity_base () |
15 | { |
16 | { |
16 | hide (); |
17 | hide (); |
17 | } |
18 | } |
18 | |
19 | |
19 | void entity_base::update_bbox () |
20 | void entity_base::update () |
20 | { |
21 | { |
21 | if (parent) |
22 | if (parent) |
22 | parent->update_bbox (); |
23 | parent->update (); |
23 | } |
24 | } |
24 | |
25 | |
25 | void entity_base::hide () |
26 | void 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 | |
41 | void entity_filter::update_bbox () |
42 | void 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 | |
48 | void entity_filter::show () |
49 | void 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 | |
67 | void entity_container::update_bbox () |
68 | void 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 | |
77 | void entity_container::show () |
78 | void entity_container::show () |
78 | { |
79 | { |
79 | entity_base::show (); |
80 | entity_base::show (); |
… | |
… | |
120 | template class entity_opengl2d<GL_QUADS>; |
121 | template class entity_opengl2d<GL_QUADS>; |
121 | template class entity_opengl2d<GL_QUAD_STRIP>; |
122 | template class entity_opengl2d<GL_QUAD_STRIP>; |
122 | template class entity_opengl2d<GL_POLYGON>; |
123 | template class entity_opengl2d<GL_POLYGON>; |
123 | |
124 | |
124 | template<GLenum type> |
125 | template<GLenum type> |
125 | void entity_opengl1d<type>::update_bbox () |
126 | void 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 | |
135 | template<GLenum type> |
136 | template<GLenum type> |
136 | void entity_opengl1d<type>::draw (draw_context &ctx) |
137 | void 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); |
… | |
… | |
203 | entity_transform::entity_transform () |
204 | entity_transform::entity_transform () |
204 | { |
205 | { |
205 | m.identity (); |
206 | m.identity (); |
206 | } |
207 | } |
207 | |
208 | |
208 | void entity_transform::update_bbox () |
209 | void 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 | |
|
|
226 | void 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 | |
|
|
235 | void entity_transform::update (const gl_matrix &xfrm) |
|
|
236 | { |
|
|
237 | m = m * xfrm; |
|
|
238 | |
|
|
239 | renormalize (); |
|
|
240 | update (); |
|
|
241 | } |
|
|
242 | |
|
|
243 | void entity_transform::set_matrix (const gl_matrix &xfrm) |
|
|
244 | { |
|
|
245 | m = xfrm; |
|
|
246 | |
|
|
247 | renormalize (); |
|
|
248 | update (); |
223 | } |
249 | } |
224 | |
250 | |
225 | void entity_transform::show () |
251 | void entity_transform::show () |
226 | { |
252 | { |
227 | entity_base::show (); |
253 | entity_base::show (); |
… | |
… | |
229 | |
255 | |
230 | void entity_transform::draw (draw_context &ctx) |
256 | void 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 | |
238 | void entity_anim::draw (draw_context &ctx) |
268 | void 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 | |