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