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

Comparing libgender/view.C (file contents):
Revision 1.71 by root, Thu Nov 4 04:46:58 2004 UTC vs.
Revision 1.74 by root, Sat Nov 6 04:26:18 2004 UTC

108 GLdouble aspect = (GLdouble)w/h; 108 GLdouble aspect = (GLdouble)w/h;
109 GLdouble ftan = tan (fov * (.5 * M_PI / 180.)); 109 GLdouble ftan = tan (fov * (.5 * M_PI / 180.));
110 GLdouble ymax = z_near * ftan; 110 GLdouble ymax = z_near * ftan;
111 GLdouble xmax = ymax * aspect; 111 GLdouble xmax = ymax * aspect;
112 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
113 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);
114 130
115 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;
116 136
117 d = normalize (d);//D 137 d = normalize (d);//D
118 u = normalize (u);//D 138 u = normalize (u);//D
119 139
120 vec3 rz = -d; 140 vec3 rz = -d;
121 vec3 rx = cross (u, rz); 141 vec3 rx = cross (u, rz);
122 vec3 ry = cross (rz, rx); 142 vec3 ry = cross (rz, rx);
123 143
124 matrix &m = projection;
125 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;
126 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;
127 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;
128 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;
129 148
131 //printf ("diagfact = %f\n", diagfact); 150 //printf ("diagfact = %f\n", diagfact);
132 diagfact = sqrtf (3.);//D WHY??? 151 diagfact = sqrtf (3.);//D WHY???
133 152
134 glMultMatrixf (m); 153 glMultMatrixf (m);
135 154
136 glGetFloatv (GL_PROJECTION_MATRIX, m); 155 glGetFloatv (GL_MODELVIEW_MATRIX, m);
156
157 m = perspective * m;
137 158
138 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) );
139 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) );
140 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) );
141 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) );
156 GLdouble depth = h / ftan; 177 GLdouble depth = h / ftan;
157 178
158 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));
159 } 180 }
160 181
161 glMatrixMode (GL_MODELVIEW);
162 glLoadIdentity ();
163 glTranslatef (-p.x, -p.y, -p.z); 182 glTranslatef (-p.x, -p.y, -p.z);
164} 183}
165 184
166void view::begin () 185void view::begin ()
167{ 186{
291{ 310{
292 using namespace shader::compile; 311 using namespace shader::compile;
293 312
294 lightvec = xyz (lightpos - model_view_matrix * vin.vertex); 313 lightvec = xyz (lightpos - model_view_matrix * vin.vertex);
295 camdist = max (1 - length (lightvec) / radius, 0); 314 camdist = max (1 - length (lightvec) / radius, 0);
296}
297 315
298shader::temp_3f linear_light::operator ()() 316 fsh ();
317}
318
319void linear_light::fsh ()
299{ 320{
300 using namespace shader::compile; 321 using namespace shader::compile;
301 322
302 temp_3f res; 323 sh_lightvec = lightvec;
303 res = float3 (c.r / 255.F, c.g / 255.F, c.b / 255.F) * (min (intensity * camdist * 0.6F + 0.9F, 1.F)); 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));
304
305 return res;
306} 325}
307 326
308 327

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines