ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/view.C
Revision: 1.3
Committed: Mon Oct 4 02:06:57 2004 UTC (22 years ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.2: +27 -9 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include <cmath>
2    
3     #include "oct.h"
4     #include "view.h"
5    
6 root 1.2 draw_context::draw_context (view &v)
7     : v(v), l(0), mode(LIGHTED)
8 root 1.1 {
9     }
10    
11     draw_context::~draw_context ()
12     {
13     }
14    
15     bool draw_context::may_draw (entity_base *e)
16     {
17     if (drawn.find (e) != drawn.end ())
18     return false;
19    
20     drawn.insert (e);
21     return true;
22     }
23    
24     void view::draw (draw_context &ctx)
25     {
26 root 1.3
27     if (ctx.mode == draw_context::DEPTH)
28     {
29     glEnable (GL_POLYGON_OFFSET_FILL);
30     glPolygonOffset (0, 1);
31     glDrawBuffer (GL_NONE);
32     glDepthFunc (GL_LESS);
33     glDisable (GL_LIGHTING);
34     }
35     else
36     {
37     glDisable (GL_POLYGON_OFFSET_FILL);
38     glDrawBuffer (GL_BACK);
39     glDepthFunc (GL_LEQUAL);
40     glEnable (GL_LIGHTING);
41     }
42    
43 root 1.1 glViewport (0, 0, w, h);
44    
45     glMatrixMode (GL_PROJECTION);
46     glLoadIdentity ();
47    
48     GLdouble aspect = (GLdouble)w/h;
49 root 1.3 GLdouble zNear = 0.001;
50     GLdouble zFar = 100.;
51 root 1.1
52     GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
53     glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
54    
55     vec3 rz = -d;
56     vec3 rx = cross (u, rz);
57     vec3 ry = cross (rz, rx);
58    
59 root 1.3 gl_matrix &m = ctx.projection;
60     m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0;
61     m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0;
62     m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0;
63     m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
64    
65     glMultMatrixf ((GLfloat *)m.data);
66 root 1.1
67     glMatrixMode (GL_MODELVIEW);
68     glLoadIdentity ();
69 root 1.3 glTranslatef (-p.x, -p.y, -p.z);
70 root 1.1
71     world.draw (ctx);
72     }
73