ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/entity.C
Revision: 1.20
Committed: Sun Oct 3 09:18:23 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.19: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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