]> git.mxchange.org Git - flightgear.git/blob - Scenery/tilemgr.cxx
C++ ifying ...
[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.hxx>
37
38 #include <Bucket/bucketutils.h>
39 #include <Debug/fg_debug.h>
40 #include <Include/fg_constants.h>
41 #include <Main/options.hxx>
42 #include <Main/views.hxx>
43 #include <Math/fg_geodesy.hxx>
44 #include <Math/mat3.h>
45 #include <Math/point3d.hxx>
46 #include <Math/polar3d.hxx>
47 #include <Math/vector.hxx>
48 #include <Objects/material.hxx>
49 #include <Objects/obj.hxx>
50 #include <Weather/weather.hxx>
51
52 #include "scenery.hxx"
53 #include "tile.hxx"
54 #include "tilecache.hxx"
55
56
57 // to test clipping speedup in fgTileMgrRender()
58 #if defined ( USE_FAST_FOV_CLIP )
59   // #define TEST_FOV_CLIP
60   // #define TEST_ELEV
61 #endif
62
63
64 #define FG_LOCAL_X_Y         81  // max(o->tile_diameter) ** 2
65
66 #define FG_SQUARE( X ) ( (X) * (X) )
67
68 #ifdef WIN32
69 #  define FG_MEM_COPY(to,from,n)        memcpy(to, from, n)
70 #else
71 #  define FG_MEM_COPY(to,from,n)        bcopy(from, to, n)
72 #endif
73
74 // closest (potentially viewable) tiles, centered on current tile.
75 // This is an array of pointers to cache indexes.
76 int tiles[FG_LOCAL_X_Y];
77
78
79 // Initialize the Tile Manager subsystem
80 int fgTileMgrInit( void ) {
81     fgPrintf( FG_TERRAIN, FG_INFO, "Initializing Tile Manager subsystem.\n");
82
83     // load default material library
84     material_mgr.load_lib();
85
86     return 1;
87 }
88
89
90 // load a tile
91 void fgTileMgrLoadTile( fgBUCKET *p, int *index) {
92     fgTILECACHE *c;
93
94     c = &global_tile_cache;
95
96     fgPrintf( FG_TERRAIN, FG_DEBUG, "Updating for bucket %d %d %d %d\n", 
97            p->lon, p->lat, p->x, p->y);
98     
99     // if not in cache, load tile into the next available slot
100     if ( (*index = c->exists(p)) < 0 ) {
101         *index = c->next_avail();
102         c->fill_in(*index, p);
103     }
104
105     fgPrintf( FG_TERRAIN, FG_DEBUG, "Selected cache index of %d\n", *index);
106 }
107
108
109 // given the current lon/lat, fill in the array of local chunks.  If
110 // the chunk isn't already in the cache, then read it from disk.
111 int fgTileMgrUpdate( void ) {
112     fgTILECACHE *c;
113     fgFLIGHT *f;
114     fgBUCKET p1, p2;
115     static fgBUCKET p_last = {-1000, 0, 0, 0};
116     int tile_diameter;
117     int i, j, dw, dh;
118
119     c = &global_tile_cache;
120     f = current_aircraft.flight;
121
122     tile_diameter = current_options.get_tile_diameter();
123
124     fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p1);
125     dw = tile_diameter / 2;
126     dh = tile_diameter / 2;
127
128     if ( (p1.lon == p_last.lon) && (p1.lat == p_last.lat) &&
129          (p1.x == p_last.x) && (p1.y == p_last.y) ) {
130         // same bucket as last time
131         fgPrintf( FG_TERRAIN, FG_DEBUG, "Same bucket as last time\n");
132     } else if ( p_last.lon == -1000 ) {
133         // First time through, initialize the system and load all
134         // relavant tiles
135
136         fgPrintf( FG_TERRAIN, FG_INFO, "  First time through ... ");
137         fgPrintf( FG_TERRAIN, FG_INFO, "  Updating Tile list for %d,%d %d,%d\n",
138                   p1.lon, p1.lat, p1.x, p1.y);
139         fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
140                   tile_diameter * tile_diameter);
141
142         // wipe/initialize tile cache
143         c->init();
144
145         // build the local area list and update cache
146         for ( j = 0; j < tile_diameter; j++ ) {
147             for ( i = 0; i < tile_diameter; i++ ) {
148                 fgBucketOffset(&p1, &p2, i - dw, j - dh);
149                 fgTileMgrLoadTile(&p2, &tiles[(j*tile_diameter) + i]);
150             }
151         }
152     } else {
153         // We've moved to a new bucket, we need to scroll our
154         // structures, and load in the new tiles
155
156         // CURRENTLY THIS ASSUMES WE CAN ONLY MOVE TO ADJACENT TILES.
157         // AT ULTRA HIGH SPEEDS THIS ASSUMPTION MAY NOT BE VALID IF
158         // THE AIRCRAFT CAN SKIP A TILE IN A SINGLE ITERATION.
159
160         fgPrintf( FG_TERRAIN, FG_INFO, "Updating Tile list for %d,%d %d,%d\n",
161                   p1.lon, p1.lat, p1.x, p1.y);
162
163         if ( (p1.lon > p_last.lon) ||
164              ( (p1.lon == p_last.lon) && (p1.x > p_last.x) ) ) {
165             fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
166                       tile_diameter);
167             for ( j = 0; j < tile_diameter; j++ ) {
168                 // scrolling East
169                 for ( i = 0; i < tile_diameter - 1; i++ ) {
170                     tiles[(j*tile_diameter) + i] = 
171                         tiles[(j*tile_diameter) + i + 1];
172                 }
173                 // load in new column
174                 fgBucketOffset(&p_last, &p2, dw + 1, j - dh);
175                 fgTileMgrLoadTile(&p2, &tiles[(j*tile_diameter) + 
176                                              tile_diameter - 1]);
177             }
178         } else if ( (p1.lon < p_last.lon) ||
179                     ( (p1.lon == p_last.lon) && (p1.x < p_last.x) ) ) {
180             fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
181                       tile_diameter);
182             for ( j = 0; j < tile_diameter; j++ ) {
183                 // scrolling West
184                 for ( i = tile_diameter - 1; i > 0; i-- ) {
185                     tiles[(j*tile_diameter) + i] = 
186                         tiles[(j*tile_diameter) + i - 1];
187                 }
188                 // load in new column
189                 fgBucketOffset(&p_last, &p2, -dw - 1, j - dh);
190                 fgTileMgrLoadTile(&p2, &tiles[(j*tile_diameter) + 0]);
191             }
192         }
193
194         if ( (p1.lat > p_last.lat) ||
195              ( (p1.lat == p_last.lat) && (p1.y > p_last.y) ) ) {
196             fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
197                       tile_diameter);
198             for ( i = 0; i < tile_diameter; i++ ) {
199                 // scrolling North
200                 for ( j = 0; j < tile_diameter - 1; j++ ) {
201                     tiles[(j * tile_diameter) + i] =
202                         tiles[((j+1) * tile_diameter) + i];
203                 }
204                 // load in new column
205                 fgBucketOffset(&p_last, &p2, i - dw, dh + 1);
206                 fgTileMgrLoadTile(&p2, &tiles[((tile_diameter-1) * 
207                                                tile_diameter) + i]);
208             }
209         } else if ( (p1.lat < p_last.lat) ||
210                     ( (p1.lat == p_last.lat) && (p1.y < p_last.y) ) ) {
211             fgPrintf( FG_TERRAIN, FG_INFO, "  Loading %d tiles\n", 
212                       tile_diameter);
213             for ( i = 0; i < tile_diameter; i++ ) {
214                 // scrolling South
215                 for ( j = tile_diameter - 1; j > 0; j-- ) {
216                     tiles[(j * tile_diameter) + i] = 
217                         tiles[((j-1) * tile_diameter) + i];
218                 }
219                 // load in new column
220                 fgBucketOffset(&p_last, &p2, i - dw, -dh - 1);
221                 fgTileMgrLoadTile(&p2, &tiles[0 + i]);
222             }
223         }
224     }
225     p_last.lon = p1.lon;
226     p_last.lat = p1.lat;
227     p_last.x = p1.x;
228     p_last.y = p1.y;
229     return 1;
230 }
231
232
233 // Calculate shortest distance from point to line
234 static double point_line_dist_squared( const Point3D& tc, const Point3D& vp, 
235                                        MAT3vec d )
236 {
237     MAT3vec p, p0;
238     double dist;
239
240     p[0] = tc.x(); p[1] = tc.y(); p[2] = tc.z();
241     p0[0] = vp.x(); p0[1] = vp.y(); p0[2] = vp.z();
242
243     dist = fgPointLineSquared(p, p0, d);
244
245     // printf("dist = %.2f\n", dist);
246
247     return(dist);
248 }
249
250
251 // Calculate if point/radius is inside view frustum
252 static int viewable( const Point3D& cp, double radius ) {
253     int viewable = 1; // start by assuming it's viewable
254     double x1, y1;
255
256 /********************************/
257 #if defined( USE_FAST_FOV_CLIP ) // views.hxx
258 /********************************/
259         
260     MAT3vec eye;        
261     double *mat;
262     double x, y, z;
263
264     x = cp.x();
265     y = cp.y();
266     z = cp.z();
267         
268     mat = (double *)(current_view.WORLD_TO_EYE);
269         
270     eye[2] =  x*mat[2] + y*mat[6] + z*mat[10] + mat[14];
271         
272     // Check near and far clip plane
273     if( ( eye[2] > radius ) ||
274         ( eye[2] + radius + current_weather.visibility < 0) )
275     {
276         return(0);
277     }
278         
279     eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * current_view.slope_x;
280
281     // check right and left clip plane (from eye perspective)
282     x1 = radius * current_view.fov_x_clip;
283     if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) )
284     {
285         return(0);
286     }
287         
288     eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) * current_view.slope_y;
289
290     // check bottom and top clip plane (from eye perspective)
291     y1 = radius * current_view.fov_y_clip;
292     if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) )
293     {
294         return(0);
295     }
296
297 /********************************/      
298 #else // DO NOT USE_FAST_FOV_CLIP
299 /********************************/      
300
301     fgVIEW *v;
302     MAT3hvec world, eye;
303     double x0, slope;
304
305     v = &current_view;
306
307     MAT3_SET_HVEC(world, cp->x, cp->y, cp->z, 1.0);
308     // MAT3mult_vec(eye, world, v->WORLD_TO_EYE);
309     // printf( "\nworld -> eye = %.2f %.2f %.2f  radius = %.2f\n", 
310     //         eye[0], eye[1], eye[2], radius);
311
312     // Use lazy evaluation for calculating eye hvec.
313 #define vec world
314 #define mat v->WORLD_TO_EYE
315     eye[2] = vec[0]*mat[0][2]+vec[1]*mat[1][2]+vec[2]*mat[2][2]+mat[3][2];
316
317     // Check near clip plane
318     if ( eye[2] > radius ) {
319         return(0);
320     }
321
322     // Check far clip plane
323     if ( eye[2] + radius < -current_weather.visibility ) {
324         return(0);
325     }
326
327     // check right clip plane (from eye perspective)
328     // y = m * (x - x0) = equation of a line intercepting X axis at x0
329     x1 = v->cos_fov_x * radius;
330     y1 = v->sin_fov_x * radius;
331     slope = v->slope_x;
332     eye[0] = vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0];
333
334     if ( eye[2] > ((slope * (eye[0] - x1)) + y1) ) {
335         return( false );
336     }
337
338     // check left clip plane (from eye perspective)
339     if ( eye[2] > -((slope * (eye[0] + x1)) - y1) ) {
340         return( false );
341     }
342
343     // check bottom clip plane (from eye perspective)
344     x1 = -(v->cos_fov_y) * radius;
345     y1 = v->sin_fov_y * radius;
346     slope = v->slope_y;
347     eye[1] = vec[0]*mat[0][1]+vec[1]*mat[1][1]+vec[2]*mat[2][1]+mat[3][1];
348 #undef vec
349 #undef mat
350
351     if ( eye[2] > ((slope * (eye[1] - x1)) + y1) ) {
352         return( false );
353     }
354
355     // check top clip plane (from eye perspective)
356     if ( eye[2] > -((slope * (eye[1] + x1)) - y1) ) {
357         return( false );
358     }
359
360 #endif // defined( USE_FAST_FOV_CLIP )
361         
362     return(viewable);
363 }
364
365
366 // NEW 
367
368 // inrange() IS THIS POINT WITHIN POSSIBLE VIEWING RANGE ?
369 //      calculate distance from vertical tangent line at
370 //      current position to center of object.
371 //      this is equivalent to
372 //      dist = point_line_dist_squared( &(t->center), &(v->abs_view_pos), 
373 //                                      v->local_up );
374 //      if ( dist < FG_SQUARE(t->bounding_radius) ) {
375 //
376 // the compiler should inline this for us
377
378 static int
379 inrange( const double radius, const Point3D& center, const Point3D& vp,
380          const MAT3vec up)
381 {
382     MAT3vec u, u1, v;
383     //  double tmp;
384         
385     // u = p - p0
386     u[0] = center.x() - vp.x();
387     u[1] = center.y() - vp.y();
388     u[2] = center.z() - vp.z();
389         
390     // calculate the projection, u1, of u along d.
391     // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
392         
393     MAT3_SCALE_VEC(u1, up,
394                    (MAT3_DOT_PRODUCT(u, up) / MAT3_DOT_PRODUCT(up, up)) );
395     
396     // v = u - u1 = vector from closest point on line, p1, to the
397     // original point, p.
398     MAT3_SUB_VEC(v, u, u1);
399         
400     return( FG_SQUARE(radius) >= MAT3_DOT_PRODUCT(v, v));
401 }
402
403
404 // Determine scenery altitude.  Normally this just happens when we
405 // render the scene, but we'd also like to be able to do this
406 // explicitely.  lat & lon are in radians.  abs_view_pos in meters.
407 // Returns result in meters.
408 double fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ) {
409     fgTILECACHE *c;
410     fgTILE *t;
411     // fgVIEW *v;
412     fgFRAGMENT *frag_ptr;
413     fgBUCKET p;
414     Point3D earth_center, result;
415     Point3D pp;
416     MAT3vec local_up;
417     list < fgFRAGMENT > :: iterator current;
418     list < fgFRAGMENT > :: iterator last;
419     double dist, lat_geod, alt, sea_level_r;
420     // double x, y, z;
421     int index;
422
423     c = &global_tile_cache;
424     // v = &current_view;
425
426     local_up[0] = abs_view_pos.x();
427     local_up[1] = abs_view_pos.y();
428     local_up[2] = abs_view_pos.z();
429
430     // Find current translation offset
431     fgBucketFind(lon * RAD_TO_DEG, lat * RAD_TO_DEG, &p);
432     index = c->exists(&p);
433     t = c->get_tile(index);
434
435     scenery.next_center = t->center;
436     
437     earth_center.setvals(0.0, 0.0, 0.0);
438
439     fgPrintf( FG_TERRAIN, FG_DEBUG, 
440               "Pos = (%.2f, %.2f) Current bucket = %d %d %d %d  Index = %ld\n", 
441               lon * RAD_TO_DEG, lat * RAD_TO_DEG,
442               p.lon, p.lat, p.x, p.y, fgBucketGenIndex(&p) );
443
444     // calculate tile offset
445     // x = (t->offset.x = t->center.x - scenery.center.x);
446     // y = (t->offset.y = t->center.y - scenery.center.y);
447     // z = (t->offset.z = t->center.z - scenery.center.z);
448     
449     // calc current terrain elevation calculate distance from
450     // vertical tangent line at current position to center of
451     // tile.
452         
453     /* printf("distance squared = %.2f, bounding radius = %.2f\n", 
454        point_line_dist_squared(&(t->offset), &(v->view_pos), 
455        v->local_up), t->bounding_radius); */
456
457     dist = point_line_dist_squared( t->center, abs_view_pos, local_up );
458     if ( dist < FG_SQUARE(t->bounding_radius) ) {
459
460         // traverse fragment list for tile
461         current = t->fragment_list.begin();
462         last = t->fragment_list.end();
463
464         for ( ; current != last; ++current ) {
465             frag_ptr = &(*current);
466             /* printf("distance squared = %.2f, bounding radius = %.2f\n", 
467                point_line_dist_squared( &(frag_ptr->center), 
468                &abs_view_pos), local_up),
469                frag_ptr->bounding_radius); */
470
471             dist = point_line_dist_squared( frag_ptr->center,
472                                             abs_view_pos,
473                                             local_up);
474             if ( dist <= FG_SQUARE(frag_ptr->bounding_radius) ) {
475                 if ( frag_ptr->intersect( abs_view_pos, 
476                                           earth_center, 0, result ) ) {
477                     // compute geocentric coordinates of tile center
478                     pp = fgCartToPolar3d(result);
479                     // convert to geodetic coordinates
480                     fgGeocToGeod(pp.lat(), pp.radius(), &lat_geod, 
481                                  &alt, &sea_level_r);
482                     // printf("alt = %.2f\n", alt);
483                     // exit since we found an intersection
484                     return(alt);
485                 }
486             }
487         }
488     }
489
490     printf("no terrain intersection found\n");
491     return(0);
492 }
493
494
495 // NEW for legibility
496
497 // update this tile's geometry for current view
498 // The Compiler should inline this
499 static void
500 update_tile_geometry( fgTILE *t, GLdouble *MODEL_VIEW)
501 {
502     GLdouble *m;
503     double x, y, z;
504         
505     // calculate tile offset
506     t->offset = t->center - scenery.center;
507
508     x = t->offset.x();
509     y = t->offset.y();
510     z = t->offset.z();
511         
512     m = t->model_view;
513         
514     // Calculate the model_view transformation matrix for this tile
515     FG_MEM_COPY( m, MODEL_VIEW, 16*sizeof(GLdouble) );
516     
517     // This is equivalent to doing a glTranslatef(x, y, z);
518     m[12] += (m[0]*x + m[4]*y + m[8] *z);
519     m[13] += (m[1]*x + m[5]*y + m[9] *z);
520     m[14] += (m[2]*x + m[6]*y + m[10]*z);
521     // m[15] += (m[3]*x + m[7]*y + m[11]*z);
522     // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
523     // so m[15] is unchanged
524 }
525
526
527 // Render the local tiles
528 void fgTileMgrRender( void ) {
529     fgFLIGHT *f;
530     fgTILECACHE *c;
531     fgTILE *t;
532     fgVIEW *v;
533     Point3D frag_offset;
534     fgFRAGMENT *frag_ptr;
535     fgMATERIAL *mtl_ptr;
536     list < fgFRAGMENT > :: iterator current;
537     list < fgFRAGMENT > :: iterator last;
538     int i;
539     int tile_diameter;
540     int index;
541     int culled = 0;
542     int drawn = 0;
543
544     c = &global_tile_cache;
545     f = current_aircraft.flight;
546     v = &current_view;
547
548     tile_diameter = current_options.get_tile_diameter();
549
550     scenery.cur_elev = fgTileMgrCurElev( FG_Longitude, FG_Latitude, 
551                                          v->abs_view_pos );
552  
553     // initialize the transient per-material fragment lists
554     material_mgr.init_transient_material_lists();
555    
556     // Pass 1
557     // traverse the potentially viewable tile list
558     for ( i = 0; i < (tile_diameter * tile_diameter); i++ ) {
559         index = tiles[i];
560         // fgPrintf( FG_TERRAIN, FG_DEBUG, "Index = %d\n", index);
561         t = c->get_tile(index);
562
563         // calculate tile offset
564         t->SetOffset( scenery.center );
565
566         // Course (tile based) culling
567         if ( viewable(t->offset, t->bounding_radius) ) {
568             // at least a portion of this tile could be viewable
569             
570             // Calculate the model_view transformation matrix for this tile
571             // This is equivalent to doing a glTranslatef(x, y, z);
572             t->UpdateViewMatrix( v->MODEL_VIEW );
573
574             // xglPushMatrix();
575             // xglTranslatef(t->offset.x, t->offset.y, t->offset.z);
576
577             // traverse fragment list for tile
578             current = t->fragment_list.begin();
579             last = t->fragment_list.end();
580
581             for ( ; current != last; ++current ) {
582                 frag_ptr = &(*current);
583                 
584                 if ( frag_ptr->display_list >= 0 ) {
585                     // Fine (fragment based) culling
586                     frag_offset = frag_ptr->center - scenery.center;
587
588                     if ( viewable(frag_offset, frag_ptr->bounding_radius*2) ) {
589                         // add to transient per-material property fragment list
590                         // frag_ptr->tile_offset.x = t->offset.x;
591                         // frag_ptr->tile_offset.y = t->offset.y;
592                         // frag_ptr->tile_offset.z = t->offset.z;
593
594                         mtl_ptr = frag_ptr->material_ptr;
595                         // printf(" lookup = %s\n", mtl_ptr->texture_name);
596                         if ( ! mtl_ptr->append_sort_list( frag_ptr ) ) {
597                             fgPrintf( FG_TERRAIN, FG_ALERT,
598                                       "Overran material sorting array\n" );
599                         }
600
601                         // xglCallList(frag_ptr->display_list);
602                         drawn++;
603                     } else {
604                         // printf("Culled a fragment %.2f %.2f %.2f %.2f\n",
605                         //        frag_ptr->center.x, frag_ptr->center.y,
606                         //        frag_ptr->center.z, frag_ptr->bounding_radius);
607                         culled++;
608                     }
609                 }
610             }
611
612             // xglPopMatrix();
613         } else {
614             culled += t->fragment_list.size();
615         }
616     }
617
618     if ( (drawn + culled) > 0 ) {
619         v->vfc_ratio = (double)culled / (double)(drawn + culled);
620     } else {
621         v->vfc_ratio = 0.0;
622     }
623     // printf("drawn = %d  culled = %d  saved = %.2f\n", drawn, culled, 
624     //        v->vfc_ratio);
625
626     // Pass 2
627     // traverse the transient per-material fragment lists and render
628     // out all fragments for each material property.
629     xglPushMatrix();
630     material_mgr.render_fragments();
631     xglPopMatrix();
632 }
633
634
635 // $Log$
636 // Revision 1.40  1998/10/17 01:34:28  curt
637 // C++ ifying ...
638 //
639 // Revision 1.39  1998/10/16 00:55:50  curt
640 // Converted to Point3D class.
641 //
642 // Revision 1.38  1998/09/17 18:36:18  curt
643 // Tweaks and optimizations by Norman Vine.
644 //
645 // Revision 1.37  1998/09/15 01:36:45  curt
646 // cleaned up my fragment.num_faces hack :-) to use the STL (no need in
647 // duplicating work.)
648 // Tweaked fgTileMgrRender() do not calc tile matrix unless necessary.
649 // removed some unneeded stuff from fgTileMgrCurElev()
650 //
651 // Revision 1.36  1998/09/14 12:45:26  curt
652 // minor tweaks.
653 //
654 // Revision 1.35  1998/09/10 19:07:16  curt
655 // /Simulator/Objects/fragment.hxx
656 //   Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
657 //
658 // ./Simulator/Objects/material.cxx
659 // ./Simulator/Objects/material.hxx
660 //   Made fgMATERIAL and fgMATERIAL_MGR bona fide classes with private
661 //   data members - that should keep the rabble happy :)
662 //
663 // ./Simulator/Scenery/tilemgr.cxx
664 //   In viewable() delay evaluation of eye[0] and eye[1] in until they're
665 //   actually needed.
666 //   Change to fgTileMgrRender() to call fgMATERIAL_MGR::render_fragments()
667 //   method.
668 //
669 // ./Include/fg_stl_config.h
670 // ./Include/auto_ptr.hxx
671 //   Added support for g++ 2.7.
672 //   Further changes to other files are forthcoming.
673 //
674 // Brief summary of changes required for g++ 2.7.
675 //   operator->() not supported by iterators: use (*i).x instead of i->x
676 //   default template arguments not supported,
677 //   <functional> doesn't have mem_fun_ref() needed by callbacks.
678 //   some std include files have different names.
679 //   template member functions not supported.
680 //
681 // Revision 1.34  1998/09/09 20:58:09  curt
682 // Tweaks to loop constructs with STL usage.
683 //
684 // Revision 1.33  1998/09/08 15:05:10  curt
685 // Optimization by Norman Vine.
686 //
687 // Revision 1.32  1998/08/25 16:52:44  curt
688 // material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
689 //   ../Objects
690 //
691 // Revision 1.31  1998/08/24 20:11:40  curt
692 // Tweaks ...
693 //
694 // Revision 1.30  1998/08/22  14:49:59  curt
695 // Attempting to iron out seg faults and crashes.
696 // Did some shuffling to fix a initialization order problem between view
697 // position, scenery elevation.
698 //
699 // Revision 1.29  1998/08/20 15:12:06  curt
700 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
701 // the need for "void" pointers and casts.
702 // Quick hack to count the number of scenery polygons that are being drawn.
703 //
704 // Revision 1.28  1998/08/12 21:13:06  curt
705 // material.cxx: don't load textures if they are disabled
706 // obj.cxx: optimizations from Norman Vine
707 // tile.cxx: minor tweaks
708 // tile.hxx: addition of num_faces
709 // tilemgr.cxx: minor tweaks
710 //
711 // Revision 1.27  1998/07/24 21:42:09  curt
712 // material.cxx: whups, double method declaration with no definition.
713 // obj.cxx: tweaks to avoid errors in SGI's CC.
714 // tile.cxx: optimizations by Norman Vine.
715 // tilemgr.cxx: optimizations by Norman Vine.
716 //
717 // Revision 1.26  1998/07/20 12:51:26  curt
718 // Added far clip plane to fragment clipping calculations and tie this to
719 // weather->visibility.  This way you can increase framerates by increasing
720 // for and lowering visibility.
721 //
722 // Revision 1.25  1998/07/13 21:02:01  curt
723 // Wrote access functions for current fgOPTIONS.
724 //
725 // Revision 1.24  1998/07/12 03:18:29  curt
726 // Added ground collision detection.  This involved:
727 // - saving the entire vertex list for each tile with the tile records.
728 // - saving the face list for each fragment with the fragment records.
729 // - code to intersect the current vertical line with the proper face in
730 //   an efficient manner as possible.
731 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
732 //
733 // Revision 1.23  1998/07/08 14:47:23  curt
734 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
735 // polare3d.h renamed to polar3d.hxx
736 // fg{Cartesian,Polar}Point3d consolodated.
737 // Added some initial support for calculating local current ground elevation.
738 //
739 // Revision 1.22  1998/07/04 00:54:31  curt
740 // Added automatic mipmap generation.
741 //
742 // When rendering fragments, use saved model view matrix from associated tile
743 // rather than recalculating it with push() translate() pop().
744 //
745 // Revision 1.21  1998/06/27 16:54:59  curt
746 // Check for GL_VERSION_1_1 or GL_EXT_texture_object to decide whether to use
747 //   "EXT" versions of texture management routines.
748 //
749 // Revision 1.20  1998/06/17 21:36:42  curt
750 // Load and manage multiple textures defined in the Materials library.
751 // Boost max material fagments for each material property to 800.
752 // Multiple texture support when rendering.
753 //
754 // Revision 1.19  1998/06/08 17:57:54  curt
755 // Working first pass at material proporty sorting.
756 //
757 // Revision 1.18  1998/06/06 01:09:32  curt
758 // I goofed on the log message in the last commit ... now fixed.
759 //
760 // Revision 1.17  1998/06/06 01:07:18  curt
761 // Increased per material fragment list size from 100 to 400.
762 // Now correctly draw viewable fragments in per material order.
763 //
764 // Revision 1.16  1998/06/05 22:39:55  curt
765 // Working on sorting by, and rendering by material properties.
766 //
767 // Revision 1.15  1998/06/03 00:47:51  curt
768 // No .h for STL includes.
769 // Minor view culling optimizations.
770 //
771 // Revision 1.14  1998/06/01 17:56:20  curt
772 // Incremental additions to material.cxx (not fully functional)
773 // Tweaked vfc_ratio math to avoid divide by zero.
774 //
775 // Revision 1.13  1998/05/24 02:49:10  curt
776 // Implimented fragment level view frustum culling.
777 //
778 // Revision 1.12  1998/05/23 14:09:23  curt
779 // Added tile.cxx and tile.hxx.
780 // Working on rewriting the tile management system so a tile is just a list
781 // fragments, and the fragment record contains the display list for that fragment.
782 //
783 // Revision 1.11  1998/05/20 20:53:55  curt
784 // Moved global ref point and radius (bounding sphere info, and offset) to
785 // data file rather than calculating it on the fly.
786 // Fixed polygon winding problem in scenery generation stage rather than
787 // compensating for it on the fly.
788 // Made a fgTILECACHE class.
789 //
790 // Revision 1.10  1998/05/17 16:59:34  curt
791 // Frist pass at view frustum culling now operational.
792 //
793 // Revision 1.9  1998/05/16 13:09:58  curt
794 // Beginning to add support for view frustum culling.
795 // Added some temporary code to calculate bouding radius, until the
796 //   scenery generation tools and scenery can be updated.
797 //
798 // Revision 1.8  1998/05/07 23:15:21  curt
799 // Fixed a glTexImage2D() usage bug where width and height were mis-swapped.
800 // Added support for --tile-radius=n option.
801 //
802 // Revision 1.7  1998/05/06 03:16:42  curt
803 // Added an option to control square tile radius.
804 //
805 // Revision 1.6  1998/05/02 01:52:18  curt
806 // Playing around with texture coordinates.
807 //
808 // Revision 1.5  1998/04/30 12:35:32  curt
809 // Added a command line rendering option specify smooth/flat shading.
810 //
811 // Revision 1.4  1998/04/27 03:30:14  curt
812 // Minor transformation adjustments to try to keep scenery tiles closer to
813 // (0, 0, 0)  GLfloats run out of precision at the distances we need to model
814 // the earth, but we can do a bunch of pre-transformations using double math
815 // and then cast to GLfloat once everything is close in where we have less
816 // precision problems.
817 //
818 // Revision 1.3  1998/04/25 22:06:32  curt
819 // Edited cvs log messages in source files ... bad bad bad!
820 //
821 // Revision 1.2  1998/04/24 00:51:09  curt
822 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
823 // Tweaked the scenery file extentions to be "file.obj" (uncompressed)
824 // or "file.obz" (compressed.)
825 //
826 // Revision 1.1  1998/04/22 13:22:48  curt
827 // C++ - ifing the code a bit.
828 //
829 // Revision 1.25  1998/04/18 04:14:07  curt
830 // Moved fg_debug.c to it's own library.
831 //
832 // Revision 1.24  1998/04/14 02:23:18  curt
833 // Code reorganizations.  Added a Lib/ directory for more general libraries.
834 //
835 // Revision 1.23  1998/04/08 23:30:08  curt
836 // Adopted Gnu automake/autoconf system.
837 //
838 // Revision 1.22  1998/04/03 22:11:38  curt
839 // Converting to Gnu autoconf system.
840 //
841 // Revision 1.21  1998/03/23 21:23:05  curt
842 // Debugging output tweaks.
843 //
844 // Revision 1.20  1998/03/14 00:30:51  curt
845 // Beginning initial terrain texturing experiments.
846 //
847 // Revision 1.19  1998/02/20 00:16:25  curt
848 // Thursday's tweaks.
849 //
850 // Revision 1.18  1998/02/19 13:05:54  curt
851 // Incorporated some HUD tweaks from Michelle America.
852 // Tweaked the sky's sunset/rise colors.
853 // Other misc. tweaks.
854 //
855 // Revision 1.17  1998/02/16 13:39:46  curt
856 // Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
857 // tiles to occasionally be missing.
858 //
859 // Revision 1.16  1998/02/12 21:59:53  curt
860 // Incorporated code changes contributed by Charlie Hotchkiss
861 // <chotchkiss@namg.us.anritsu.com>
862 //
863 // Revision 1.14  1998/02/09 21:30:19  curt
864 // Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
865 //
866 // Revision 1.13  1998/02/07 15:29:46  curt
867 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
868 // <chotchkiss@namg.us.anritsu.com>
869 //
870 // Revision 1.12  1998/02/01 03:39:55  curt
871 // Minor tweaks.
872 //
873 // Revision 1.11  1998/01/31 00:43:27  curt
874 // Added MetroWorks patches from Carmen Volpe.
875 //
876 // Revision 1.10  1998/01/29 00:51:40  curt
877 // First pass at tile cache, dynamic tile loading and tile unloading now works.
878 //
879 // Revision 1.9  1998/01/27 03:26:44  curt
880 // Playing with new fgPrintf command.
881 //
882 // Revision 1.8  1998/01/27 00:48:04  curt
883 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
884 // system and commandline/config file processing code.
885 //
886 // Revision 1.7  1998/01/26 15:55:25  curt
887 // Progressing on building dynamic scenery system.
888 //
889 // Revision 1.6  1998/01/24 00:03:30  curt
890 // Initial revision.
891 //
892 // Revision 1.5  1998/01/19 19:27:18  curt
893 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
894 // This should simplify things tremendously.
895 //
896 // Revision 1.4  1998/01/19 18:40:38  curt
897 // Tons of little changes to clean up the code and to remove fatal errors
898 // when building with the c++ compiler.
899 //
900 // Revision 1.3  1998/01/13 00:23:11  curt
901 // Initial changes to support loading and management of scenery tiles.  Note,
902 // there's still a fair amount of work left to be done.
903 //
904 // Revision 1.2  1998/01/08 02:22:27  curt
905 // Continue working on basic features.
906 //
907 // Revision 1.1  1998/01/07 23:50:51  curt
908 // "area" renamed to "tile"
909 //
910 // Revision 1.2  1998/01/07 03:29:29  curt
911 // Given an arbitrary lat/lon, we can now:
912 //   generate a unique index for the chunk containing the lat/lon
913 //   generate a path name to the chunk file
914 //   build a list of the indexes of all the nearby areas.
915 //
916 // Revision 1.1  1998/01/07 02:05:48  curt
917 // Initial revision.