ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
Revision: 1.13
Committed: Tue Oct 5 08:13:01 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.12: +1 -12 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.4 // check occlusion queries here
27    
28     ctx.generation++;
29    
30 root 1.5 renormalize (orig, p);
31 root 1.3
32     if (ctx.mode == draw_context::DEPTH)
33     {
34     glEnable (GL_POLYGON_OFFSET_FILL);
35     glPolygonOffset (0, 1);
36     glDepthFunc (GL_LESS);
37     glDisable (GL_LIGHTING);
38 root 1.4 glColorMask (0, 0, 0, 0);
39 root 1.3 }
40     else
41     {
42     glDisable (GL_POLYGON_OFFSET_FILL);
43     glDrawBuffer (GL_BACK);
44     glDepthFunc (GL_LEQUAL);
45     glEnable (GL_LIGHTING);
46 root 1.4 glDepthMask (0);
47 root 1.3 }
48    
49 root 1.1 glViewport (0, 0, w, h);
50    
51     glMatrixMode (GL_PROJECTION);
52     glLoadIdentity ();
53    
54     GLdouble aspect = (GLdouble)w/h;
55 root 1.6 GLdouble zNear = 0.1;
56     GLdouble zFar = 50.;
57 root 1.1
58     GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
59     glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
60    
61 root 1.6 d = normalize (d);//D
62     u = normalize (u);//D
63 root 1.1 vec3 rz = -d;
64     vec3 rx = cross (u, rz);
65     vec3 ry = cross (rz, rx);
66    
67 root 1.9 matrix &m = ctx.projection;
68 root 1.6 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = -p.x;
69     m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = -p.y;
70     m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = -p.z;
71 root 1.3 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
72    
73     glMultMatrixf ((GLfloat *)m.data);
74 root 1.6
75 root 1.5 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m);
76    
77 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) );
78     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) );
79     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) );
80     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) );
81     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) );
82     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) );
83 root 1.1
84 root 1.13 glMatrixMode (GL_MODELVIEW);
85 root 1.12 glLoadIdentity ();
86    
87 root 1.1 world.draw (ctx);
88 root 1.4
89     ctx.drawn.clear ();
90    
91     glColorMask (1, 1, 1, 0);
92     glDepthMask (1);
93 root 1.1 }
94 root 1.6
95 root 1.1