ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
(Generate patch)

Comparing libgender/view.C (file contents):
Revision 1.66 by root, Fri Oct 29 23:27:02 2004 UTC vs.
Revision 1.74 by root, Sat Nov 6 04:26:18 2004 UTC

4 4
5#include "view.h" 5#include "view.h"
6#include "oct.h" 6#include "oct.h"
7 7
8using namespace gl; 8using namespace gl;
9
10pass pass_depth (0);
9 11
10vector<GLuint> occ_query_objects; 12vector<GLuint> occ_query_objects;
11 13
12static GLuint begin_occ_query () 14static GLuint begin_occ_query ()
13{ 15{
106 GLdouble aspect = (GLdouble)w/h; 108 GLdouble aspect = (GLdouble)w/h;
107 GLdouble ftan = tan (fov * (.5 * M_PI / 180.)); 109 GLdouble ftan = tan (fov * (.5 * M_PI / 180.));
108 GLdouble ymax = z_near * ftan; 110 GLdouble ymax = z_near * ftan;
109 GLdouble xmax = ymax * aspect; 111 GLdouble xmax = ymax * aspect;
110 112
113 matrix perspective;
114#if 1
115 {
116 matrix &m = perspective;
117
118 m(0,0) = 1.F / xmax; m(0,1) = 0; m(0,2) = 0; m(0,3) = 0;
119 m(1,0) = 0; m(1,1) = 1.F / ymax; m(1,2) = 0; m(1,3) = 0;
120 m(2,0) = 0; m(2,1) = 0; m(2,2) = -2.F / z_far; m(2,3) = 0;
121 m(3,0) = 0; m(3,1) = 0; m(3,2) = -1; m(3,3) = 0;
122
123 glLoadMatrixf (perspective);
124 }
125#else
111 glFrustum (-xmax, xmax, -ymax, ymax, z_near, z_far); 126 glFrustum (-xmax, xmax, -ymax, ymax, z_near, z_far);
127#endif
128
129 glGetFloatv (GL_PROJECTION_MATRIX, perspective);
112 130
113 perspfact = z_near / ymax * 0.5F * h; 131 perspfact = z_near / ymax * 0.5F * h;
132
133 glMatrixMode (GL_MODELVIEW);
134 glLoadIdentity ();
135 matrix &m = projection;
114 136
115 d = normalize (d);//D 137 d = normalize (d);//D
116 u = normalize (u);//D 138 u = normalize (u);//D
117 139
118 vec3 rz = -d; 140 vec3 rz = -d;
119 vec3 rx = cross (u, rz); 141 vec3 rx = cross (u, rz);
120 vec3 ry = cross (rz, rx); 142 vec3 ry = cross (rz, rx);
121 143
122 matrix &m = projection;
123 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0; 144 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0;
124 m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0; 145 m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0;
125 m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0; 146 m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0;
126 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1; 147 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
127 148
128 diagfact = abs (rz.x) + abs (rz.y) + abs (rz.z); 149 diagfact = abs (rz.x) + abs (rz.y) + abs (rz.z);
129 //printf ("diagfact = %f\n", diagfact); 150 //printf ("diagfact = %f\n", diagfact);
130 diagfact = sqrtf (3.);//D WHY??? 151 diagfact = sqrtf (3.);//D WHY???
131 152
132 glMultMatrixf (m); 153 glMultMatrixf (m);
133 glTranslatef (-p.x, -p.y, -p.z);
134 154
135 glGetFloatv (GL_PROJECTION_MATRIX, m); 155 glGetFloatv (GL_MODELVIEW_MATRIX, m);
156
157 m = perspective * m;
136 158
137 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) ); 159 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) );
138 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) ); 160 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) );
139 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) ); 161 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) );
140 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) ); 162 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) );
155 GLdouble depth = h / ftan; 177 GLdouble depth = h / ftan;
156 178
157 frustum.c = cone (p, d, atan (sqrt (GLdouble (w * w + h * h)) * ftan / h)); 179 frustum.c = cone (p, d, atan (sqrt (GLdouble (w * w + h * h)) * ftan / h));
158 } 180 }
159 181
160 glMatrixMode (GL_MODELVIEW); 182 glTranslatef (-p.x, -p.y, -p.z);
161 glLoadIdentity ();
162} 183}
163 184
164void view::begin () 185void view::begin ()
165{ 186{
166 generation++; 187 generation++;
182 vislist.clear (); 203 vislist.clear ();
183} 204}
184 205
185#define DEPTH_OFFSET (1. / (GLdouble)(1L << 16)) 206#define DEPTH_OFFSET (1. / (GLdouble)(1L << 16))
186 207
187void view::render (enum pass p) 208void view::render (enum pass_type p, pass &data)
188{ 209{
189 pass = p; 210 pass_type = p;
211 pass_data = &data;
190 212
191 switch (pass) 213 switch (pass_type)
192 { 214 {
193 case DEPTH: 215 case DEPTH:
194 glColorMask (1, 1, 1, 1); 216 glColorMask (1, 1, 1, 1);
195 glDepthMask (1); 217 glDepthMask (1);
196 218
246 } 268 }
247 269
248 for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i) 270 for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i)
249 (*i)->display (*this); 271 (*i)->display (*this);
250 272
251 if (pass == LIGHTED) 273 if (pass_type == DEPTH)
252 printf ("fps %f NF %f:%f vis %d CAM (%d,%d,%d)\n", timer.fps, z_near, z_far, drawn.size (), orig.x, orig.y, orig.z);//D 274 printf ("fps %f NF %f:%f vis %d CAM (%d,%d,%d)\n", timer.fps, z_near, z_far, drawn.size (), orig.x, orig.y, orig.z);//D
253 275
254 drawn.clear (); 276 drawn.clear ();
255 277
256#if 0 278#if 0
270 glDisable (GL_DEPTH_CLAMP_NV); 292 glDisable (GL_DEPTH_CLAMP_NV);
271 } 293 }
272#endif 294#endif
273} 295}
274 296
297void light::enable ()
298{
299 lightpos->set (p);
300}
275 301
302void light::disable ()
303{
304}
305
306static shader::varying_1f camdist;
307static shader::varying_3f lightvec;
308
309void linear_light::vsh ()
310{
311 using namespace shader::compile;
312
313 lightvec = xyz (lightpos - model_view_matrix * vin.vertex);
314 camdist = max (1 - length (lightvec) / radius, 0);
315
316 fsh ();
317}
318
319void linear_light::fsh ()
320{
321 using namespace shader::compile;
322
323 sh_lightvec = lightvec;
324 sh_colour = float3 (c.r / 255.F, c.g / 255.F, c.b / 255.F) * (min (intensity * camdist * 0.6F + 0.9F, 1.F));
325}
326
327

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines