ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/view.C
Revision: 1.25
Committed: Wed Oct 6 09:40:50 2004 UTC (21 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.24: +12 -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.17 view::view ()
7 root 1.18 : gamma(1.0)
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.18 void view::reset_projection ()
25 root 1.1 {
26 root 1.5 renormalize (orig, p);
27 root 1.3
28 root 1.1 glViewport (0, 0, w, h);
29    
30     glMatrixMode (GL_PROJECTION);
31     glLoadIdentity ();
32    
33     GLdouble aspect = (GLdouble)w/h;
34 root 1.6 GLdouble zNear = 0.1;
35     GLdouble zFar = 50.;
36 root 1.1
37     GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
38     glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
39    
40 root 1.6 d = normalize (d);//D
41     u = normalize (u);//D
42 root 1.1 vec3 rz = -d;
43     vec3 rx = cross (u, rz);
44     vec3 ry = cross (rz, rx);
45    
46 root 1.17 matrix &m = projection;
47 root 1.16 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0;
48     m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0;
49     m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0;
50 root 1.3 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
51    
52     glMultMatrixf ((GLfloat *)m.data);
53 root 1.6
54 root 1.5 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m);
55    
56 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) );
57     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) );
58     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) );
59     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) );
60     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) );
61     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) );
62 root 1.1
63 root 1.13 glMatrixMode (GL_MODELVIEW);
64 root 1.12 glLoadIdentity ();
65 root 1.16 glTranslatef (-p.x, -p.y, -p.z);
66 root 1.18 }
67    
68     void view::begin ()
69     {
70     vismap.clear ();
71 root 1.19 vislist.clear ();
72 root 1.18
73     generation++;
74 root 1.12
75 root 1.18 reset_projection ();
76    
77     // check occlusion queries here
78 root 1.24 #if 0
79 root 1.20 for (vector<octant *>::iterator i = checklist.begin (); i != checklist.end (); ++i)
80 root 1.22 //printf ("%p %d\n", *i, occ_query_result ((*i)->occ_query));
81     occ_query_result ((*i)->occ_query);
82 root 1.20
83 root 1.17 checklist.clear ();
84 root 1.24 #endif
85 root 1.18
86 root 1.17 world.detect_visibility (*this);
87 root 1.18 }
88    
89     void view::end ()
90     {
91     vismap.clear ();
92     }
93    
94     void view::pass (enum mode m)
95     {
96     mode = m;
97    
98     glDisable (GL_ALPHA_TEST);
99     glDisable (GL_BLEND);
100 root 1.4
101 root 1.18 if (mode == view::DEPTH)
102     {
103     glEnable (GL_POLYGON_OFFSET_FILL);
104     glPolygonOffset (0, 1);
105     glDepthFunc (GL_LESS);
106     glDisable (GL_LIGHTING);
107     glColorMask (0, 0, 0, 0);
108 root 1.24 cgGLEnableProfile (vsh_profile);// z-fighting??
109 root 1.23 cgGLDisableProfile (fsh_profile);
110 root 1.18 }
111     else
112     {
113     glEnable (GL_MINMAX);
114     glDisable (GL_POLYGON_OFFSET_FILL);
115     glDepthFunc (GL_LESS);
116     glDepthMask (0);
117 root 1.23 cgGLEnableProfile (vsh_profile);
118     cgGLEnableProfile (fsh_profile);
119 root 1.18 }
120    
121 root 1.17 for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i)
122     (*i)->display (*this);
123    
124     drawn.clear ();
125 root 1.24
126 root 1.25 if (mode == view::DEPTH)
127     {
128     static int count; count++;
129     if (farlist.size ())
130     printf ("%d: size %d\n", count, farlist.size ());
131    
132     glDepthFunc (GL_LEQUAL);
133     for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i)
134     (*i)->draw_bbox (*this);
135    
136     farlist.clear ();
137     }
138 root 1.4
139     glColorMask (1, 1, 1, 0);
140     glDepthMask (1);
141 root 1.1 }
142 root 1.6
143 root 1.1