ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
Revision: 1.17
Committed: Wed Oct 6 00:55:37 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.16: +21 -16 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.17 view::view ()
7     : mode(LIGHTED)
8 root 1.1 {
9     }
10    
11 root 1.17 view::~view ()
12 root 1.1 {
13     }
14    
15 root 1.17 bool view::may_draw (entity_base *e)
16 root 1.1 {
17     if (drawn.find (e) != drawn.end ())
18     return false;
19    
20     drawn.insert (e);
21     return true;
22     }
23    
24 root 1.17 void view::draw ()
25 root 1.1 {
26 root 1.4 // check occlusion queries here
27    
28 root 1.17 generation++;
29 root 1.4
30 root 1.5 renormalize (orig, p);
31 root 1.3
32 root 1.16 glDisable (GL_ALPHA_TEST);
33     glDisable (GL_BLEND);
34    
35 root 1.17 if (mode == view::DEPTH)
36 root 1.3 {
37     glEnable (GL_POLYGON_OFFSET_FILL);
38     glPolygonOffset (0, 1);
39     glDepthFunc (GL_LESS);
40     glDisable (GL_LIGHTING);
41 root 1.4 glColorMask (0, 0, 0, 0);
42 root 1.16 //cgGLDisableProfile (CG_PROFILE_ARBVP1);
43 root 1.14 cgGLDisableProfile (CG_PROFILE_ARBFP1);
44 root 1.3 }
45     else
46     {
47 root 1.16 glEnable (GL_MINMAX);
48 root 1.3 glDisable (GL_POLYGON_OFFSET_FILL);
49 root 1.15 glDepthFunc (GL_LESS);
50 root 1.4 glDepthMask (0);
51 root 1.14 cgGLEnableProfile (CG_PROFILE_ARBVP1);
52     cgGLEnableProfile (CG_PROFILE_ARBFP1);
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.17 matrix &m = projection;
74 root 1.16 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0;
75     m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0;
76     m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0;
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.17 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     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     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     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     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     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.13 glMatrixMode (GL_MODELVIEW);
91 root 1.12 glLoadIdentity ();
92 root 1.16 glTranslatef (-p.x, -p.y, -p.z);
93 root 1.12
94 root 1.17 vislist.clear ();
95     checklist.clear ();
96     world.detect_visibility (*this);
97 root 1.4
98 root 1.17 for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i)
99     (*i)->display (*this);
100    
101     drawn.clear ();
102 root 1.4
103     glColorMask (1, 1, 1, 0);
104     glDepthMask (1);
105 root 1.1 }
106 root 1.6
107 root 1.1