ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
Revision: 1.1
Committed: Sun Oct 3 05:10:46 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <cmath>
2
3 #include "oct.h"
4 #include "view.h"
5
6 draw_context::draw_context ()
7 {
8 }
9
10 draw_context::~draw_context ()
11 {
12 }
13
14 bool draw_context::may_draw (entity_base *e)
15 {
16 if (drawn.find (e) != drawn.end ())
17 return false;
18
19 drawn.insert (e);
20 return true;
21 }
22
23 void view::draw (draw_context &ctx)
24 {
25 glViewport (0, 0, w, h);
26
27 glMatrixMode (GL_PROJECTION);
28 glLoadIdentity ();
29
30 GLdouble aspect = (GLdouble)w/h;
31 GLdouble zNear = 0.0001;
32 GLdouble zFar = 1000.;
33
34 GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
35 glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
36
37 vec3 rz = -d;
38 vec3 rx = cross (u, rz);
39 vec3 ry = cross (rz, rx);
40
41 GLfloat m[4][4];
42 m[0][0] = rx.x; m[0][1] = rx.y; m[0][2] = rx.z; m[0][3] = 0;
43 m[1][0] = ry.x; m[1][1] = ry.y; m[1][2] = ry.z; m[1][3] = 0;
44 m[2][0] = rz.x; m[2][1] = rz.y; m[2][2] = rz.z; m[2][3] = 0;
45 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1;
46 glMultMatrixf ((GLfloat *)m);
47
48 glTranslatef (-p.x, -p.y, -p.z);
49
50 glMatrixMode (GL_MODELVIEW);
51 glLoadIdentity ();
52
53 world.draw (ctx);
54 }
55