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