]> git.mxchange.org Git - flightgear.git/blob - Scenery/tilemgr.cxx
Wrote access functions for current fgOPTIONS.
[flightgear.git] / Scenery / tilemgr.cxx
1 // tilemgr.cxx -- routines to handle dynamic management of scenery tiles
2 //
3 // Written by Curtis Olson, started January 1998.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #ifdef HAVE_WINDOWS_H
30 #  include <windows.h>
31 #endif
32
33 #include <GL/glut.h>
34 #include <XGL/xgl.h>
35
36 #include <Aircraft/aircraft.h>
37
38 #include <Bucket/bucketutils.h>
39 #include <Debug/fg_debug.h>
40 #include <Include/fg_constants.h>
41 #include <Include/fg_types.h>
42 #include <Main/options.hxx>
43 #include <Main/views.hxx>
44 #include <Math/fg_geodesy.h>
45 #include <Math/mat3.h>
46 #include <Math/polar3d.hxx>
47 #include <Math/vector.hxx>
48
49 #include "material.hxx"
50 #include "obj.hxx"
51 #include "scenery.hxx"
52 #include "tilecache.hxx"
53
54
55 #define FG_LOCAL_X_Y         81  // max(o->tile_diameter) ** 2
56
57
58 // closest (potentially viewable) tiles, centered on current tile.
59 // This is an array of pointers to cache indexes.
60 int tiles[FG_LOCAL_X_Y];
61
62
63 // Initialize the Tile Manager subsystem
64 int fgTileMgrInit( void ) {
65     fgPrintf( FG_TERRAIN, FG_INFO, "Initializing Tile Manager subsystem.\n");
66
67     // load default material library
68     material_mgr.load_lib();
69
70     return 1;
71 }
72
73
74 // load a tile
75 void fgTileMgrLoadTile( fgBUCKET *p, int *index) {
76     fgTILECACHE *c;
77
78     c = &global_tile_cache;
79
80     fgPrintf( FG_TERRAIN, FG_DEBUG, "Updating for bucket %d %d %d %d\n", 
81            p->lon, p->lat, p->x, p->y);
82     
83     // if not in cache, load tile into the next available slot
84     if ( (*index = c->Exists(p)) < 0 ) {
85         *index = c->NextAvail();
86         c->EntryFillIn(*index, p);
87     }
88
89     fgPrintf( FG_TERRAIN, FG_DEBUG, "Selected cache index of %d\n", *index);
90 }
91
92
93 // given the current lon/lat, fill in the array of local chunks.  If
94 // the chunk isn't already in the cache, then read it from disk.
95 int fgTileMgrUpdate( void ) {
96     fgTILECACHE *c;
97     fgFLIGHT *f;
98     fgBUCKET p1, p2;
99     static fgBUCKET p_last = {-1000, 0, 0, 0};
100     int tile_diameter;
101     int i, j, dw, dh;
102
103     c = &global_tile_cache;
104     f = current_aircraft.flight;
105
106     tile_diameter = current_options.get_tile_diameter();
107
108     fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p1);
109     dw = tile_diameter / 2;
110     dh = tile_diameter / 2;
111
112     if ( (p1.lon == p_last.lon) && (p1.lat == p_last.lat) &&
113          (p1.x == p_last.x) && (p1.y == p_last.y) ) {
114         // same bucket as last time
115         fgPrintf( FG_TERRAIN, FG_DEBUG, "Same bucket as last time\n");
116     } else if ( p_last.lon == -1000 ) {
117         // First time through, initialize the system and load all
118         // relavant tiles
119
120         fgPrintf( FG_TERRAIN, FG_INFO, "  First time through ... ");
121         fgPrintf( FG_TERRAIN, FG_INFO, "  Updating Tile list for %d,%d %d,%d\n",
122                   p1.lon, p1.lat, p1.x, p1.y);
123         fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
124                   tile_diameter * tile_diameter);
125
126         // wipe/initialize tile cache
127         c->Init();
128
129         // build the local area list and update cache
130         for ( j = 0; j < tile_diameter; j++ ) {
131             for ( i = 0; i < tile_diameter; i++ ) {
132                 fgBucketOffset(&p1, &p2, i - dw, j - dh);
133                 fgTileMgrLoadTile(&p2, &tiles[(j*tile_diameter) + i]);
134             }
135         }
136     } else {
137         // We've moved to a new bucket, we need to scroll our
138         // structures, and load in the new tiles
139
140         // CURRENTLY THIS ASSUMES WE CAN ONLY MOVE TO ADJACENT TILES.
141         // AT ULTRA HIGH SPEEDS THIS ASSUMPTION MAY NOT BE VALID IF
142         // THE AIRCRAFT CAN SKIP A TILE IN A SINGLE ITERATION.
143
144         fgPrintf( FG_TERRAIN, FG_INFO, "Updating Tile list for %d,%d %d,%d\n",
145                   p1.lon, p1.lat, p1.x, p1.y);
146
147         if ( (p1.lon > p_last.lon) ||
148              ( (p1.lon == p_last.lon) && (p1.x > p_last.x) ) ) {
149             fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
150                       tile_diameter);
151             for ( j = 0; j < tile_diameter; j++ ) {
152                 // scrolling East
153                 for ( i = 0; i < tile_diameter - 1; i++ ) {
154                     tiles[(j*tile_diameter) + i] = 
155                         tiles[(j*tile_diameter) + i + 1];
156                 }
157                 // load in new column
158                 fgBucketOffset(&p_last, &p2, dw + 1, j - dh);
159                 fgTileMgrLoadTile(&p2, &tiles[(j*tile_diameter) + 
160                                              tile_diameter - 1]);
161             }
162         } else if ( (p1.lon < p_last.lon) ||
163                     ( (p1.lon == p_last.lon) && (p1.x < p_last.x) ) ) {
164             fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
165                       tile_diameter);
166             for ( j = 0; j < tile_diameter; j++ ) {
167                 // scrolling West
168                 for ( i = tile_diameter - 1; i > 0; i-- ) {
169                     tiles[(j*tile_diameter) + i] = 
170                         tiles[(j*tile_diameter) + i - 1];
171                 }
172                 // load in new column
173                 fgBucketOffset(&p_last, &p2, -dw - 1, j - dh);
174                 fgTileMgrLoadTile(&p2, &tiles[(j*tile_diameter) + 0]);
175             }
176         }
177
178         if ( (p1.lat > p_last.lat) ||
179              ( (p1.lat == p_last.lat) && (p1.y > p_last.y) ) ) {
180             fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
181                       tile_diameter);
182             for ( i = 0; i < tile_diameter; i++ ) {
183                 // scrolling North
184                 for ( j = 0; j < tile_diameter - 1; j++ ) {
185                     tiles[(j * tile_diameter) + i] =
186                         tiles[((j+1) * tile_diameter) + i];
187                 }
188                 // load in new column
189                 fgBucketOffset(&p_last, &p2, i - dw, dh + 1);
190                 fgTileMgrLoadTile(&p2, &tiles[((tile_diameter-1) * 
191                                                tile_diameter) + i]);
192             }
193         } else if ( (p1.lat < p_last.lat) ||
194                     ( (p1.lat == p_last.lat) && (p1.y < p_last.y) ) ) {
195             fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
196                       tile_diameter);
197             for ( i = 0; i < tile_diameter; i++ ) {
198                 // scrolling South
199                 for ( j = tile_diameter - 1; j > 0; j-- ) {
200                     tiles[(j * tile_diameter) + i] = 
201                         tiles[((j-1) * tile_diameter) + i];
202                 }
203                 // load in new column
204                 fgBucketOffset(&p_last, &p2, i - dw, -dh - 1);
205                 fgTileMgrLoadTile(&p2, &tiles[0 + i]);
206             }
207         }
208     }
209     p_last.lon = p1.lon;
210     p_last.lat = p1.lat;
211     p_last.x = p1.x;
212     p_last.y = p1.y;
213     return 1;
214 }
215
216
217 // Calculate shortest distance from point to line
218 static double point_line_dist( fgPoint3d *tc, fgPoint3d *vp, MAT3vec d) {
219     MAT3vec p, p0;
220     double dist;
221
222     p[0] = tc->x; p[1] = tc->y; p[2] = tc->z;
223     p0[0] = vp->x; p0[1] = vp->y; p0[2] = vp->z;
224
225     dist = fgPointLine(p, p0, d);
226
227     // printf("dist = %.2f\n", dist);
228
229     return(dist);
230 }
231
232
233 // Calculate if point/radius is inside view frustum
234 static int viewable( fgPoint3d *cp, double radius ) {
235     fgVIEW *v;
236     MAT3hvec world, eye;
237     int viewable = 1; // start by assuming it's viewable
238     double x0, x1, y1, slope;
239
240     v = &current_view;
241
242     MAT3_SET_HVEC(world, cp->x, cp->y, cp->z, 1.0);
243     MAT3mult_vec(eye, world, v->WORLD_TO_EYE);
244     // printf( "\nworld -> eye = %.2f %.2f %.2f  radius = %.2f\n", 
245     //         eye[0], eye[1], eye[2], radius);
246
247     // Check near clip plane
248     if ( eye[2] - radius > 0.0 ) {
249         return(0);
250     }
251
252     // check right clip plane (from eye perspective)
253     // y = m * (x - x0) = equation of a line intercepting X axis at x0
254     x1 = v->cos_fov_x * radius;
255     y1 = v->sin_fov_x * radius;
256     slope = v->slope_x;
257     x0 = x1 - y1 / slope;
258
259     // printf("(r) x1 = %.2f  y1 = %.2f\n", x1, y1);
260     // printf("eye[0] = %.2f  eye[2] = %.2f\n", eye[0], eye[2]);
261     // printf("(r) x0 = %.2f  slope_x = %.2f  radius = %.2f\n", 
262     //        x0, slope, radius);
263
264     if ( eye[2] > slope * (eye[0] - x0) ) {
265         return(0);
266     }
267
268     // check left clip plane (from eye perspective)
269     x1 = -x1;
270     slope = -slope;
271     x0 = x1 - y1 / slope;
272
273     // printf("(r) x1 = %.2f  y1 = %.2f\n", x1, y1);
274     // printf("eye[0] = %.2f  eye[2] = %.2f\n", eye[0], eye[2]);
275     // printf("(r) x0 = %.2f  slope_x = %.2f  radius = %.2f\n", 
276     //        x0, slope, radius);
277
278     if ( eye[2] > slope * (eye[0] - x0) ) {
279         return(0);
280     }
281
282     // check bottom clip plane (from eye perspective)
283     x1 = -(v->cos_fov_y) * radius;
284     y1 = v->sin_fov_y * radius;
285     slope = v->slope_y;
286     x0 = x1 - y1 / slope;
287
288     // printf("(r) x1 = %.2f  y1 = %.2f\n", x1, y1);
289     // printf("eye[1] = %.2f  eye[2] = %.2f\n", eye[1], eye[2]);
290     // printf("(r) x0 = %.2f  slope_y = %.2f  radius = %.2f\n", 
291     //       x0, slope, radius);
292
293     if ( eye[2] > slope * (eye[1] - x0) ) {
294         return(0);
295     }
296
297     // check top clip plane (from eye perspective)
298     x1 = -x1;
299     slope = -slope;
300     x0 = x1 - y1 / slope;
301
302     // printf("(r) x1 = %.2f  y1 = %.2f\n", x1, y1);
303     // printf("eye[1] = %.2f  eye[2] = %.2f\n", eye[1], eye[2]);
304     // printf("(r) x0 = %.2f  slope_y = %.2f  radius = %.2f\n", 
305     //        x0, slope, radius);
306
307     if ( eye[2] > slope * (eye[1] - x0) ) {
308         return(0);
309     }
310
311     return(viewable);
312 }
313
314
315 // Render the local tiles
316 void fgTileMgrRender( void ) {
317     fgTILECACHE *c;
318     fgFLIGHT *f;
319     fgTILE *t, *last_tile_ptr;
320     fgVIEW *v;
321     fgBUCKET p;
322     fgPoint3d frag_offset, pp;
323     fgPoint3d earth_center, result;
324     fgFRAGMENT *frag_ptr;
325     fgMATERIAL *mtl_ptr;
326     GLdouble *m;
327     double dist, min_dist, lat_geod, alt, sea_level_r;
328     double x, y, z;
329     list < fgFRAGMENT > :: iterator current;
330     list < fgFRAGMENT > :: iterator last;
331     int i, j, size;
332     int tile_diameter, textures;
333     int index;
334     int culled = 0;
335     int drawn = 0;
336
337     c = &global_tile_cache;
338     f = current_aircraft.flight;
339     v = &current_view;
340
341     tile_diameter = current_options.get_tile_diameter();
342     textures = current_options.get_textures();
343
344     // Find current translation offset
345     fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p);
346     index = c->Exists(&p);
347     t = c->GetTile(index);
348
349     scenery.next_center.x = t->center.x;
350     scenery.next_center.y = t->center.y;
351     scenery.next_center.z = t->center.z;
352
353     earth_center.x = 0.0;
354     earth_center.y = 0.0;
355     earth_center.z = 0.0;
356
357     fgPrintf( FG_TERRAIN, FG_DEBUG, 
358               "Pos = (%.2f, %.2f) Current bucket = %d %d %d %d  Index = %ld\n", 
359               FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG,
360               p.lon, p.lat, p.x, p.y, fgBucketGenIndex(&p) );
361
362     // initialize the transient per-material fragment lists
363     material_mgr.init_transient_material_lists();
364     min_dist = 100000.0;
365
366     // Pass 1
367     // traverse the potentially viewable tile list
368     for ( i = 0; i < (tile_diameter * tile_diameter); i++ ) {
369         index = tiles[i];
370         // fgPrintf( FG_TERRAIN, FG_DEBUG, "Index = %d\n", index);
371         t = c->GetTile(index);
372
373         // calculate tile offset
374         x = t->offset.x = t->center.x - scenery.center.x;
375         y = t->offset.y = t->center.y - scenery.center.y;
376         z = t->offset.z = t->center.z - scenery.center.z;
377
378         m = t->model_view;
379         for ( j = 0; j < 16; j++ ) {
380             m[j] = v->MODEL_VIEW[j];
381         }
382
383         // Calculate the model_view transformation matrix for this tile
384         // This is equivalent to doing a glTranslatef(x, y, z);
385         m[12] = m[0] * x + m[4] * y + m[8]  * z + m[12];
386         m[13] = m[1] * x + m[5] * y + m[9]  * z + m[13];
387         m[14] = m[2] * x + m[6] * y + m[10] * z + m[14];
388         m[15] = m[3] * x + m[7] * y + m[11] * z + m[15];
389
390         // temp ... calc current terrain elevation
391         // calculate distance from vertical tangent line at
392         // current position to center of tile.
393         
394         /* printf("distance = %.2f, bounding radius = %.2f\n", 
395                point_line_dist(&(t->offset), &(v->view_pos), v->local_up),
396                t->bounding_radius); */
397
398         dist = point_line_dist(&(t->center), &(v->abs_view_pos), v->local_up);
399         if ( dist < t->bounding_radius ) {
400
401             // traverse fragment list for tile
402             current = t->fragment_list.begin();
403             last = t->fragment_list.end();
404
405             while ( current != last ) {
406                 frag_ptr = &(*current);
407                 current++;
408                 /* printf("distance = %.2f, bounding radius = %.2f\n", 
409                        point_line_dist( &(frag_ptr->center), 
410                                         &(v->abs_view_pos), v->local_up),
411                        frag_ptr->bounding_radius); */
412
413                 dist = point_line_dist( &(frag_ptr->center), 
414                                         &(v->abs_view_pos), v->local_up);
415                 if ( dist <= frag_ptr->bounding_radius ) {
416                     if ( frag_ptr->intersect( &(v->abs_view_pos), 
417                                               &earth_center, 0, &result ) ) {
418                         // compute geocentric coordinates of tile center
419                         pp = fgCartToPolar3d(result);
420                         // convert to geodetic coordinates
421                         fgGeocToGeod(pp.lat, pp.radius, &lat_geod, 
422                                      &alt, &sea_level_r);
423                         // printf("alt = %.2f\n", alt);
424                         scenery.cur_elev = alt;
425                         // exit this loop since we found an intersection
426                         break;
427                     }
428                 }
429             }
430         }
431
432         // Course (tile based) culling
433         if ( viewable(&(t->offset), t->bounding_radius) ) {
434             // at least a portion of this tile could be viewable
435             
436             // xglPushMatrix();
437             // xglTranslatef(t->offset.x, t->offset.y, t->offset.z);
438
439             // traverse fragment list for tile
440             current = t->fragment_list.begin();
441             last = t->fragment_list.end();
442
443             while ( current != last ) {
444                 frag_ptr = &(*current);
445                 current++;
446                 
447                 if ( frag_ptr->display_list >= 0 ) {
448                     // Fine (fragment based) culling
449                     frag_offset.x = frag_ptr->center.x - scenery.center.x;
450                     frag_offset.y = frag_ptr->center.y - scenery.center.y;
451                     frag_offset.z = frag_ptr->center.z - scenery.center.z;
452
453                     if ( viewable(&frag_offset, frag_ptr->bounding_radius*2) ) {
454                         // add to transient per-material property fragment list
455                         // frag_ptr->tile_offset.x = t->offset.x;
456                         // frag_ptr->tile_offset.y = t->offset.y;
457                         // frag_ptr->tile_offset.z = t->offset.z;
458
459                         mtl_ptr = (fgMATERIAL *)(frag_ptr->material_ptr);
460                         // printf(" lookup = %s\n", mtl_ptr->texture_name);
461                         if ( mtl_ptr->list_size < FG_MAX_MATERIAL_FRAGS ) {
462                             mtl_ptr->list[mtl_ptr->list_size] = frag_ptr;
463                             (mtl_ptr->list_size)++;
464                         } else {
465                             fgPrintf( FG_TERRAIN, FG_ALERT,
466                                       "Overran material sorting array\n" );
467                         }
468
469                         // xglCallList(frag_ptr->display_list);
470                         drawn++;
471                     } else {
472                         // printf("Culled a fragment %.2f %.2f %.2f %.2f\n",
473                         //        frag_ptr->center.x, frag_ptr->center.y,
474                         //        frag_ptr->center.z, frag_ptr->bounding_radius);
475                         culled++;
476                     }
477                 }
478             }
479
480             // xglPopMatrix();
481         } else {
482             culled += t->fragment_list.size();
483         }
484     }
485
486     if ( (drawn + culled) > 0 ) {
487         v->vfc_ratio = (double)culled / (double)(drawn + culled);
488     } else {
489         v->vfc_ratio = 0.0;
490     }
491     // printf("drawn = %d  culled = %d  saved = %.2f\n", drawn, culled, 
492     //        v->vfc_ratio);
493
494     // Pass 2
495     // traverse the transient per-material fragment lists and render
496     // out all fragments for each material property.
497     map < string, fgMATERIAL, less<string> > :: iterator mapcurrent = 
498         material_mgr.material_map.begin();
499     map < string, fgMATERIAL, less<string> > :: iterator maplast = 
500         material_mgr.material_map.end();
501
502     xglPushMatrix();
503
504     while ( mapcurrent != maplast ) {
505         // (char *)key = (*mapcurrent).first;
506         // (fgMATERIAL)value = (*mapcurrent).second;
507         mtl_ptr = &(*mapcurrent).second;
508
509         last_tile_ptr = NULL;
510
511         size = mtl_ptr->list_size;
512         if ( size > 0 ) {
513             if ( textures ) {
514 #ifdef GL_VERSION_1_1
515                 xglBindTexture(GL_TEXTURE_2D, mtl_ptr->texture_id);
516 #elif GL_EXT_texture_object
517                 xglBindTextureEXT(GL_TEXTURE_2D, mtl_ptr->texture_id);
518 #else
519 #  error port me
520 #endif
521             } else {
522                 xglMaterialfv (GL_FRONT, GL_AMBIENT, mtl_ptr->ambient);
523                 xglMaterialfv (GL_FRONT, GL_DIFFUSE, mtl_ptr->diffuse);
524             }
525
526             // printf("traversing = %s, size = %d\n", 
527             //       mtl_ptr->texture_name, size);
528             for ( i = 0; i < size; i++ ) {
529                 frag_ptr = mtl_ptr->list[i];
530                 
531                 if ( frag_ptr->tile_ptr == last_tile_ptr ) {
532                     // same tile as last time, no transform necessary
533                 } else {
534                     // new tile, new translate
535                     // xglLoadMatrixf( frag_ptr->matrix );
536                     t = (fgTILE *)(frag_ptr->tile_ptr);
537                     xglLoadMatrixd(t->model_view );
538                 }
539             
540                 // Woohoo!!!  We finally get to draw something!
541                 // printf("  display_list = %d\n", frag_ptr->display_list);
542                 xglCallList(frag_ptr->display_list);
543
544                 last_tile_ptr = (fgTILE *)(frag_ptr->tile_ptr);
545             }
546         }
547
548         *mapcurrent++;
549     }
550
551     xglPopMatrix();
552 }
553
554
555 // $Log$
556 // Revision 1.25  1998/07/13 21:02:01  curt
557 // Wrote access functions for current fgOPTIONS.
558 //
559 // Revision 1.24  1998/07/12 03:18:29  curt
560 // Added ground collision detection.  This involved:
561 // - saving the entire vertex list for each tile with the tile records.
562 // - saving the face list for each fragment with the fragment records.
563 // - code to intersect the current vertical line with the proper face in
564 //   an efficient manner as possible.
565 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
566 //
567 // Revision 1.23  1998/07/08 14:47:23  curt
568 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
569 // polare3d.h renamed to polar3d.hxx
570 // fg{Cartesian,Polar}Point3d consolodated.
571 // Added some initial support for calculating local current ground elevation.
572 //
573 // Revision 1.22  1998/07/04 00:54:31  curt
574 // Added automatic mipmap generation.
575 //
576 // When rendering fragments, use saved model view matrix from associated tile
577 // rather than recalculating it with push() translate() pop().
578 //
579 // Revision 1.21  1998/06/27 16:54:59  curt
580 // Check for GL_VERSION_1_1 or GL_EXT_texture_object to decide whether to use
581 //   "EXT" versions of texture management routines.
582 //
583 // Revision 1.20  1998/06/17 21:36:42  curt
584 // Load and manage multiple textures defined in the Materials library.
585 // Boost max material fagments for each material property to 800.
586 // Multiple texture support when rendering.
587 //
588 // Revision 1.19  1998/06/08 17:57:54  curt
589 // Working first pass at material proporty sorting.
590 //
591 // Revision 1.18  1998/06/06 01:09:32  curt
592 // I goofed on the log message in the last commit ... now fixed.
593 //
594 // Revision 1.17  1998/06/06 01:07:18  curt
595 // Increased per material fragment list size from 100 to 400.
596 // Now correctly draw viewable fragments in per material order.
597 //
598 // Revision 1.16  1998/06/05 22:39:55  curt
599 // Working on sorting by, and rendering by material properties.
600 //
601 // Revision 1.15  1998/06/03 00:47:51  curt
602 // No .h for STL includes.
603 // Minor view culling optimizations.
604 //
605 // Revision 1.14  1998/06/01 17:56:20  curt
606 // Incremental additions to material.cxx (not fully functional)
607 // Tweaked vfc_ratio math to avoid divide by zero.
608 //
609 // Revision 1.13  1998/05/24 02:49:10  curt
610 // Implimented fragment level view frustum culling.
611 //
612 // Revision 1.12  1998/05/23 14:09:23  curt
613 // Added tile.cxx and tile.hxx.
614 // Working on rewriting the tile management system so a tile is just a list
615 // fragments, and the fragment record contains the display list for that fragment.
616 //
617 // Revision 1.11  1998/05/20 20:53:55  curt
618 // Moved global ref point and radius (bounding sphere info, and offset) to
619 // data file rather than calculating it on the fly.
620 // Fixed polygon winding problem in scenery generation stage rather than
621 // compensating for it on the fly.
622 // Made a fgTILECACHE class.
623 //
624 // Revision 1.10  1998/05/17 16:59:34  curt
625 // Frist pass at view frustum culling now operational.
626 //
627 // Revision 1.9  1998/05/16 13:09:58  curt
628 // Beginning to add support for view frustum culling.
629 // Added some temporary code to calculate bouding radius, until the
630 //   scenery generation tools and scenery can be updated.
631 //
632 // Revision 1.8  1998/05/07 23:15:21  curt
633 // Fixed a glTexImage2D() usage bug where width and height were mis-swapped.
634 // Added support for --tile-radius=n option.
635 //
636 // Revision 1.7  1998/05/06 03:16:42  curt
637 // Added an option to control square tile radius.
638 //
639 // Revision 1.6  1998/05/02 01:52:18  curt
640 // Playing around with texture coordinates.
641 //
642 // Revision 1.5  1998/04/30 12:35:32  curt
643 // Added a command line rendering option specify smooth/flat shading.
644 //
645 // Revision 1.4  1998/04/27 03:30:14  curt
646 // Minor transformation adjustments to try to keep scenery tiles closer to
647 // (0, 0, 0)  GLfloats run out of precision at the distances we need to model
648 // the earth, but we can do a bunch of pre-transformations using double math
649 // and then cast to GLfloat once everything is close in where we have less
650 // precision problems.
651 //
652 // Revision 1.3  1998/04/25 22:06:32  curt
653 // Edited cvs log messages in source files ... bad bad bad!
654 //
655 // Revision 1.2  1998/04/24 00:51:09  curt
656 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
657 // Tweaked the scenery file extentions to be "file.obj" (uncompressed)
658 // or "file.obz" (compressed.)
659 //
660 // Revision 1.1  1998/04/22 13:22:48  curt
661 // C++ - ifing the code a bit.
662 //
663 // Revision 1.25  1998/04/18 04:14:07  curt
664 // Moved fg_debug.c to it's own library.
665 //
666 // Revision 1.24  1998/04/14 02:23:18  curt
667 // Code reorganizations.  Added a Lib/ directory for more general libraries.
668 //
669 // Revision 1.23  1998/04/08 23:30:08  curt
670 // Adopted Gnu automake/autoconf system.
671 //
672 // Revision 1.22  1998/04/03 22:11:38  curt
673 // Converting to Gnu autoconf system.
674 //
675 // Revision 1.21  1998/03/23 21:23:05  curt
676 // Debugging output tweaks.
677 //
678 // Revision 1.20  1998/03/14 00:30:51  curt
679 // Beginning initial terrain texturing experiments.
680 //
681 // Revision 1.19  1998/02/20 00:16:25  curt
682 // Thursday's tweaks.
683 //
684 // Revision 1.18  1998/02/19 13:05:54  curt
685 // Incorporated some HUD tweaks from Michelle America.
686 // Tweaked the sky's sunset/rise colors.
687 // Other misc. tweaks.
688 //
689 // Revision 1.17  1998/02/16 13:39:46  curt
690 // Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
691 // tiles to occasionally be missing.
692 //
693 // Revision 1.16  1998/02/12 21:59:53  curt
694 // Incorporated code changes contributed by Charlie Hotchkiss
695 // <chotchkiss@namg.us.anritsu.com>
696 //
697 // Revision 1.14  1998/02/09 21:30:19  curt
698 // Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
699 //
700 // Revision 1.13  1998/02/07 15:29:46  curt
701 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
702 // <chotchkiss@namg.us.anritsu.com>
703 //
704 // Revision 1.12  1998/02/01 03:39:55  curt
705 // Minor tweaks.
706 //
707 // Revision 1.11  1998/01/31 00:43:27  curt
708 // Added MetroWorks patches from Carmen Volpe.
709 //
710 // Revision 1.10  1998/01/29 00:51:40  curt
711 // First pass at tile cache, dynamic tile loading and tile unloading now works.
712 //
713 // Revision 1.9  1998/01/27 03:26:44  curt
714 // Playing with new fgPrintf command.
715 //
716 // Revision 1.8  1998/01/27 00:48:04  curt
717 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
718 // system and commandline/config file processing code.
719 //
720 // Revision 1.7  1998/01/26 15:55:25  curt
721 // Progressing on building dynamic scenery system.
722 //
723 // Revision 1.6  1998/01/24 00:03:30  curt
724 // Initial revision.
725 //
726 // Revision 1.5  1998/01/19 19:27:18  curt
727 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
728 // This should simplify things tremendously.
729 //
730 // Revision 1.4  1998/01/19 18:40:38  curt
731 // Tons of little changes to clean up the code and to remove fatal errors
732 // when building with the c++ compiler.
733 //
734 // Revision 1.3  1998/01/13 00:23:11  curt
735 // Initial changes to support loading and management of scenery tiles.  Note,
736 // there's still a fair amount of work left to be done.
737 //
738 // Revision 1.2  1998/01/08 02:22:27  curt
739 // Continue working on basic features.
740 //
741 // Revision 1.1  1998/01/07 23:50:51  curt
742 // "area" renamed to "tile"
743 //
744 // Revision 1.2  1998/01/07 03:29:29  curt
745 // Given an arbitrary lat/lon, we can now:
746 //   generate a unique index for the chunk containing the lat/lon
747 //   generate a path name to the chunk file
748 //   build a list of the indexes of all the nearby areas.
749 //
750 // Revision 1.1  1998/01/07 02:05:48  curt
751 // Initial revision.