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