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

Comparing libgender/entity.C (file contents):
Revision 1.1 by root, Sat Oct 2 15:54:43 2004 UTC vs.
Revision 1.2 by root, Sun Oct 3 01:14:40 2004 UTC

1#include <algorithm> 1#include <algorithm>
2#include <cmath>
2 3
3using namespace std; 4using namespace std;
4 5
5#include "entity.h" 6#include "entity.h"
7
8const vec3 cross (const vec3 &a, const vec3 &b)
9{
10 return vec3 (
11 a.y * b.z - a.z * b.y,
12 a.z * b.x - a.x * b.z,
13 a.x * b.y - a.y * b.x
14 );
15}
16
17GLfloat dot (const vec3 &a, const vec3 &b)
18{
19 return a.x * b.x + a.y * b.y + a.z * b.z;
20}
6 21
7void box::add (const box &o) 22void box::add (const box &o)
8{ 23{
9 a.x = min (a.x, o.a.x); 24 a.x = min (a.x, o.a.x);
10 a.y = min (a.y, o.a.y); 25 a.y = min (a.y, o.a.y);
49 delete e; 64 delete e;
50} 65}
51 66
52void entity::show (const sector &sec) 67void entity::show (const sector &sec)
53{ 68{
69 show ();
70}
71
72void entity::show ()
73{
54 e->show (this->sec); 74 e->show (this->sec);
55} 75}
56 76
57void entity::draw () 77void entity::draw ()
58{ 78{
79 glPushMatrix ();
59 //TODO setup matrix etc. 80 //TODO setup matrix etc.
60 e->draw (); 81 e->draw ();
82 glPopMatrix ();
61} 83}
62 84
63void entity_container::update_bbox () 85void entity_container::update_bbox ()
64{ 86{
65 bbox.reset (); 87 bbox.reset ();
91 delete *i; 113 delete *i;
92 114
93 clear (); 115 clear ();
94} 116}
95 117
118template entity_opengl1d<GL_POINTS>;
119template entity_opengl1d<GL_LINES>;
120template entity_opengl1d<GL_LINE_STRIP>;
121template entity_opengl1d<GL_LINE_LOOP>;
122template entity_opengl2d<GL_TRIANGLES>;
123template entity_opengl2d<GL_TRIANGLE_STRIP>;
124template entity_opengl2d<GL_TRIANGLE_FAN>;
125template entity_opengl2d<GL_QUADS>;
126template entity_opengl2d<GL_QUAD_STRIP>;
127template entity_opengl2d<GL_POLYGON>;
96 128
129template<GLenum type>
130void entity_opengl1d<type>::update_bbox ()
131{
132 entity_base::update_bbox ();
133}
134
135template<GLenum type>
136void entity_opengl2d<type>::update_bbox ()
137{
138 entity_base::update_bbox ();
139}
140
141template<GLenum type>
142void entity_opengl1d<type>::draw ()
143{
144 glBegin (type);
145
146 for (iterator i = begin (); i < end (); ++i)
147 {
148 glColor3fv ((GLfloat *)&i->c);
149 glVertex3fv ((GLfloat *)&i->p);
150 }
151
152 glEnd ();
153}
154
155template<GLenum type>
156void entity_opengl2d<type>::draw ()
157{
158 glBegin (type);
159
160 for (iterator i = begin (); i < end (); ++i)
161 {
162 glColor3fv ((GLfloat *)&i->c);
163 glNormal3fv ((GLfloat *)&i->n);
164 glTexCoord2fv ((GLfloat *)&i->t);
165 glVertex3fv ((GLfloat *)&i->p);
166 }
167
168 glEnd ();
169}
170
171template<GLenum type>
172void entity_opengl1d<type>::show (const sector &sec)
173{
174}
175
176template<GLenum type>
177void entity_opengl2d<type>::show (const sector &sec)
178{
179}
180
181void view::draw (const draw_context &c)
182{
183 glViewport (0, 0, w, h);
184
185 glMatrixMode (GL_PROJECTION);
186 glLoadIdentity ();
187
188 double aspect = (double)w/h;
189 double zNear = 5;
190 double zFar = 1000.;
191
192 {
193 GLdouble xmin, xmax, ymin, ymax;
194
195 ymax = zNear * tan (fov * (M_PI / 360.0));
196 ymin = -ymax;
197 xmin = ymin * aspect;
198 xmax = ymax * aspect;
199
200 glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
201 }
202
203 vec3 rz = -d;
204 vec3 rx = cross (u, rz);
205 vec3 ry = cross (rz, rx);
206
207 GLfloat m[4][4];
208 m[0][0] = rx.x; m[0][1] = rx.y; m[0][2] = rx.z; m[0][3] = 0;
209 m[1][0] = ry.x; m[1][1] = ry.y; m[1][2] = ry.z; m[1][3] = 0;
210 m[2][0] = rz.x; m[2][1] = rz.y; m[2][2] = rz.z; m[2][3] = 0;
211 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1;
212 glMultMatrixf ((GLfloat *)m);
213
214 glTranslatef (-p.x, -p.y, -p.z);
215
216 glMatrixMode (GL_MODELVIEW);
217 glLoadIdentity ();
218
219 entity *e = new entity;
220 e->sec.x = e->sec.y = e->sec.z = 0;
221
222 entity_triangles *tri = new entity_triangles;
223 tri->push_back (vertex2d (colour (1, 0, 0), point (-9, 0, -9), vec3 (0, 0, 1)));
224 tri->push_back (vertex2d (colour (0, 1, 1), point ( 0, 9, -9), vec3 (0, 0, 1)));
225 tri->push_back (vertex2d (colour (1, 0, 1), point ( 9, 0, -9), vec3 (0, 0, 1)));
226 e->set (tri);
227
228 e->show ();
229 e->draw ();
230
231 delete e;
232}
233
234

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines