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