ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/view.C
Revision: 1.10
Committed: Tue Oct 5 03:52:13 2004 UTC (22 years ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.9: +6 -2 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 root 1.10 void draw_context::transform (const matrix &m)
16     {
17     modelview = modelview * m;
18     mvp = projection * modelview;
19     }
20    
21 root 1.1 bool draw_context::may_draw (entity_base *e)
22     {
23     if (drawn.find (e) != drawn.end ())
24     return false;
25    
26     drawn.insert (e);
27     return true;
28     }
29    
30     void view::draw (draw_context &ctx)
31     {
32 root 1.4 // check occlusion queries here
33    
34     ctx.generation++;
35    
36 root 1.5 renormalize (orig, p);
37 root 1.3
38     if (ctx.mode == draw_context::DEPTH)
39     {
40     glEnable (GL_POLYGON_OFFSET_FILL);
41     glPolygonOffset (0, 1);
42     glDepthFunc (GL_LESS);
43     glDisable (GL_LIGHTING);
44 root 1.4 glColorMask (0, 0, 0, 0);
45 root 1.3 }
46     else
47     {
48     glDisable (GL_POLYGON_OFFSET_FILL);
49     glDrawBuffer (GL_BACK);
50     glDepthFunc (GL_LEQUAL);
51     glEnable (GL_LIGHTING);
52 root 1.4 glDepthMask (0);
53 root 1.3 }
54    
55 root 1.1 glViewport (0, 0, w, h);
56    
57     glMatrixMode (GL_PROJECTION);
58     glLoadIdentity ();
59    
60     GLdouble aspect = (GLdouble)w/h;
61 root 1.6 GLdouble zNear = 0.1;
62     GLdouble zFar = 50.;
63 root 1.1
64     GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
65     glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
66    
67 root 1.6 d = normalize (d);//D
68     u = normalize (u);//D
69 root 1.1 vec3 rz = -d;
70     vec3 rx = cross (u, rz);
71     vec3 ry = cross (rz, rx);
72    
73 root 1.9 matrix &m = ctx.projection;
74 root 1.6 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = -p.x;
75     m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = -p.y;
76     m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = -p.z;
77 root 1.3 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
78    
79     glMultMatrixf ((GLfloat *)m.data);
80 root 1.6
81 root 1.5 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m);
82    
83 root 1.6 ctx.frustum.l = plane ( m(3,0) + m(0,0), m(3,1) + m(0,1), m(3,2) + m(0,2), m(3,3) + m(0,3) );
84     ctx.frustum.r = plane ( m(3,0) - m(0,0), m(3,1) - m(0,1), m(3,2) - m(0,2), m(3,3) - m(0,3) );
85     ctx.frustum.b = plane ( m(3,0) + m(1,0), m(3,1) + m(1,1), m(3,2) + m(1,2), m(3,3) + m(1,3) );
86     ctx.frustum.t = plane ( m(3,0) - m(1,0), m(3,1) - m(1,1), m(3,2) - m(1,2), m(3,3) - m(1,3) );
87     ctx.frustum.n = plane ( m(3,0) + m(2,0), m(3,1) + m(2,1), m(3,2) + m(2,2), m(3,3) + m(2,3) );
88     ctx.frustum.f = plane ( m(3,0) - m(2,0), m(3,1) - m(2,1), m(3,2) - m(2,2), m(3,3) - m(2,3) );
89 root 1.1
90 root 1.8 for (int i = 0; i < 4; i++)
91     for (int j = 0; j < 4 ; j++)
92     mvp[i][j] = m(i,j);
93    
94 root 1.9 ctx.modelview.identity ();
95    
96 root 1.1 world.draw (ctx);
97 root 1.4
98     ctx.drawn.clear ();
99    
100     glColorMask (1, 1, 1, 0);
101     glDepthMask (1);
102 root 1.1 }
103 root 1.6
104 root 1.1