1 // tilemgr.cxx -- routines to handle dynamic management of scenery tiles
3 // Written by Curtis Olson, started January 1998.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
22 // (Log is kept at end of this file)
36 #include <Aircraft/aircraft.hxx>
38 #include <Bucket/bucketutils.hxx>
39 #include <Debug/logstream.hxx>
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>
52 #include "scenery.hxx"
54 #include "tilecache.hxx"
57 // to test clipping speedup in fgTileMgrRender()
58 #if defined ( USE_FAST_FOV_CLIP )
59 // #define TEST_FOV_CLIP
64 #define FG_LOCAL_X_Y 81 // max(o->tile_diameter) ** 2
66 #define FG_SQUARE( X ) ( (X) * (X) )
69 # define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
71 # define FG_MEM_COPY(to,from,n) bcopy(from, to, n)
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];
79 // Initialize the Tile Manager subsystem
80 int fgTileMgrInit( void ) {
81 FG_LOG( FG_TERRAIN, FG_INFO, "Initializing Tile Manager subsystem." );
83 // load default material library
84 material_mgr.load_lib();
91 void fgTileMgrLoadTile( const fgBUCKET& p, int *index) {
94 c = &global_tile_cache;
96 FG_LOG( FG_TERRAIN, FG_DEBUG, "Updating for bucket " << p );
98 // if not in cache, load tile into the next available slot
99 *index = c->exists(p);
101 *index = c->next_avail();
102 c->fill_in(*index, p);
105 FG_LOG( FG_TERRAIN, FG_DEBUG, "Selected cache index: " << *index );
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 ) {
115 static fgBUCKET p_last = {-1000, 0, 0, 0};
119 c = &global_tile_cache;
120 f = current_aircraft.flight;
122 tile_diameter = current_options.get_tile_diameter();
124 fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p1);
125 dw = tile_diameter / 2;
126 dh = tile_diameter / 2;
128 if ( p1 == p_last ) {
129 // same bucket as last time
130 FG_LOG( FG_TERRAIN, FG_DEBUG, "Same bucket as last time" );
131 } else if ( p_last.lon == -1000 ) {
132 // First time through, initialize the system and load all
135 FG_LOG( FG_TERRAIN, FG_INFO, " First time through ... " );
136 FG_LOG( FG_TERRAIN, FG_INFO, " Updating Tile list for " << p1 );
137 FG_LOG( FG_TERRAIN, FG_INFO, " Loading "
138 << tile_diameter * tile_diameter << " tiles" );
140 // wipe/initialize tile cache
143 // build the local area list and update cache
144 for ( j = 0; j < tile_diameter; j++ ) {
145 for ( i = 0; i < tile_diameter; i++ ) {
146 fgBucketOffset(&p1, &p2, i - dw, j - dh);
147 fgTileMgrLoadTile( p2, &tiles[(j*tile_diameter) + i]);
151 // We've moved to a new bucket, we need to scroll our
152 // structures, and load in the new tiles
154 // CURRENTLY THIS ASSUMES WE CAN ONLY MOVE TO ADJACENT TILES.
155 // AT ULTRA HIGH SPEEDS THIS ASSUMPTION MAY NOT BE VALID IF
156 // THE AIRCRAFT CAN SKIP A TILE IN A SINGLE ITERATION.
158 FG_LOG( FG_TERRAIN, FG_INFO, "Updating Tile list for " << p1 );
160 if ( (p1.lon > p_last.lon) ||
161 ( (p1.lon == p_last.lon) && (p1.x > p_last.x) ) ) {
162 FG_LOG( FG_TERRAIN, FG_INFO,
163 " Loading " << tile_diameter << "tiles" );
164 for ( j = 0; j < tile_diameter; j++ ) {
166 for ( i = 0; i < tile_diameter - 1; i++ ) {
167 tiles[(j*tile_diameter) + i] =
168 tiles[(j*tile_diameter) + i + 1];
170 // load in new column
171 fgBucketOffset(&p_last, &p2, dw + 1, j - dh);
172 fgTileMgrLoadTile( p2, &tiles[(j*tile_diameter) +
175 } else if ( (p1.lon < p_last.lon) ||
176 ( (p1.lon == p_last.lon) && (p1.x < p_last.x) ) ) {
177 FG_LOG( FG_TERRAIN, FG_INFO,
178 " Loading " << tile_diameter << "tiles" );
179 for ( j = 0; j < tile_diameter; j++ ) {
181 for ( i = tile_diameter - 1; i > 0; i-- ) {
182 tiles[(j*tile_diameter) + i] =
183 tiles[(j*tile_diameter) + i - 1];
185 // load in new column
186 fgBucketOffset(&p_last, &p2, -dw - 1, j - dh);
187 fgTileMgrLoadTile( p2, &tiles[(j*tile_diameter) + 0]);
191 if ( (p1.lat > p_last.lat) ||
192 ( (p1.lat == p_last.lat) && (p1.y > p_last.y) ) ) {
193 FG_LOG( FG_TERRAIN, FG_INFO,
194 " Loading " << tile_diameter << "tiles" );
195 for ( i = 0; i < tile_diameter; i++ ) {
197 for ( j = 0; j < tile_diameter - 1; j++ ) {
198 tiles[(j * tile_diameter) + i] =
199 tiles[((j+1) * tile_diameter) + i];
201 // load in new column
202 fgBucketOffset(&p_last, &p2, i - dw, dh + 1);
203 fgTileMgrLoadTile( p2, &tiles[((tile_diameter-1) *
204 tile_diameter) + i]);
206 } else if ( (p1.lat < p_last.lat) ||
207 ( (p1.lat == p_last.lat) && (p1.y < p_last.y) ) ) {
208 FG_LOG( FG_TERRAIN, FG_INFO,
209 " Loading " << tile_diameter << "tiles" );
210 for ( i = 0; i < tile_diameter; i++ ) {
212 for ( j = tile_diameter - 1; j > 0; j-- ) {
213 tiles[(j * tile_diameter) + i] =
214 tiles[((j-1) * tile_diameter) + i];
216 // load in new column
217 fgBucketOffset(&p_last, &p2, i - dw, -dh - 1);
218 fgTileMgrLoadTile( p2, &tiles[0 + i]);
230 // Calculate shortest distance from point to line
231 static double point_line_dist_squared( const Point3D& tc, const Point3D& vp,
237 p[0] = tc.x(); p[1] = tc.y(); p[2] = tc.z();
238 p0[0] = vp.x(); p0[1] = vp.y(); p0[2] = vp.z();
240 dist = fgPointLineSquared(p, p0, d);
242 // cout << "dist = " << dist << endl;
248 // Calculate if point/radius is inside view frustum
249 static int viewable( const Point3D& cp, double radius ) {
250 int viewable = 1; // start by assuming it's viewable
253 /********************************/
254 #if defined( USE_FAST_FOV_CLIP ) // views.hxx
255 /********************************/
265 mat = (double *)(current_view.WORLD_TO_EYE);
267 eye[2] = x*mat[2] + y*mat[6] + z*mat[10] + mat[14];
269 // Check near and far clip plane
270 if( ( eye[2] > radius ) ||
271 ( eye[2] + radius + current_weather.visibility < 0) )
276 eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * current_view.slope_x;
278 // check right and left clip plane (from eye perspective)
279 x1 = radius * current_view.fov_x_clip;
280 if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) )
285 eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) * current_view.slope_y;
287 // check bottom and top clip plane (from eye perspective)
288 y1 = radius * current_view.fov_y_clip;
289 if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) )
294 /********************************/
295 #else // DO NOT USE_FAST_FOV_CLIP
296 /********************************/
304 MAT3_SET_HVEC(world, cp->x, cp->y, cp->z, 1.0);
305 // MAT3mult_vec(eye, world, v->WORLD_TO_EYE);
306 // printf( "\nworld -> eye = %.2f %.2f %.2f radius = %.2f\n",
307 // eye[0], eye[1], eye[2], radius);
309 // Use lazy evaluation for calculating eye hvec.
311 #define mat v->WORLD_TO_EYE
312 eye[2] = vec[0]*mat[0][2]+vec[1]*mat[1][2]+vec[2]*mat[2][2]+mat[3][2];
314 // Check near clip plane
315 if ( eye[2] > radius ) {
319 // Check far clip plane
320 if ( eye[2] + radius < -current_weather.visibility ) {
324 // check right clip plane (from eye perspective)
325 // y = m * (x - x0) = equation of a line intercepting X axis at x0
326 x1 = v->cos_fov_x * radius;
327 y1 = v->sin_fov_x * radius;
329 eye[0] = vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0];
331 if ( eye[2] > ((slope * (eye[0] - x1)) + y1) ) {
335 // check left clip plane (from eye perspective)
336 if ( eye[2] > -((slope * (eye[0] + x1)) - y1) ) {
340 // check bottom clip plane (from eye perspective)
341 x1 = -(v->cos_fov_y) * radius;
342 y1 = v->sin_fov_y * radius;
344 eye[1] = vec[0]*mat[0][1]+vec[1]*mat[1][1]+vec[2]*mat[2][1]+mat[3][1];
348 if ( eye[2] > ((slope * (eye[1] - x1)) + y1) ) {
352 // check top clip plane (from eye perspective)
353 if ( eye[2] > -((slope * (eye[1] + x1)) - y1) ) {
357 #endif // defined( USE_FAST_FOV_CLIP )
365 // inrange() IS THIS POINT WITHIN POSSIBLE VIEWING RANGE ?
366 // calculate distance from vertical tangent line at
367 // current position to center of object.
368 // this is equivalent to
369 // dist = point_line_dist_squared( &(t->center), &(v->abs_view_pos),
371 // if ( dist < FG_SQUARE(t->bounding_radius) ) {
373 // the compiler should inline this for us
376 inrange( const double radius, const Point3D& center, const Point3D& vp,
383 u[0] = center.x() - vp.x();
384 u[1] = center.y() - vp.y();
385 u[2] = center.z() - vp.z();
387 // calculate the projection, u1, of u along d.
388 // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
390 MAT3_SCALE_VEC(u1, up,
391 (MAT3_DOT_PRODUCT(u, up) / MAT3_DOT_PRODUCT(up, up)) );
393 // v = u - u1 = vector from closest point on line, p1, to the
394 // original point, p.
395 MAT3_SUB_VEC(v, u, u1);
397 return( FG_SQUARE(radius) >= MAT3_DOT_PRODUCT(v, v));
401 // Determine scenery altitude. Normally this just happens when we
402 // render the scene, but we'd also like to be able to do this
403 // explicitely. lat & lon are in radians. abs_view_pos in meters.
404 // Returns result in meters.
406 fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ) {
410 fgFRAGMENT *frag_ptr;
412 Point3D earth_center(0.0);
415 double dist, lat_geod, alt, sea_level_r;
419 c = &global_tile_cache;
420 // v = ¤t_view;
422 local_up[0] = abs_view_pos.x();
423 local_up[1] = abs_view_pos.y();
424 local_up[2] = abs_view_pos.z();
426 // Find current translation offset
427 fgBucketFind(lon * RAD_TO_DEG, lat * RAD_TO_DEG, &p);
428 index = c->exists(p);
430 FG_LOG( FG_TERRAIN, FG_WARN, "Tile not found" );
434 t = c->get_tile(index);
436 scenery.next_center = t->center;
438 // earth_center = Point3D(0.0, 0.0, 0.0);
440 FG_LOG( FG_TERRAIN, FG_DEBUG,
441 "Pos = (" << lon * RAD_TO_DEG << ", " << lat * RAD_TO_DEG
442 << ") Current bucket = " << p
443 << " Index = " << fgBucketGenIndex(&p) );
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);
450 // calc current terrain elevation calculate distance from
451 // vertical tangent line at current position to center of
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); */
458 dist = point_line_dist_squared( t->center, abs_view_pos, local_up );
459 if ( dist < FG_SQUARE(t->bounding_radius) ) {
461 // traverse fragment list for tile
462 fgTILE::FragmentIterator current = t->begin();
463 fgTILE::FragmentIterator last = t->end();
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); */
472 dist = point_line_dist_squared( frag_ptr->center,
475 if ( dist <= FG_SQUARE(frag_ptr->bounding_radius) ) {
476 if ( frag_ptr->intersect( abs_view_pos,
477 earth_center, 0, result ) ) {
478 FG_LOG( FG_TERRAIN, FG_DEBUG, "intersection point " <<
480 // compute geocentric coordinates of tile center
481 Point3D pp = fgCartToPolar3d(result);
482 FG_LOG( FG_TERRAIN, FG_DEBUG, " polar form = " << pp );
483 // convert to geodetic coordinates
484 fgGeocToGeod(pp.lat(), pp.radius(), &lat_geod,
487 // printf("alt = %.2f\n", alt);
488 // exit since we found an intersection
489 if ( alt > -9999.0 ) {
490 // printf("returning alt\n");
493 // printf("returning 0\n");
501 cout << "no terrain intersection found\n";
506 // NEW for legibility
508 // update this tile's geometry for current view
509 // The Compiler should inline this
511 update_tile_geometry( fgTILE *t, GLdouble *MODEL_VIEW)
516 // calculate tile offset
517 t->offset = t->center - scenery.center;
525 // Calculate the model_view transformation matrix for this tile
526 FG_MEM_COPY( m, MODEL_VIEW, 16*sizeof(GLdouble) );
528 // This is equivalent to doing a glTranslatef(x, y, z);
529 m[12] += (m[0]*x + m[4]*y + m[8] *z);
530 m[13] += (m[1]*x + m[5]*y + m[9] *z);
531 m[14] += (m[2]*x + m[6]*y + m[10]*z);
532 // m[15] += (m[3]*x + m[7]*y + m[11]*z);
533 // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
534 // so m[15] is unchanged
538 // Render the local tiles
539 void fgTileMgrRender( void ) {
545 fgFRAGMENT *frag_ptr;
553 c = &global_tile_cache;
554 f = current_aircraft.flight;
557 tile_diameter = current_options.get_tile_diameter();
559 scenery.cur_elev = fgTileMgrCurElev( FG_Longitude, FG_Latitude,
562 // initialize the transient per-material fragment lists
563 material_mgr.init_transient_material_lists();
566 // traverse the potentially viewable tile list
567 for ( i = 0; i < (tile_diameter * tile_diameter); i++ ) {
569 // fgPrintf( FG_TERRAIN, FG_DEBUG, "Index = %d\n", index);
570 t = c->get_tile(index);
572 // calculate tile offset
573 t->SetOffset( scenery.center );
575 // Course (tile based) culling
576 if ( viewable(t->offset, t->bounding_radius) ) {
577 // at least a portion of this tile could be viewable
579 // Calculate the model_view transformation matrix for this tile
580 // This is equivalent to doing a glTranslatef(x, y, z);
581 t->UpdateViewMatrix( v->MODEL_VIEW );
584 // xglTranslatef(t->offset.x, t->offset.y, t->offset.z);
586 // traverse fragment list for tile
587 fgTILE::FragmentIterator current = t->begin();
588 fgTILE::FragmentIterator last = t->end();
590 for ( ; current != last; ++current ) {
591 frag_ptr = &(*current);
593 if ( frag_ptr->display_list >= 0 ) {
594 // Fine (fragment based) culling
595 frag_offset = frag_ptr->center - scenery.center;
597 if ( viewable(frag_offset, frag_ptr->bounding_radius*2) ) {
598 // add to transient per-material property fragment list
599 // frag_ptr->tile_offset.x = t->offset.x;
600 // frag_ptr->tile_offset.y = t->offset.y;
601 // frag_ptr->tile_offset.z = t->offset.z;
603 mtl_ptr = frag_ptr->material_ptr;
604 // printf(" lookup = %s\n", mtl_ptr->texture_name);
605 if ( ! mtl_ptr->append_sort_list( frag_ptr ) ) {
606 FG_LOG( FG_TERRAIN, FG_ALERT,
607 "Overran material sorting array" );
610 // xglCallList(frag_ptr->display_list);
613 // printf("Culled a fragment %.2f %.2f %.2f %.2f\n",
614 // frag_ptr->center.x, frag_ptr->center.y,
615 // frag_ptr->center.z, frag_ptr->bounding_radius);
623 culled += t->fragment_list.size();
627 if ( (drawn + culled) > 0 ) {
628 v->vfc_ratio = (double)culled / (double)(drawn + culled);
632 // printf("drawn = %d culled = %d saved = %.2f\n", drawn, culled,
636 // traverse the transient per-material fragment lists and render
637 // out all fragments for each material property.
639 material_mgr.render_fragments();
645 // Revision 1.44 1998/11/23 21:49:48 curt
648 // Revision 1.43 1998/11/09 23:40:52 curt
649 // Bernie Bright <bbright@c031.aone.net.au> writes:
650 // I've made some changes to the Scenery handling. Basically just tidy ups.
651 // The main difference is in tile.[ch]xx where I've changed list<fgFRAGMENT> to
652 // vector<fgFRAGMENT>. Studying our usage patterns this seems reasonable.
653 // Lists are good if you need to insert/delete elements randomly but we
654 // don't do that. All access seems to be sequential. Two additional
655 // benefits are smaller memory usage - each list element requires pointers
656 // to the next and previous elements, and faster access - vector iterators
657 // are smaller and faster than list iterators. This should also help
658 // Charlie Hotchkiss' problem when compiling with Borland and STLport.
660 // ./Lib/Bucket/bucketutils.hxx
661 // Convenience functions for fgBUCKET.
663 // ./Simulator/Scenery/tile.cxx
664 // ./Simulator/Scenery/tile.hxx
665 // Changed fragment list to a vector.
666 // Added some convenience member functions.
668 // ./Simulator/Scenery/tilecache.cxx
669 // ./Simulator/Scenery/tilecache.hxx
670 // use const fgBUCKET& instead of fgBUCKET* where appropriate.
672 // ./Simulator/Scenery/tilemgr.cxx
673 // ./Simulator/Scenery/tilemgr.hxx
674 // uses all the new convenience functions.
676 // Revision 1.42 1998/11/06 21:18:23 curt
677 // Converted to new logstream debugging facility. This allows release
678 // builds with no messages at all (and no performance impact) by using
679 // the -DFG_NDEBUG flag.
681 // Revision 1.41 1998/10/18 01:17:23 curt
684 // Revision 1.40 1998/10/17 01:34:28 curt
687 // Revision 1.39 1998/10/16 00:55:50 curt
688 // Converted to Point3D class.
690 // Revision 1.38 1998/09/17 18:36:18 curt
691 // Tweaks and optimizations by Norman Vine.
693 // Revision 1.37 1998/09/15 01:36:45 curt
694 // cleaned up my fragment.num_faces hack :-) to use the STL (no need in
695 // duplicating work.)
696 // Tweaked fgTileMgrRender() do not calc tile matrix unless necessary.
697 // removed some unneeded stuff from fgTileMgrCurElev()
699 // Revision 1.36 1998/09/14 12:45:26 curt
702 // Revision 1.35 1998/09/10 19:07:16 curt
703 // /Simulator/Objects/fragment.hxx
704 // Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
706 // ./Simulator/Objects/material.cxx
707 // ./Simulator/Objects/material.hxx
708 // Made fgMATERIAL and fgMATERIAL_MGR bona fide classes with private
709 // data members - that should keep the rabble happy :)
711 // ./Simulator/Scenery/tilemgr.cxx
712 // In viewable() delay evaluation of eye[0] and eye[1] in until they're
714 // Change to fgTileMgrRender() to call fgMATERIAL_MGR::render_fragments()
717 // ./Include/fg_stl_config.h
718 // ./Include/auto_ptr.hxx
719 // Added support for g++ 2.7.
720 // Further changes to other files are forthcoming.
722 // Brief summary of changes required for g++ 2.7.
723 // operator->() not supported by iterators: use (*i).x instead of i->x
724 // default template arguments not supported,
725 // <functional> doesn't have mem_fun_ref() needed by callbacks.
726 // some std include files have different names.
727 // template member functions not supported.
729 // Revision 1.34 1998/09/09 20:58:09 curt
730 // Tweaks to loop constructs with STL usage.
732 // Revision 1.33 1998/09/08 15:05:10 curt
733 // Optimization by Norman Vine.
735 // Revision 1.32 1998/08/25 16:52:44 curt
736 // material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
739 // Revision 1.31 1998/08/24 20:11:40 curt
742 // Revision 1.30 1998/08/22 14:49:59 curt
743 // Attempting to iron out seg faults and crashes.
744 // Did some shuffling to fix a initialization order problem between view
745 // position, scenery elevation.
747 // Revision 1.29 1998/08/20 15:12:06 curt
748 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
749 // the need for "void" pointers and casts.
750 // Quick hack to count the number of scenery polygons that are being drawn.
752 // Revision 1.28 1998/08/12 21:13:06 curt
753 // material.cxx: don't load textures if they are disabled
754 // obj.cxx: optimizations from Norman Vine
755 // tile.cxx: minor tweaks
756 // tile.hxx: addition of num_faces
757 // tilemgr.cxx: minor tweaks
759 // Revision 1.27 1998/07/24 21:42:09 curt
760 // material.cxx: whups, double method declaration with no definition.
761 // obj.cxx: tweaks to avoid errors in SGI's CC.
762 // tile.cxx: optimizations by Norman Vine.
763 // tilemgr.cxx: optimizations by Norman Vine.
765 // Revision 1.26 1998/07/20 12:51:26 curt
766 // Added far clip plane to fragment clipping calculations and tie this to
767 // weather->visibility. This way you can increase framerates by increasing
768 // for and lowering visibility.
770 // Revision 1.25 1998/07/13 21:02:01 curt
771 // Wrote access functions for current fgOPTIONS.
773 // Revision 1.24 1998/07/12 03:18:29 curt
774 // Added ground collision detection. This involved:
775 // - saving the entire vertex list for each tile with the tile records.
776 // - saving the face list for each fragment with the fragment records.
777 // - code to intersect the current vertical line with the proper face in
778 // an efficient manner as possible.
779 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
781 // Revision 1.23 1998/07/08 14:47:23 curt
782 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
783 // polare3d.h renamed to polar3d.hxx
784 // fg{Cartesian,Polar}Point3d consolodated.
785 // Added some initial support for calculating local current ground elevation.
787 // Revision 1.22 1998/07/04 00:54:31 curt
788 // Added automatic mipmap generation.
790 // When rendering fragments, use saved model view matrix from associated tile
791 // rather than recalculating it with push() translate() pop().
793 // Revision 1.21 1998/06/27 16:54:59 curt
794 // Check for GL_VERSION_1_1 or GL_EXT_texture_object to decide whether to use
795 // "EXT" versions of texture management routines.
797 // Revision 1.20 1998/06/17 21:36:42 curt
798 // Load and manage multiple textures defined in the Materials library.
799 // Boost max material fagments for each material property to 800.
800 // Multiple texture support when rendering.
802 // Revision 1.19 1998/06/08 17:57:54 curt
803 // Working first pass at material proporty sorting.
805 // Revision 1.18 1998/06/06 01:09:32 curt
806 // I goofed on the log message in the last commit ... now fixed.
808 // Revision 1.17 1998/06/06 01:07:18 curt
809 // Increased per material fragment list size from 100 to 400.
810 // Now correctly draw viewable fragments in per material order.
812 // Revision 1.16 1998/06/05 22:39:55 curt
813 // Working on sorting by, and rendering by material properties.
815 // Revision 1.15 1998/06/03 00:47:51 curt
816 // No .h for STL includes.
817 // Minor view culling optimizations.
819 // Revision 1.14 1998/06/01 17:56:20 curt
820 // Incremental additions to material.cxx (not fully functional)
821 // Tweaked vfc_ratio math to avoid divide by zero.
823 // Revision 1.13 1998/05/24 02:49:10 curt
824 // Implimented fragment level view frustum culling.
826 // Revision 1.12 1998/05/23 14:09:23 curt
827 // Added tile.cxx and tile.hxx.
828 // Working on rewriting the tile management system so a tile is just a list
829 // fragments, and the fragment record contains the display list for that fragment.
831 // Revision 1.11 1998/05/20 20:53:55 curt
832 // Moved global ref point and radius (bounding sphere info, and offset) to
833 // data file rather than calculating it on the fly.
834 // Fixed polygon winding problem in scenery generation stage rather than
835 // compensating for it on the fly.
836 // Made a fgTILECACHE class.
838 // Revision 1.10 1998/05/17 16:59:34 curt
839 // Frist pass at view frustum culling now operational.
841 // Revision 1.9 1998/05/16 13:09:58 curt
842 // Beginning to add support for view frustum culling.
843 // Added some temporary code to calculate bouding radius, until the
844 // scenery generation tools and scenery can be updated.
846 // Revision 1.8 1998/05/07 23:15:21 curt
847 // Fixed a glTexImage2D() usage bug where width and height were mis-swapped.
848 // Added support for --tile-radius=n option.
850 // Revision 1.7 1998/05/06 03:16:42 curt
851 // Added an option to control square tile radius.
853 // Revision 1.6 1998/05/02 01:52:18 curt
854 // Playing around with texture coordinates.
856 // Revision 1.5 1998/04/30 12:35:32 curt
857 // Added a command line rendering option specify smooth/flat shading.
859 // Revision 1.4 1998/04/27 03:30:14 curt
860 // Minor transformation adjustments to try to keep scenery tiles closer to
861 // (0, 0, 0) GLfloats run out of precision at the distances we need to model
862 // the earth, but we can do a bunch of pre-transformations using double math
863 // and then cast to GLfloat once everything is close in where we have less
864 // precision problems.
866 // Revision 1.3 1998/04/25 22:06:32 curt
867 // Edited cvs log messages in source files ... bad bad bad!
869 // Revision 1.2 1998/04/24 00:51:09 curt
870 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
871 // Tweaked the scenery file extentions to be "file.obj" (uncompressed)
872 // or "file.obz" (compressed.)
874 // Revision 1.1 1998/04/22 13:22:48 curt
875 // C++ - ifing the code a bit.
877 // Revision 1.25 1998/04/18 04:14:07 curt
878 // Moved fg_debug.c to it's own library.
880 // Revision 1.24 1998/04/14 02:23:18 curt
881 // Code reorganizations. Added a Lib/ directory for more general libraries.
883 // Revision 1.23 1998/04/08 23:30:08 curt
884 // Adopted Gnu automake/autoconf system.
886 // Revision 1.22 1998/04/03 22:11:38 curt
887 // Converting to Gnu autoconf system.
889 // Revision 1.21 1998/03/23 21:23:05 curt
890 // Debugging output tweaks.
892 // Revision 1.20 1998/03/14 00:30:51 curt
893 // Beginning initial terrain texturing experiments.
895 // Revision 1.19 1998/02/20 00:16:25 curt
896 // Thursday's tweaks.
898 // Revision 1.18 1998/02/19 13:05:54 curt
899 // Incorporated some HUD tweaks from Michelle America.
900 // Tweaked the sky's sunset/rise colors.
901 // Other misc. tweaks.
903 // Revision 1.17 1998/02/16 13:39:46 curt
904 // Miscellaneous weekend tweaks. Fixed? a cache problem that caused whole
905 // tiles to occasionally be missing.
907 // Revision 1.16 1998/02/12 21:59:53 curt
908 // Incorporated code changes contributed by Charlie Hotchkiss
909 // <chotchkiss@namg.us.anritsu.com>
911 // Revision 1.14 1998/02/09 21:30:19 curt
912 // Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
914 // Revision 1.13 1998/02/07 15:29:46 curt
915 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
916 // <chotchkiss@namg.us.anritsu.com>
918 // Revision 1.12 1998/02/01 03:39:55 curt
921 // Revision 1.11 1998/01/31 00:43:27 curt
922 // Added MetroWorks patches from Carmen Volpe.
924 // Revision 1.10 1998/01/29 00:51:40 curt
925 // First pass at tile cache, dynamic tile loading and tile unloading now works.
927 // Revision 1.9 1998/01/27 03:26:44 curt
928 // Playing with new fgPrintf command.
930 // Revision 1.8 1998/01/27 00:48:04 curt
931 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
932 // system and commandline/config file processing code.
934 // Revision 1.7 1998/01/26 15:55:25 curt
935 // Progressing on building dynamic scenery system.
937 // Revision 1.6 1998/01/24 00:03:30 curt
940 // Revision 1.5 1998/01/19 19:27:18 curt
941 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
942 // This should simplify things tremendously.
944 // Revision 1.4 1998/01/19 18:40:38 curt
945 // Tons of little changes to clean up the code and to remove fatal errors
946 // when building with the c++ compiler.
948 // Revision 1.3 1998/01/13 00:23:11 curt
949 // Initial changes to support loading and management of scenery tiles. Note,
950 // there's still a fair amount of work left to be done.
952 // Revision 1.2 1998/01/08 02:22:27 curt
953 // Continue working on basic features.
955 // Revision 1.1 1998/01/07 23:50:51 curt
956 // "area" renamed to "tile"
958 // Revision 1.2 1998/01/07 03:29:29 curt
959 // Given an arbitrary lat/lon, we can now:
960 // generate a unique index for the chunk containing the lat/lon
961 // generate a path name to the chunk file
962 // build a list of the indexes of all the nearby areas.
964 // Revision 1.1 1998/01/07 02:05:48 curt