ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
Revision: 1.14
Committed: Tue Oct 5 08:28:39 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.13: +4 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <cmath>
2
3 #include "oct.h"
4 #include "view.h"
5
6 draw_context::draw_context (view &v)
7 : v(v), l(0), mode(LIGHTED)
8 {
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 // check occlusion queries here
27
28 ctx.generation++;
29
30 renormalize (orig, p);
31
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 glColorMask (0, 0, 0, 0);
39 cgGLDisableProfile (CG_PROFILE_ARBVP1);
40 cgGLDisableProfile (CG_PROFILE_ARBFP1);
41 }
42 else
43 {
44 glDisable (GL_POLYGON_OFFSET_FILL);
45 glDrawBuffer (GL_BACK);
46 glDepthFunc (GL_LEQUAL);
47 glEnable (GL_LIGHTING);
48 glDepthMask (0);
49 cgGLEnableProfile (CG_PROFILE_ARBVP1);
50 cgGLEnableProfile (CG_PROFILE_ARBFP1);
51 }
52
53 glViewport (0, 0, w, h);
54
55 glMatrixMode (GL_PROJECTION);
56 glLoadIdentity ();
57
58 GLdouble aspect = (GLdouble)w/h;
59 GLdouble zNear = 0.1;
60 GLdouble zFar = 50.;
61
62 GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
63 glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
64
65 d = normalize (d);//D
66 u = normalize (u);//D
67 vec3 rz = -d;
68 vec3 rx = cross (u, rz);
69 vec3 ry = cross (rz, rx);
70
71 matrix &m = ctx.projection;
72 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = -p.x;
73 m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = -p.y;
74 m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = -p.z;
75 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
76
77 glMultMatrixf ((GLfloat *)m.data);
78
79 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m);
80
81 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) );
82 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) );
83 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) );
84 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) );
85 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) );
86 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) );
87
88 glMatrixMode (GL_MODELVIEW);
89 glLoadIdentity ();
90
91 world.draw (ctx);
92
93 ctx.drawn.clear ();
94
95 glColorMask (1, 1, 1, 0);
96 glDepthMask (1);
97 }
98
99