]> git.mxchange.org Git - flightgear.git/blob - Main/views.cxx
Optimizations by Norman Vine.
[flightgear.git] / Main / views.cxx
1 // views.cxx -- data structures and routines for managing and view
2 //               parameters.
3 //
4 // Written by Curtis Olson, started August 1997.
5 //
6 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <Aircraft/aircraft.h>
31 #include <Debug/fg_debug.h>
32 #include <Include/fg_constants.h>
33 #include <Math/mat3.h>
34 #include <Math/polar3d.hxx>
35 #include <Math/vector.hxx>
36 #include <Scenery/scenery.hxx>
37 #include <Time/fg_time.hxx>
38
39 #include "options.hxx"
40 #include "views.hxx"
41
42
43 // This is a record containing current view parameters
44 fgVIEW current_view;
45
46
47 // Constructor
48 fgVIEW::fgVIEW( void ) {
49 }
50
51
52 // Initialize a view structure
53 void fgVIEW::Init( void ) {
54     fgPrintf( FG_VIEW, FG_INFO, "Initializing View parameters\n");
55
56     view_offset = 0.0;
57     goal_view_offset = 0.0;
58
59     winWidth = 640;  // FG_DEFAULT_WIN_WIDTH
60     winHeight = 480; // FG_DEFAULT_WIN_HEIGHT
61     win_ratio = (double) winWidth / (double) winHeight;
62     update_fov = true;
63 }
64
65
66 // Update the field of view parameters
67 void fgVIEW::UpdateFOV( fgOPTIONS *o ) {
68     double fov, theta_x, theta_y;
69
70     fov = o->get_fov();
71         
72     // printf("win_ratio = %.2f\n", win_ratio);
73     // calculate sin() and cos() of fov / 2 in X direction;
74     theta_x = (fov * win_ratio * DEG_TO_RAD) / 2.0;
75     // printf("theta_x = %.2f\n", theta_x);
76     sin_fov_x = sin(theta_x);
77     cos_fov_x = cos(theta_x);
78     slope_x =  -cos_fov_x / sin_fov_x;
79     // printf("slope_x = %.2f\n", slope_x);
80
81 #if defined( USE_FAST_FOV_CLIP )
82     fov_x_clip = slope_x*cos_fov_x - sin_fov_x;
83 #endif // defined( USE_FAST_FOV_CLIP )
84
85     // calculate sin() and cos() of fov / 2 in Y direction;
86     theta_y = (fov * DEG_TO_RAD) / 2.0;
87     // printf("theta_y = %.2f\n", theta_y);
88     sin_fov_y = sin(theta_y);
89     cos_fov_y = cos(theta_y);
90     slope_y = cos_fov_y / sin_fov_y;
91     // printf("slope_y = %.2f\n", slope_y);
92
93 #if defined( USE_FAST_FOV_CLIP )
94     fov_y_clip = -(slope_y*cos_fov_y + sin_fov_y);      
95 #endif // defined( USE_FAST_FOV_CLIP )
96 }
97
98
99 // Basically, this is a modified version of the Mesa gluLookAt()
100 // function that's been modified slightly so we can capture the
101 // result before sending it off to OpenGL land.
102 void fgVIEW::LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
103                      GLdouble centerx, GLdouble centery, GLdouble centerz,
104                      GLdouble upx, GLdouble upy, GLdouble upz ) {
105     GLdouble *m;
106     GLdouble x[3], y[3], z[3];
107     GLdouble mag;
108
109     m = current_view.MODEL_VIEW;
110
111     /* Make rotation matrix */
112
113     /* Z vector */
114     z[0] = eyex - centerx;
115     z[1] = eyey - centery;
116     z[2] = eyez - centerz;
117     mag = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] );
118     if (mag) {  /* mpichler, 19950515 */
119         z[0] /= mag;
120         z[1] /= mag;
121         z[2] /= mag;
122     }
123
124     /* Y vector */
125     y[0] = upx;
126     y[1] = upy;
127     y[2] = upz;
128
129     /* X vector = Y cross Z */
130     x[0] =  y[1]*z[2] - y[2]*z[1];
131     x[1] = -y[0]*z[2] + y[2]*z[0];
132     x[2] =  y[0]*z[1] - y[1]*z[0];
133     
134     /* Recompute Y = Z cross X */
135     y[0] =  z[1]*x[2] - z[2]*x[1];
136     y[1] = -z[0]*x[2] + z[2]*x[0];
137     y[2] =  z[0]*x[1] - z[1]*x[0];
138
139     /* mpichler, 19950515 */
140     /* cross product gives area of parallelogram, which is < 1.0 for
141      * non-perpendicular unit-length vectors; so normalize x, y here
142      */
143
144     mag = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] );
145     if (mag) {
146         x[0] /= mag;
147         x[1] /= mag;
148       x[2] /= mag;
149     }
150
151     mag = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] );
152     if (mag) {
153         y[0] /= mag;
154         y[1] /= mag;
155         y[2] /= mag;
156     }
157
158 #define M(row,col)  m[col*4+row]
159     M(0,0) = x[0];  M(0,1) = x[1];  M(0,2) = x[2];  M(0,3) = 0.0;
160     M(1,0) = y[0];  M(1,1) = y[1];  M(1,2) = y[2];  M(1,3) = 0.0;
161     M(2,0) = z[0];  M(2,1) = z[1];  M(2,2) = z[2];  M(2,3) = 0.0;
162     // the following is part of the original gluLookAt(), but we are
163     // commenting it out because we know we are going to be doing a
164     // translation below which will set these values anyways
165     // M(3,0) = 0.0;   M(3,1) = 0.0;   M(3,2) = 0.0;   M(3,3) = 1.0;
166 #undef M
167
168     // Translate Eye to Origin
169     // replaces: glTranslated( -eyex, -eyey, -eyez );
170
171     // this has been slightly modified from the original glTranslate()
172     // code because we know that coming into this m[12] = m[13] =
173     // m[14] = 0.0, and m[15] = 1.0;
174     m[12] = m[0] * -eyex + m[4] * -eyey + m[8]  * -eyez /* + m[12] */;
175     m[13] = m[1] * -eyex + m[5] * -eyey + m[9]  * -eyez /* + m[13] */;
176     m[14] = m[2] * -eyex + m[6] * -eyey + m[10] * -eyez /* + m[14] */;
177     m[15] = 1.0 /* m[3] * -eyex + m[7] * -eyey + m[11] * -eyez + m[15] */;
178
179     // xglMultMatrixd( m );
180     xglLoadMatrixd( m );
181 }
182
183
184 // Update the view volume, position, and orientation
185 void fgVIEW::UpdateViewParams( void ) {
186     fgFLIGHT *f;
187     fgLIGHT *l;
188
189     f = current_aircraft.flight;
190     l = &cur_light_params;
191
192     UpdateViewMath(f);
193     UpdateWorldToEye(f);
194
195     // if (!o->panel_status) {
196     // xglViewport( 0, (GLint)((winHeight) / 2 ) , 
197     // (GLint)(winWidth), (GLint)(winHeight) / 2 );
198     // Tell GL we are about to modify the projection parameters
199     // xglMatrixMode(GL_PROJECTION);
200     // xglLoadIdentity();
201     // gluPerspective(o->fov, win_ratio / 2.0, 1.0, 100000.0);
202     // } else {
203     xglViewport(0, 0 , (GLint)(winWidth), (GLint)(winHeight) );
204     // Tell GL we are about to modify the projection parameters
205     xglMatrixMode(GL_PROJECTION);
206     xglLoadIdentity();
207     if ( FG_Altitude * FEET_TO_METER - scenery.cur_elev > 10.0 ) {
208         gluPerspective(current_options.get_fov(), win_ratio, 10.0, 100000.0);
209     } else {
210         gluPerspective(current_options.get_fov(), win_ratio, 0.5, 100000.0);
211         // printf("Near ground, minimizing near clip plane\n");
212     }
213     // }
214
215     xglMatrixMode(GL_MODELVIEW);
216     xglLoadIdentity();
217     
218     // set up our view volume (default)
219     LookAt(view_pos.x, view_pos.y, view_pos.z,
220            view_pos.x + view_forward[0], 
221                view_pos.y + view_forward[1], 
222                view_pos.z + view_forward[2],
223                view_up[0], view_up[1], view_up[2]);
224
225     // look almost straight up (testing and eclipse watching)
226     /* LookAt(view_pos.x, view_pos.y, view_pos.z,
227                view_pos.x + view_up[0] + .001, 
228                view_pos.y + view_up[1] + .001, 
229                view_pos.z + view_up[2] + .001,
230                view_up[0], view_up[1], view_up[2]); */
231
232     // lock view horizontally towards sun (testing)
233     /* LookAt(view_pos.x, view_pos.y, view_pos.z,
234                view_pos.x + surface_to_sun[0], 
235                view_pos.y + surface_to_sun[1], 
236                view_pos.z + surface_to_sun[2],
237                view_up[0], view_up[1], view_up[2]); */
238
239     // lock view horizontally towards south (testing)
240     /* LookAt(view_pos.x, view_pos.y, view_pos.z,
241                view_pos.x + surface_south[0], 
242                view_pos.y + surface_south[1], 
243                view_pos.z + surface_south[2],
244                view_up[0], view_up[1], view_up[2]); */
245
246     // set the sun position
247     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
248 }
249
250
251 // Update the view parameters
252 void fgVIEW::UpdateViewMath( fgFLIGHT *f ) {
253     fgPoint3d p;
254     MAT3vec vec, forward, v0, minus_z;
255     MAT3mat R, TMP, UP, LOCAL, VIEW;
256     double ntmp;
257
258     if(update_fov == true) {
259         // printf("Updating fov\n");
260         UpdateFOV(&current_options);
261         update_fov = false;
262     }
263                 
264     scenery.center.x = scenery.next_center.x;
265     scenery.center.y = scenery.next_center.y;
266     scenery.center.z = scenery.next_center.z;
267
268     // printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x,
269     //        scenery.center.y, scenery.center.z);
270
271     // calculate the cartesion coords of the current lat/lon/0 elev
272     p.lon = FG_Longitude;
273     p.lat = FG_Lat_geocentric;
274     p.radius = FG_Sea_level_radius * FEET_TO_METER;
275
276     cur_zero_elev = fgPolarToCart3d(p);
277
278     cur_zero_elev.x -= scenery.center.x;
279     cur_zero_elev.y -= scenery.center.y;
280     cur_zero_elev.z -= scenery.center.z;
281
282     // calculate view position in current FG view coordinate system
283     // p.lon & p.lat are already defined earlier, p.radius was set to
284     // the sea level radius, so now we add in our altitude.
285     if ( FG_Altitude * FEET_TO_METER > 
286          (scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
287         p.radius += FG_Altitude * FEET_TO_METER;
288     } else {
289         p.radius += scenery.cur_elev + 0.5 * METER_TO_FEET;
290     }
291
292     abs_view_pos = fgPolarToCart3d(p);
293
294     view_pos.x = abs_view_pos.x - scenery.center.x;
295     view_pos.y = abs_view_pos.y - scenery.center.y;
296     view_pos.z = abs_view_pos.z - scenery.center.z;
297
298     fgPrintf( FG_VIEW, FG_DEBUG, "Absolute view pos = %.4f, %.4f, %.4f\n", 
299            abs_view_pos.x, abs_view_pos.y, abs_view_pos.z);
300     fgPrintf( FG_VIEW, FG_DEBUG, "Relative view pos = %.4f, %.4f, %.4f\n", 
301            view_pos.x, view_pos.y, view_pos.z);
302
303     // Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw)
304     // from FG_T_local_to_body[3][3]
305
306     // Question: Why is the LaRCsim matrix arranged so differently
307     // than the one we need???
308     LOCAL[0][0] = FG_T_local_to_body_33;
309     LOCAL[0][1] = -FG_T_local_to_body_32;
310     LOCAL[0][2] = -FG_T_local_to_body_31;
311     LOCAL[0][3] = 0.0;
312     LOCAL[1][0] = -FG_T_local_to_body_23;
313     LOCAL[1][1] = FG_T_local_to_body_22;
314     LOCAL[1][2] = FG_T_local_to_body_21;
315     LOCAL[1][3] = 0.0;
316     LOCAL[2][0] = -FG_T_local_to_body_13;
317     LOCAL[2][1] = FG_T_local_to_body_12;
318     LOCAL[2][2] = FG_T_local_to_body_11;
319     LOCAL[2][3] = 0.0;
320     LOCAL[3][0] = LOCAL[3][1] = LOCAL[3][2] = LOCAL[3][3] = 0.0;
321     LOCAL[3][3] = 1.0;
322     // printf("LaRCsim LOCAL matrix\n");
323     // MAT3print(LOCAL, stdout);
324
325 #ifdef OLD_LOCAL_TO_BODY_CODE
326         // old code to calculate LOCAL matrix calculated from Phi,
327         // Theta, and Psi (roll, pitch, yaw)
328
329         MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
330         MAT3rotate(R, vec, FG_Phi);
331         /* printf("Roll matrix\n"); */
332         /* MAT3print(R, stdout); */
333
334         MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
335         /* MAT3mult_vec(vec, vec, R); */
336         MAT3rotate(TMP, vec, FG_Theta);
337         /* printf("Pitch matrix\n"); */
338         /* MAT3print(TMP, stdout); */
339         MAT3mult(R, R, TMP);
340
341         MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
342         /* MAT3mult_vec(vec, vec, R); */
343         /* MAT3rotate(TMP, vec, FG_Psi - FG_PI_2); */
344         MAT3rotate(TMP, vec, -FG_Psi);
345         /* printf("Yaw matrix\n");
346            MAT3print(TMP, stdout); */
347         MAT3mult(LOCAL, R, TMP);
348         // printf("FG derived LOCAL matrix\n");
349         // MAT3print(LOCAL, stdout);
350 #endif // OLD_LOCAL_TO_BODY_CODE
351
352     // Derive the local UP transformation matrix based on *geodetic*
353     // coordinates
354     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
355     MAT3rotate(R, vec, FG_Longitude);     // R = rotate about Z axis
356     // printf("Longitude matrix\n");
357     // MAT3print(R, stdout);
358
359     MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
360     MAT3mult_vec(vec, vec, R);
361     MAT3rotate(TMP, vec, -FG_Latitude);  // TMP = rotate about X axis
362     // printf("Latitude matrix\n");
363     // MAT3print(TMP, stdout);
364
365     MAT3mult(UP, R, TMP);
366     // printf("Local up matrix\n");
367     // MAT3print(UP, stdout);
368
369     MAT3_SET_VEC(local_up, 1.0, 0.0, 0.0);
370     MAT3mult_vec(local_up, local_up, UP);
371
372     // printf( "Local Up = (%.4f, %.4f, %.4f)\n",
373     //         local_up[0], local_up[1], local_up[2]);
374     
375     // Alternative method to Derive local up vector based on
376     // *geodetic* coordinates
377     // alt_up = fgPolarToCart(FG_Longitude, FG_Latitude, 1.0);
378     // printf( "    Alt Up = (%.4f, %.4f, %.4f)\n", 
379     //         alt_up.x, alt_up.y, alt_up.z);
380
381     // Calculate the VIEW matrix
382     MAT3mult(VIEW, LOCAL, UP);
383     // printf("VIEW matrix\n");
384     // MAT3print(VIEW, stdout);
385
386     // generate the current up, forward, and fwrd-view vectors
387     MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
388     MAT3mult_vec(view_up, vec, VIEW);
389
390     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
391     MAT3mult_vec(forward, vec, VIEW);
392     // printf( "Forward vector is (%.2f,%.2f,%.2f)\n", forward[0], forward[1], 
393     //         forward[2]);
394
395     MAT3rotate(TMP, view_up, view_offset);
396     MAT3mult_vec(view_forward, forward, TMP);
397
398     // make a vector to the current view position
399     MAT3_SET_VEC(v0, view_pos.x, view_pos.y, view_pos.z);
400
401     // Given a vector pointing straight down (-Z), map into onto the
402     // local plane representing "horizontal".  This should give us the
403     // local direction for moving "south".
404     MAT3_SET_VEC(minus_z, 0.0, 0.0, -1.0);
405     map_vec_onto_cur_surface_plane(local_up, v0, minus_z, surface_south);
406     MAT3_NORMALIZE_VEC(surface_south, ntmp);
407     // printf( "Surface direction directly south %.2f %.2f %.2f\n",
408     //         surface_south[0], surface_south[1], surface_south[2]);
409
410     // now calculate the surface east vector
411     MAT3rotate(TMP, view_up, FG_PI_2);
412     MAT3mult_vec(surface_east, surface_south, TMP);
413     // printf( "Surface direction directly east %.2f %.2f %.2f\n",
414     //         surface_east[0], surface_east[1], surface_east[2]);
415     // printf( "Should be close to zero = %.2f\n", 
416     //         MAT3_DOT_PRODUCT(surface_south, surface_east));
417 }
418
419
420 // Update the "World to Eye" transformation matrix
421 // This is most useful for view frustum culling
422 void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) {
423     MAT3mat R_Phi, R_Theta, R_Psi, R_Lat, R_Lon, T_view;
424     MAT3mat TMP;
425     MAT3hvec vec;
426
427     // if we have a view offset use slow way for now
428     if(fabs(view_offset)>FG_EPSILON){ 
429         // Roll Matrix
430         MAT3_SET_HVEC(vec, 0.0, 0.0, -1.0, 1.0);
431         MAT3rotate(R_Phi, vec, FG_Phi);
432         // printf("Roll matrix (Phi)\n");
433         // MAT3print(R_Phi, stdout);
434
435         // Pitch Matrix
436         MAT3_SET_HVEC(vec, 1.0, 0.0, 0.0, 1.0);
437         MAT3rotate(R_Theta, vec, FG_Theta);
438         // printf("\nPitch matrix (Theta)\n");
439         // MAT3print(R_Theta, stdout);
440
441         // Yaw Matrix
442         MAT3_SET_HVEC(vec, 0.0, -1.0, 0.0, 1.0);
443         MAT3rotate(R_Psi, vec, FG_Psi + FG_PI - view_offset );
444         // printf("\nYaw matrix (Psi)\n");
445         // MAT3print(R_Psi, stdout);
446
447         // aircraft roll/pitch/yaw
448         MAT3mult(TMP, R_Phi, R_Theta);
449         MAT3mult(AIRCRAFT, TMP, R_Psi);
450
451     } else { // JUST USE LOCAL_TO_BODY  NHV 5/25/98
452         // hey this is even different then LOCAL[][] above ??
453          
454         AIRCRAFT[0][0] = -FG_T_local_to_body_22;
455         AIRCRAFT[0][1] = -FG_T_local_to_body_23;
456         AIRCRAFT[0][2] = FG_T_local_to_body_21;
457         AIRCRAFT[0][3] = 0.0;
458         AIRCRAFT[1][0] = FG_T_local_to_body_32;
459         AIRCRAFT[1][1] = FG_T_local_to_body_33;
460         AIRCRAFT[1][2] = -FG_T_local_to_body_31;
461         AIRCRAFT[1][3] = 0.0;
462         AIRCRAFT[2][0] = FG_T_local_to_body_12;
463         AIRCRAFT[2][1] = FG_T_local_to_body_13;
464         AIRCRAFT[2][2] = -FG_T_local_to_body_11;
465         AIRCRAFT[2][3] = 0.0;
466         AIRCRAFT[3][0] = AIRCRAFT[3][1] = AIRCRAFT[3][2] = AIRCRAFT[3][3] = 0.0;
467         AIRCRAFT[3][3] = 1.0;
468
469         // ??? SOMETHING LIKE THIS SHOULD WORK    NHV
470         // Rotate about LOCAL_UP  (AIRCRAFT[2][])
471         // MAT3_SET_HVEC(vec, AIRCRAFT[2][0], AIRCRAFT[2][1],
472         //                        AIRCRAFT[2][2], AIRCRAFT[2][3]);
473         // MAT3rotate(TMP, vec, FG_PI - view_offset );
474         // MAT3mult(AIRCRAFT, AIRCRAFT, TMP);
475     }
476     // printf("\naircraft roll pitch yaw\n");
477     // MAT3print(AIRCRAFT, stdout);
478
479     // View position in scenery centered coordinates
480     MAT3_SET_HVEC(vec, view_pos.x, view_pos.y, view_pos.z, 1.0);
481     MAT3translate(T_view, vec);
482     // printf("\nTranslation matrix\n");
483     // MAT3print(T_view, stdout);
484
485     // Latitude
486     MAT3_SET_HVEC(vec, 1.0, 0.0, 0.0, 1.0);
487     // R_Lat = rotate about X axis
488     MAT3rotate(R_Lat, vec, FG_Latitude);
489     // printf("\nLatitude matrix\n");
490     // MAT3print(R_Lat, stdout);
491
492     // Longitude
493     MAT3_SET_HVEC(vec, 0.0, 0.0, 1.0, 1.0);
494     // R_Lon = rotate about Z axis
495     MAT3rotate(R_Lon, vec, FG_Longitude - FG_PI_2 );
496     // printf("\nLongitude matrix\n");
497     // MAT3print(R_Lon, stdout);
498
499 #ifdef THIS_IS_OLD_CODE
500     // View position in scenery centered coordinates
501     MAT3_SET_HVEC(vec, view_pos.x, view_pos.y, view_pos.z, 1.0);
502     MAT3translate(T_view, vec);
503     // printf("\nTranslation matrix\n");
504     // MAT3print(T_view, stdout);
505
506     // aircraft roll/pitch/yaw
507     MAT3mult(TMP, R_Phi, R_Theta);
508     MAT3mult(AIRCRAFT, TMP, R_Psi);
509     // printf("\naircraft roll pitch yaw\n");
510     // MAT3print(AIRCRAFT, stdout);
511 #endif THIS_IS_OLD_CODE
512
513     // lon/lat
514     MAT3mult(WORLD, R_Lat, R_Lon);
515     // printf("\nworld\n");
516     // MAT3print(WORLD, stdout);
517
518     MAT3mult(EYE_TO_WORLD, AIRCRAFT, WORLD);
519     MAT3mult(EYE_TO_WORLD, EYE_TO_WORLD, T_view);
520     // printf("\nEye to world\n");
521     // MAT3print(EYE_TO_WORLD, stdout);
522
523     MAT3invert(WORLD_TO_EYE, EYE_TO_WORLD);
524     // printf("\nWorld to eye\n");
525     // MAT3print(WORLD_TO_EYE, stdout);
526
527     // printf( "\nview_pos = %.2f %.2f %.2f\n", 
528     //         view_pos.x, view_pos.y, view_pos.z );
529
530     // MAT3_SET_HVEC(eye, 0.0, 0.0, 0.0, 1.0);
531     // MAT3mult_vec(vec, eye, EYE_TO_WORLD);
532     // printf("\neye -> world = %.2f %.2f %.2f\n", vec[0], vec[1], vec[2]);
533
534     // MAT3_SET_HVEC(vec1, view_pos.x, view_pos.y, view_pos.z, 1.0);
535     // MAT3mult_vec(vec, vec1, WORLD_TO_EYE);
536     // printf( "\nabs_view_pos -> eye = %.2f %.2f %.2f\n", 
537     //         vec[0], vec[1], vec[2]);
538 }
539
540
541 // Destructor
542 fgVIEW::~fgVIEW( void ) {
543 }
544
545
546 // $Log$
547 // Revision 1.20  1998/09/08 15:04:35  curt
548 // Optimizations by Norman Vine.
549 //
550 // Revision 1.19  1998/08/20 20:32:34  curt
551 // Reshuffled some of the code in and around views.[ch]xx
552 //
553 // Revision 1.18  1998/07/24 21:57:02  curt
554 // Set near clip plane to 0.5 meters when close to the ground.  Also, let the view get a bit closer to the ground before hitting the hard limit.
555 //
556 // Revision 1.17  1998/07/24 21:39:12  curt
557 // Debugging output tweaks.
558 // Cast glGetString to (char *) to avoid compiler errors.
559 // Optimizations to fgGluLookAt() by Norman Vine.
560 //
561 // Revision 1.16  1998/07/13 21:01:41  curt
562 // Wrote access functions for current fgOPTIONS.
563 //
564 // Revision 1.15  1998/07/12 03:14:43  curt
565 // Added ground collision detection.
566 // Did some serious horsing around to be able to "hug" the ground properly
567 //   and still be able to take off.
568 // Set the near clip plane to 1.0 meters when less than 10 meters above the
569 //   ground.
570 // Did some serious horsing around getting the initial airplane position to be
571 //   correct based on rendered terrain elevation.
572 // Added a little cheat/hack that will prevent the view position from ever
573 //   dropping below the terrain, even when the flight model doesn't quite
574 //   put you as high as you'd like.
575 //
576 // Revision 1.14  1998/07/08 14:45:08  curt
577 // polar3d.h renamed to polar3d.hxx
578 // vector.h renamed to vector.hxx
579 // updated audio support so it waits to create audio classes (and tie up
580 //   /dev/dsp) until the mpg123 player is finished.
581 //
582 // Revision 1.13  1998/07/04 00:52:27  curt
583 // Add my own version of gluLookAt() (which is nearly identical to the
584 // Mesa/glu version.)  But, by calculating the Model View matrix our selves
585 // we can save this matrix without having to read it back in from the video
586 // card.  This hopefully allows us to save a few cpu cycles when rendering
587 // out the fragments because we can just use glLoadMatrixd() with the
588 // precalculated matrix for each tile rather than doing a push(), translate(),
589 // pop() for every fragment.
590 //
591 // Panel status defaults to off for now until it gets a bit more developed.
592 //
593 // Extract OpenGL driver info on initialization.
594 //
595 // Revision 1.12  1998/06/03 00:47:15  curt
596 // Updated to compile in audio support if OSS available.
597 // Updated for new version of Steve's audio library.
598 // STL includes don't use .h
599 // Small view optimizations.
600 //
601 // Revision 1.11  1998/05/27 02:24:05  curt
602 // View optimizations by Norman Vine.
603 //
604 // Revision 1.10  1998/05/17 16:59:03  curt
605 // First pass at view frustum culling now operational.
606 //
607 // Revision 1.9  1998/05/16 13:08:37  curt
608 // C++ - ified views.[ch]xx
609 // Shuffled some additional view parameters into the fgVIEW class.
610 // Changed tile-radius to tile-diameter because it is a much better
611 //   name.
612 // Added a WORLD_TO_EYE transformation to views.cxx.  This allows us
613 //  to transform world space to eye space for view frustum culling.
614 //
615 // Revision 1.8  1998/05/02 01:51:01  curt
616 // Updated polartocart conversion routine.
617 //
618 // Revision 1.7  1998/04/30 12:34:20  curt
619 // Added command line rendering options:
620 //   enable/disable fog/haze
621 //   specify smooth/flat shading
622 //   disable sky blending and just use a solid color
623 //   enable wireframe drawing mode
624 //
625 // Revision 1.6  1998/04/28 01:20:23  curt
626 // Type-ified fgTIME and fgVIEW.
627 // Added a command line option to disable textures.
628 //
629 // Revision 1.5  1998/04/26 05:10:04  curt
630 // "struct fgLIGHT" -> "fgLIGHT" because fgLIGHT is typedef'd.
631 //
632 // Revision 1.4  1998/04/25 22:04:53  curt
633 // Use already calculated LaRCsim values to create the roll/pitch/yaw
634 // transformation matrix (we call it LOCAL)
635 //
636 // Revision 1.3  1998/04/25 20:24:02  curt
637 // Cleaned up initialization sequence to eliminate interdependencies
638 // between sun position, lighting, and view position.  This creates a
639 // valid single pass initialization path.
640 //
641 // Revision 1.2  1998/04/24 00:49:22  curt
642 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
643 // Trying out some different option parsing code.
644 // Some code reorganization.
645 //
646 // Revision 1.1  1998/04/22 13:25:45  curt
647 // C++ - ifing the code.
648 // Starting a bit of reorganization of lighting code.
649 //
650 // Revision 1.16  1998/04/18 04:11:29  curt
651 // Moved fg_debug to it's own library, added zlib support.
652 //
653 // Revision 1.15  1998/02/20 00:16:24  curt
654 // Thursday's tweaks.
655 //
656 // Revision 1.14  1998/02/09 15:07:50  curt
657 // Minor tweaks.
658 //
659 // Revision 1.13  1998/02/07 15:29:45  curt
660 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
661 // <chotchkiss@namg.us.anritsu.com>
662 //
663 // Revision 1.12  1998/01/29 00:50:28  curt
664 // Added a view record field for absolute x, y, z position.
665 //
666 // Revision 1.11  1998/01/27 00:47:58  curt
667 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
668 // system and commandline/config file processing code.
669 //
670 // Revision 1.10  1998/01/19 19:27:09  curt
671 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
672 // This should simplify things tremendously.
673 //
674 // Revision 1.9  1998/01/13 00:23:09  curt
675 // Initial changes to support loading and management of scenery tiles.  Note,
676 // there's still a fair amount of work left to be done.
677 //
678 // Revision 1.8  1997/12/30 22:22:33  curt
679 // Further integration of event manager.
680 //
681 // Revision 1.7  1997/12/30 20:47:45  curt
682 // Integrated new event manager with subsystem initializations.
683 //
684 // Revision 1.6  1997/12/22 04:14:32  curt
685 // Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
686 //
687 // Revision 1.5  1997/12/18 04:07:02  curt
688 // Worked on properly translating and positioning the sky dome.
689 //
690 // Revision 1.4  1997/12/17 23:13:36  curt
691 // Began working on rendering a sky.
692 //
693 // Revision 1.3  1997/12/15 23:54:50  curt
694 // Add xgl wrappers for debugging.
695 // Generate terrain normals on the fly.
696 //
697 // Revision 1.2  1997/12/10 22:37:48  curt
698 // Prepended "fg" on the name of all global structures that didn't have it yet.
699 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
700 //
701 // Revision 1.1  1997/08/27 21:31:17  curt
702 // Initial revision.
703 //