ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
Revision: 1.31
Committed: Wed Oct 6 17:04:06 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.30: +4 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include <cmath>
2    
3 root 1.26 #include <GL/gl.h>
4     #include <GL/glext.h>
5    
6 root 1.1 #include "oct.h"
7     #include "view.h"
8    
9 root 1.17 view::view ()
10 root 1.18 : gamma(1.0)
11 root 1.1 {
12     }
13    
14 root 1.17 view::~view ()
15 root 1.1 {
16     }
17    
18 root 1.17 bool view::may_draw (entity_base *e)
19 root 1.1 {
20     if (drawn.find (e) != drawn.end ())
21     return false;
22    
23     drawn.insert (e);
24     return true;
25     }
26    
27 root 1.18 void view::reset_projection ()
28 root 1.1 {
29 root 1.5 renormalize (orig, p);
30 root 1.3
31 root 1.1 glViewport (0, 0, w, h);
32    
33     glMatrixMode (GL_PROJECTION);
34     glLoadIdentity ();
35    
36     GLdouble aspect = (GLdouble)w/h;
37 root 1.6 GLdouble zNear = 0.1;
38     GLdouble zFar = 50.;
39 root 1.1
40     GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
41     glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
42    
43 root 1.6 d = normalize (d);//D
44     u = normalize (u);//D
45 root 1.1 vec3 rz = -d;
46     vec3 rx = cross (u, rz);
47     vec3 ry = cross (rz, rx);
48    
49 root 1.17 matrix &m = projection;
50 root 1.16 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0;
51     m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0;
52     m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0;
53 root 1.3 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
54    
55     glMultMatrixf ((GLfloat *)m.data);
56 root 1.6
57 root 1.5 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m);
58    
59 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) );
60     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) );
61     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) );
62     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) );
63     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) );
64     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) );
65 root 1.1
66 root 1.13 glMatrixMode (GL_MODELVIEW);
67 root 1.12 glLoadIdentity ();
68 root 1.16 glTranslatef (-p.x, -p.y, -p.z);
69 root 1.18 }
70    
71     void view::begin ()
72     {
73 root 1.30 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
74     glDepthRange (0, 1. - (1. / pow (2., 16.)));
75    
76 root 1.18 vismap.clear ();
77 root 1.19 vislist.clear ();
78 root 1.18
79     generation++;
80 root 1.12
81 root 1.18 reset_projection ();
82    
83 root 1.31 for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i)
84     ;
85     farlist.clear ();
86    
87 root 1.18 // check occlusion queries here
88 root 1.24 #if 0
89 root 1.20 for (vector<octant *>::iterator i = checklist.begin (); i != checklist.end (); ++i)
90 root 1.22 //printf ("%p %d\n", *i, occ_query_result ((*i)->occ_query));
91     occ_query_result ((*i)->occ_query);
92 root 1.20
93 root 1.17 checklist.clear ();
94 root 1.24 #endif
95 root 1.18
96 root 1.17 world.detect_visibility (*this);
97 root 1.18 }
98    
99     void view::end ()
100     {
101     vismap.clear ();
102     }
103    
104     void view::pass (enum mode m)
105     {
106     mode = m;
107    
108     glDisable (GL_ALPHA_TEST);
109     glDisable (GL_BLEND);
110 root 1.4
111 root 1.18 if (mode == view::DEPTH)
112     {
113     glEnable (GL_POLYGON_OFFSET_FILL);
114     glPolygonOffset (0, 1);
115     glDepthFunc (GL_LESS);
116     glDisable (GL_LIGHTING);
117     glColorMask (0, 0, 0, 0);
118 root 1.24 cgGLEnableProfile (vsh_profile);// z-fighting??
119 root 1.23 cgGLDisableProfile (fsh_profile);
120 root 1.18 }
121     else
122     {
123     glEnable (GL_MINMAX);
124     glDisable (GL_POLYGON_OFFSET_FILL);
125     glDepthFunc (GL_LESS);
126     glDepthMask (0);
127 root 1.23 cgGLEnableProfile (vsh_profile);
128     cgGLEnableProfile (fsh_profile);
129 root 1.18 }
130    
131 root 1.17 for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i)
132     (*i)->display (*this);
133    
134     drawn.clear ();
135 root 1.24
136 root 1.27 if (mode == view::LIGHTED)
137 root 1.25 {
138 root 1.27 glEnable (GL_DEPTH_CLAMP_NV);
139 root 1.30 glDepthFunc (GL_LESS);
140 root 1.27 glEnable (GL_COLOR_MATERIAL);
141 root 1.30 glDisable (GL_LIGHTING);
142     #if 1
143 root 1.27 cgGLDisableProfile (vsh_profile);
144     cgGLDisableProfile (fsh_profile);
145     #endif
146 root 1.28 glShadeModel (GL_FLAT);
147 root 1.27
148 root 1.25 static int count; count++;
149     if (farlist.size ())
150     printf ("%d: size %d\n", count, farlist.size ());
151    
152 root 1.30 for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i)
153     {
154     glColor3f (1 / (GLfloat)(i - farlist.begin()), 1, 1 / (GLfloat)(i - farlist.begin()));
155 root 1.25 (*i)->draw_bbox (*this);
156 root 1.30 }
157 root 1.27
158     glEnable (GL_DEPTH_TEST);
159     glDisable (GL_DEPTH_CLAMP_NV);
160 root 1.28 glShadeModel (GL_SMOOTH);
161 root 1.25 }
162 root 1.4
163     glColorMask (1, 1, 1, 0);
164     glDepthMask (1);
165 root 1.27
166 root 1.1 }
167 root 1.6
168 root 1.1