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.h>
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( fgBUCKET *p, int *index) {
94 c = &global_tile_cache;
96 FG_LOG( FG_TERRAIN, FG_DEBUG,
97 "Updating for bucket "
98 << p->lon << " " << p->lat << " " << p->x << " " << p->y );
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);
106 FG_LOG( FG_TERRAIN, FG_DEBUG, "Selected cache index of " << *index);
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 ) {
116 static fgBUCKET p_last = {-1000, 0, 0, 0};
120 c = &global_tile_cache;
121 f = current_aircraft.flight;
123 tile_diameter = current_options.get_tile_diameter();
125 fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p1);
126 dw = tile_diameter / 2;
127 dh = tile_diameter / 2;
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 FG_LOG( FG_TERRAIN, FG_DEBUG, "Same bucket as last time" );
133 } else if ( p_last.lon == -1000 ) {
134 // First time through, initialize the system and load all
137 FG_LOG( FG_TERRAIN, FG_INFO, " First time through ... " );
138 FG_LOG( FG_TERRAIN, FG_INFO,
139 " Updating Tile list for "
140 << p1.lon << "," << p1.lat << " " << p1.x << "," << p1.y );
141 FG_LOG( FG_TERRAIN, FG_INFO, " Loading "
142 << tile_diameter * tile_diameter
145 // wipe/initialize tile cache
148 // build the local area list and update cache
149 for ( j = 0; j < tile_diameter; j++ ) {
150 for ( i = 0; i < tile_diameter; i++ ) {
151 fgBucketOffset(&p1, &p2, i - dw, j - dh);
152 fgTileMgrLoadTile(&p2, &tiles[(j*tile_diameter) + i]);
156 // We've moved to a new bucket, we need to scroll our
157 // structures, and load in the new tiles
159 // CURRENTLY THIS ASSUMES WE CAN ONLY MOVE TO ADJACENT TILES.
160 // AT ULTRA HIGH SPEEDS THIS ASSUMPTION MAY NOT BE VALID IF
161 // THE AIRCRAFT CAN SKIP A TILE IN A SINGLE ITERATION.
163 FG_LOG( FG_TERRAIN, FG_INFO,
164 "Updating Tile list for "
165 << p1.lon << "," << p1.lat << " " << p1.x << "," << p1.y );
167 if ( (p1.lon > p_last.lon) ||
168 ( (p1.lon == p_last.lon) && (p1.x > p_last.x) ) ) {
169 FG_LOG( FG_TERRAIN, FG_INFO,
170 " Loading " << tile_diameter << "tiles" );
171 for ( j = 0; j < tile_diameter; j++ ) {
173 for ( i = 0; i < tile_diameter - 1; i++ ) {
174 tiles[(j*tile_diameter) + i] =
175 tiles[(j*tile_diameter) + i + 1];
177 // load in new column
178 fgBucketOffset(&p_last, &p2, dw + 1, j - dh);
179 fgTileMgrLoadTile(&p2, &tiles[(j*tile_diameter) +
182 } else if ( (p1.lon < p_last.lon) ||
183 ( (p1.lon == p_last.lon) && (p1.x < p_last.x) ) ) {
184 FG_LOG( FG_TERRAIN, FG_INFO,
185 " Loading " << tile_diameter << "tiles" );
186 for ( j = 0; j < tile_diameter; j++ ) {
188 for ( i = tile_diameter - 1; i > 0; i-- ) {
189 tiles[(j*tile_diameter) + i] =
190 tiles[(j*tile_diameter) + i - 1];
192 // load in new column
193 fgBucketOffset(&p_last, &p2, -dw - 1, j - dh);
194 fgTileMgrLoadTile(&p2, &tiles[(j*tile_diameter) + 0]);
198 if ( (p1.lat > p_last.lat) ||
199 ( (p1.lat == p_last.lat) && (p1.y > p_last.y) ) ) {
200 FG_LOG( FG_TERRAIN, FG_INFO,
201 " Loading " << tile_diameter << "tiles" );
202 for ( i = 0; i < tile_diameter; i++ ) {
204 for ( j = 0; j < tile_diameter - 1; j++ ) {
205 tiles[(j * tile_diameter) + i] =
206 tiles[((j+1) * tile_diameter) + i];
208 // load in new column
209 fgBucketOffset(&p_last, &p2, i - dw, dh + 1);
210 fgTileMgrLoadTile(&p2, &tiles[((tile_diameter-1) *
211 tile_diameter) + i]);
213 } else if ( (p1.lat < p_last.lat) ||
214 ( (p1.lat == p_last.lat) && (p1.y < p_last.y) ) ) {
215 FG_LOG( FG_TERRAIN, FG_INFO,
216 " Loading " << tile_diameter << "tiles" );
217 for ( i = 0; i < tile_diameter; i++ ) {
219 for ( j = tile_diameter - 1; j > 0; j-- ) {
220 tiles[(j * tile_diameter) + i] =
221 tiles[((j-1) * tile_diameter) + i];
223 // load in new column
224 fgBucketOffset(&p_last, &p2, i - dw, -dh - 1);
225 fgTileMgrLoadTile(&p2, &tiles[0 + i]);
237 // Calculate shortest distance from point to line
238 static double point_line_dist_squared( const Point3D& tc, const Point3D& vp,
244 p[0] = tc.x(); p[1] = tc.y(); p[2] = tc.z();
245 p0[0] = vp.x(); p0[1] = vp.y(); p0[2] = vp.z();
247 dist = fgPointLineSquared(p, p0, d);
249 // printf("dist = %.2f\n", dist);
255 // Calculate if point/radius is inside view frustum
256 static int viewable( const Point3D& cp, double radius ) {
257 int viewable = 1; // start by assuming it's viewable
260 /********************************/
261 #if defined( USE_FAST_FOV_CLIP ) // views.hxx
262 /********************************/
272 mat = (double *)(current_view.WORLD_TO_EYE);
274 eye[2] = x*mat[2] + y*mat[6] + z*mat[10] + mat[14];
276 // Check near and far clip plane
277 if( ( eye[2] > radius ) ||
278 ( eye[2] + radius + current_weather.visibility < 0) )
283 eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * current_view.slope_x;
285 // check right and left clip plane (from eye perspective)
286 x1 = radius * current_view.fov_x_clip;
287 if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) )
292 eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) * current_view.slope_y;
294 // check bottom and top clip plane (from eye perspective)
295 y1 = radius * current_view.fov_y_clip;
296 if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) )
301 /********************************/
302 #else // DO NOT USE_FAST_FOV_CLIP
303 /********************************/
311 MAT3_SET_HVEC(world, cp->x, cp->y, cp->z, 1.0);
312 // MAT3mult_vec(eye, world, v->WORLD_TO_EYE);
313 // printf( "\nworld -> eye = %.2f %.2f %.2f radius = %.2f\n",
314 // eye[0], eye[1], eye[2], radius);
316 // Use lazy evaluation for calculating eye hvec.
318 #define mat v->WORLD_TO_EYE
319 eye[2] = vec[0]*mat[0][2]+vec[1]*mat[1][2]+vec[2]*mat[2][2]+mat[3][2];
321 // Check near clip plane
322 if ( eye[2] > radius ) {
326 // Check far clip plane
327 if ( eye[2] + radius < -current_weather.visibility ) {
331 // check right clip plane (from eye perspective)
332 // y = m * (x - x0) = equation of a line intercepting X axis at x0
333 x1 = v->cos_fov_x * radius;
334 y1 = v->sin_fov_x * radius;
336 eye[0] = vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0];
338 if ( eye[2] > ((slope * (eye[0] - x1)) + y1) ) {
342 // check left clip plane (from eye perspective)
343 if ( eye[2] > -((slope * (eye[0] + x1)) - y1) ) {
347 // check bottom clip plane (from eye perspective)
348 x1 = -(v->cos_fov_y) * radius;
349 y1 = v->sin_fov_y * radius;
351 eye[1] = vec[0]*mat[0][1]+vec[1]*mat[1][1]+vec[2]*mat[2][1]+mat[3][1];
355 if ( eye[2] > ((slope * (eye[1] - x1)) + y1) ) {
359 // check top clip plane (from eye perspective)
360 if ( eye[2] > -((slope * (eye[1] + x1)) - y1) ) {
364 #endif // defined( USE_FAST_FOV_CLIP )
372 // inrange() IS THIS POINT WITHIN POSSIBLE VIEWING RANGE ?
373 // calculate distance from vertical tangent line at
374 // current position to center of object.
375 // this is equivalent to
376 // dist = point_line_dist_squared( &(t->center), &(v->abs_view_pos),
378 // if ( dist < FG_SQUARE(t->bounding_radius) ) {
380 // the compiler should inline this for us
383 inrange( const double radius, const Point3D& center, const Point3D& vp,
390 u[0] = center.x() - vp.x();
391 u[1] = center.y() - vp.y();
392 u[2] = center.z() - vp.z();
394 // calculate the projection, u1, of u along d.
395 // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
397 MAT3_SCALE_VEC(u1, up,
398 (MAT3_DOT_PRODUCT(u, up) / MAT3_DOT_PRODUCT(up, up)) );
400 // v = u - u1 = vector from closest point on line, p1, to the
401 // original point, p.
402 MAT3_SUB_VEC(v, u, u1);
404 return( FG_SQUARE(radius) >= MAT3_DOT_PRODUCT(v, v));
408 // Determine scenery altitude. Normally this just happens when we
409 // render the scene, but we'd also like to be able to do this
410 // explicitely. lat & lon are in radians. abs_view_pos in meters.
411 // Returns result in meters.
412 double fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ) {
416 fgFRAGMENT *frag_ptr;
418 Point3D earth_center, result;
421 list < fgFRAGMENT > :: iterator current;
422 list < fgFRAGMENT > :: iterator last;
423 double dist, lat_geod, alt, sea_level_r;
427 c = &global_tile_cache;
428 // v = ¤t_view;
430 local_up[0] = abs_view_pos.x();
431 local_up[1] = abs_view_pos.y();
432 local_up[2] = abs_view_pos.z();
434 // Find current translation offset
435 fgBucketFind(lon * RAD_TO_DEG, lat * RAD_TO_DEG, &p);
436 index = c->exists(&p);
437 t = c->get_tile(index);
439 scenery.next_center = t->center;
441 earth_center = Point3D(0.0, 0.0, 0.0);
443 FG_LOG( FG_TERRAIN, FG_DEBUG,
444 "Pos = (" << lon * RAD_TO_DEG << ", " << lat * RAD_TO_DEG
445 << " Current bucket = "
446 << p.lon << " " << p.lat << " " << p.x << " " << p.y
447 << " Index = " << fgBucketGenIndex(&p) );
449 // calculate tile offset
450 // x = (t->offset.x = t->center.x - scenery.center.x);
451 // y = (t->offset.y = t->center.y - scenery.center.y);
452 // z = (t->offset.z = t->center.z - scenery.center.z);
454 // calc current terrain elevation calculate distance from
455 // vertical tangent line at current position to center of
458 /* printf("distance squared = %.2f, bounding radius = %.2f\n",
459 point_line_dist_squared(&(t->offset), &(v->view_pos),
460 v->local_up), t->bounding_radius); */
462 dist = point_line_dist_squared( t->center, abs_view_pos, local_up );
463 if ( dist < FG_SQUARE(t->bounding_radius) ) {
465 // traverse fragment list for tile
466 current = t->fragment_list.begin();
467 last = t->fragment_list.end();
469 for ( ; current != last; ++current ) {
470 frag_ptr = &(*current);
471 /* printf("distance squared = %.2f, bounding radius = %.2f\n",
472 point_line_dist_squared( &(frag_ptr->center),
473 &abs_view_pos), local_up),
474 frag_ptr->bounding_radius); */
476 dist = point_line_dist_squared( frag_ptr->center,
479 if ( dist <= FG_SQUARE(frag_ptr->bounding_radius) ) {
480 if ( frag_ptr->intersect( abs_view_pos,
481 earth_center, 0, result ) ) {
482 // compute geocentric coordinates of tile center
483 pp = fgCartToPolar3d(result);
484 // convert to geodetic coordinates
485 fgGeocToGeod(pp.lat(), pp.radius(), &lat_geod,
487 // printf("alt = %.2f\n", alt);
488 // exit since we found an intersection
495 printf("no terrain intersection found\n");
500 // NEW for legibility
502 // update this tile's geometry for current view
503 // The Compiler should inline this
505 update_tile_geometry( fgTILE *t, GLdouble *MODEL_VIEW)
510 // calculate tile offset
511 t->offset = t->center - scenery.center;
519 // Calculate the model_view transformation matrix for this tile
520 FG_MEM_COPY( m, MODEL_VIEW, 16*sizeof(GLdouble) );
522 // This is equivalent to doing a glTranslatef(x, y, z);
523 m[12] += (m[0]*x + m[4]*y + m[8] *z);
524 m[13] += (m[1]*x + m[5]*y + m[9] *z);
525 m[14] += (m[2]*x + m[6]*y + m[10]*z);
526 // m[15] += (m[3]*x + m[7]*y + m[11]*z);
527 // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
528 // so m[15] is unchanged
532 // Render the local tiles
533 void fgTileMgrRender( void ) {
539 fgFRAGMENT *frag_ptr;
541 list < fgFRAGMENT > :: iterator current;
542 list < fgFRAGMENT > :: iterator last;
549 c = &global_tile_cache;
550 f = current_aircraft.flight;
553 tile_diameter = current_options.get_tile_diameter();
555 scenery.cur_elev = fgTileMgrCurElev( FG_Longitude, FG_Latitude,
558 // initialize the transient per-material fragment lists
559 material_mgr.init_transient_material_lists();
562 // traverse the potentially viewable tile list
563 for ( i = 0; i < (tile_diameter * tile_diameter); i++ ) {
565 // fgPrintf( FG_TERRAIN, FG_DEBUG, "Index = %d\n", index);
566 t = c->get_tile(index);
568 // calculate tile offset
569 t->SetOffset( scenery.center );
571 // Course (tile based) culling
572 if ( viewable(t->offset, t->bounding_radius) ) {
573 // at least a portion of this tile could be viewable
575 // Calculate the model_view transformation matrix for this tile
576 // This is equivalent to doing a glTranslatef(x, y, z);
577 t->UpdateViewMatrix( v->MODEL_VIEW );
580 // xglTranslatef(t->offset.x, t->offset.y, t->offset.z);
582 // traverse fragment list for tile
583 current = t->fragment_list.begin();
584 last = t->fragment_list.end();
586 for ( ; current != last; ++current ) {
587 frag_ptr = &(*current);
589 if ( frag_ptr->display_list >= 0 ) {
590 // Fine (fragment based) culling
591 frag_offset = frag_ptr->center - scenery.center;
593 if ( viewable(frag_offset, frag_ptr->bounding_radius*2) ) {
594 // add to transient per-material property fragment list
595 // frag_ptr->tile_offset.x = t->offset.x;
596 // frag_ptr->tile_offset.y = t->offset.y;
597 // frag_ptr->tile_offset.z = t->offset.z;
599 mtl_ptr = frag_ptr->material_ptr;
600 // printf(" lookup = %s\n", mtl_ptr->texture_name);
601 if ( ! mtl_ptr->append_sort_list( frag_ptr ) ) {
602 FG_LOG( FG_TERRAIN, FG_ALERT,
603 "Overran material sorting array" );
606 // xglCallList(frag_ptr->display_list);
609 // printf("Culled a fragment %.2f %.2f %.2f %.2f\n",
610 // frag_ptr->center.x, frag_ptr->center.y,
611 // frag_ptr->center.z, frag_ptr->bounding_radius);
619 culled += t->fragment_list.size();
623 if ( (drawn + culled) > 0 ) {
624 v->vfc_ratio = (double)culled / (double)(drawn + culled);
628 // printf("drawn = %d culled = %d saved = %.2f\n", drawn, culled,
632 // traverse the transient per-material fragment lists and render
633 // out all fragments for each material property.
635 material_mgr.render_fragments();
641 // Revision 1.42 1998/11/06 21:18:23 curt
642 // Converted to new logstream debugging facility. This allows release
643 // builds with no messages at all (and no performance impact) by using
644 // the -DFG_NDEBUG flag.
646 // Revision 1.41 1998/10/18 01:17:23 curt
649 // Revision 1.40 1998/10/17 01:34:28 curt
652 // Revision 1.39 1998/10/16 00:55:50 curt
653 // Converted to Point3D class.
655 // Revision 1.38 1998/09/17 18:36:18 curt
656 // Tweaks and optimizations by Norman Vine.
658 // Revision 1.37 1998/09/15 01:36:45 curt
659 // cleaned up my fragment.num_faces hack :-) to use the STL (no need in
660 // duplicating work.)
661 // Tweaked fgTileMgrRender() do not calc tile matrix unless necessary.
662 // removed some unneeded stuff from fgTileMgrCurElev()
664 // Revision 1.36 1998/09/14 12:45:26 curt
667 // Revision 1.35 1998/09/10 19:07:16 curt
668 // /Simulator/Objects/fragment.hxx
669 // Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
671 // ./Simulator/Objects/material.cxx
672 // ./Simulator/Objects/material.hxx
673 // Made fgMATERIAL and fgMATERIAL_MGR bona fide classes with private
674 // data members - that should keep the rabble happy :)
676 // ./Simulator/Scenery/tilemgr.cxx
677 // In viewable() delay evaluation of eye[0] and eye[1] in until they're
679 // Change to fgTileMgrRender() to call fgMATERIAL_MGR::render_fragments()
682 // ./Include/fg_stl_config.h
683 // ./Include/auto_ptr.hxx
684 // Added support for g++ 2.7.
685 // Further changes to other files are forthcoming.
687 // Brief summary of changes required for g++ 2.7.
688 // operator->() not supported by iterators: use (*i).x instead of i->x
689 // default template arguments not supported,
690 // <functional> doesn't have mem_fun_ref() needed by callbacks.
691 // some std include files have different names.
692 // template member functions not supported.
694 // Revision 1.34 1998/09/09 20:58:09 curt
695 // Tweaks to loop constructs with STL usage.
697 // Revision 1.33 1998/09/08 15:05:10 curt
698 // Optimization by Norman Vine.
700 // Revision 1.32 1998/08/25 16:52:44 curt
701 // material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
704 // Revision 1.31 1998/08/24 20:11:40 curt
707 // Revision 1.30 1998/08/22 14:49:59 curt
708 // Attempting to iron out seg faults and crashes.
709 // Did some shuffling to fix a initialization order problem between view
710 // position, scenery elevation.
712 // Revision 1.29 1998/08/20 15:12:06 curt
713 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
714 // the need for "void" pointers and casts.
715 // Quick hack to count the number of scenery polygons that are being drawn.
717 // Revision 1.28 1998/08/12 21:13:06 curt
718 // material.cxx: don't load textures if they are disabled
719 // obj.cxx: optimizations from Norman Vine
720 // tile.cxx: minor tweaks
721 // tile.hxx: addition of num_faces
722 // tilemgr.cxx: minor tweaks
724 // Revision 1.27 1998/07/24 21:42:09 curt
725 // material.cxx: whups, double method declaration with no definition.
726 // obj.cxx: tweaks to avoid errors in SGI's CC.
727 // tile.cxx: optimizations by Norman Vine.
728 // tilemgr.cxx: optimizations by Norman Vine.
730 // Revision 1.26 1998/07/20 12:51:26 curt
731 // Added far clip plane to fragment clipping calculations and tie this to
732 // weather->visibility. This way you can increase framerates by increasing
733 // for and lowering visibility.
735 // Revision 1.25 1998/07/13 21:02:01 curt
736 // Wrote access functions for current fgOPTIONS.
738 // Revision 1.24 1998/07/12 03:18:29 curt
739 // Added ground collision detection. This involved:
740 // - saving the entire vertex list for each tile with the tile records.
741 // - saving the face list for each fragment with the fragment records.
742 // - code to intersect the current vertical line with the proper face in
743 // an efficient manner as possible.
744 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
746 // Revision 1.23 1998/07/08 14:47:23 curt
747 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
748 // polare3d.h renamed to polar3d.hxx
749 // fg{Cartesian,Polar}Point3d consolodated.
750 // Added some initial support for calculating local current ground elevation.
752 // Revision 1.22 1998/07/04 00:54:31 curt
753 // Added automatic mipmap generation.
755 // When rendering fragments, use saved model view matrix from associated tile
756 // rather than recalculating it with push() translate() pop().
758 // Revision 1.21 1998/06/27 16:54:59 curt
759 // Check for GL_VERSION_1_1 or GL_EXT_texture_object to decide whether to use
760 // "EXT" versions of texture management routines.
762 // Revision 1.20 1998/06/17 21:36:42 curt
763 // Load and manage multiple textures defined in the Materials library.
764 // Boost max material fagments for each material property to 800.
765 // Multiple texture support when rendering.
767 // Revision 1.19 1998/06/08 17:57:54 curt
768 // Working first pass at material proporty sorting.
770 // Revision 1.18 1998/06/06 01:09:32 curt
771 // I goofed on the log message in the last commit ... now fixed.
773 // Revision 1.17 1998/06/06 01:07:18 curt
774 // Increased per material fragment list size from 100 to 400.
775 // Now correctly draw viewable fragments in per material order.
777 // Revision 1.16 1998/06/05 22:39:55 curt
778 // Working on sorting by, and rendering by material properties.
780 // Revision 1.15 1998/06/03 00:47:51 curt
781 // No .h for STL includes.
782 // Minor view culling optimizations.
784 // Revision 1.14 1998/06/01 17:56:20 curt
785 // Incremental additions to material.cxx (not fully functional)
786 // Tweaked vfc_ratio math to avoid divide by zero.
788 // Revision 1.13 1998/05/24 02:49:10 curt
789 // Implimented fragment level view frustum culling.
791 // Revision 1.12 1998/05/23 14:09:23 curt
792 // Added tile.cxx and tile.hxx.
793 // Working on rewriting the tile management system so a tile is just a list
794 // fragments, and the fragment record contains the display list for that fragment.
796 // Revision 1.11 1998/05/20 20:53:55 curt
797 // Moved global ref point and radius (bounding sphere info, and offset) to
798 // data file rather than calculating it on the fly.
799 // Fixed polygon winding problem in scenery generation stage rather than
800 // compensating for it on the fly.
801 // Made a fgTILECACHE class.
803 // Revision 1.10 1998/05/17 16:59:34 curt
804 // Frist pass at view frustum culling now operational.
806 // Revision 1.9 1998/05/16 13:09:58 curt
807 // Beginning to add support for view frustum culling.
808 // Added some temporary code to calculate bouding radius, until the
809 // scenery generation tools and scenery can be updated.
811 // Revision 1.8 1998/05/07 23:15:21 curt
812 // Fixed a glTexImage2D() usage bug where width and height were mis-swapped.
813 // Added support for --tile-radius=n option.
815 // Revision 1.7 1998/05/06 03:16:42 curt
816 // Added an option to control square tile radius.
818 // Revision 1.6 1998/05/02 01:52:18 curt
819 // Playing around with texture coordinates.
821 // Revision 1.5 1998/04/30 12:35:32 curt
822 // Added a command line rendering option specify smooth/flat shading.
824 // Revision 1.4 1998/04/27 03:30:14 curt
825 // Minor transformation adjustments to try to keep scenery tiles closer to
826 // (0, 0, 0) GLfloats run out of precision at the distances we need to model
827 // the earth, but we can do a bunch of pre-transformations using double math
828 // and then cast to GLfloat once everything is close in where we have less
829 // precision problems.
831 // Revision 1.3 1998/04/25 22:06:32 curt
832 // Edited cvs log messages in source files ... bad bad bad!
834 // Revision 1.2 1998/04/24 00:51:09 curt
835 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
836 // Tweaked the scenery file extentions to be "file.obj" (uncompressed)
837 // or "file.obz" (compressed.)
839 // Revision 1.1 1998/04/22 13:22:48 curt
840 // C++ - ifing the code a bit.
842 // Revision 1.25 1998/04/18 04:14:07 curt
843 // Moved fg_debug.c to it's own library.
845 // Revision 1.24 1998/04/14 02:23:18 curt
846 // Code reorganizations. Added a Lib/ directory for more general libraries.
848 // Revision 1.23 1998/04/08 23:30:08 curt
849 // Adopted Gnu automake/autoconf system.
851 // Revision 1.22 1998/04/03 22:11:38 curt
852 // Converting to Gnu autoconf system.
854 // Revision 1.21 1998/03/23 21:23:05 curt
855 // Debugging output tweaks.
857 // Revision 1.20 1998/03/14 00:30:51 curt
858 // Beginning initial terrain texturing experiments.
860 // Revision 1.19 1998/02/20 00:16:25 curt
861 // Thursday's tweaks.
863 // Revision 1.18 1998/02/19 13:05:54 curt
864 // Incorporated some HUD tweaks from Michelle America.
865 // Tweaked the sky's sunset/rise colors.
866 // Other misc. tweaks.
868 // Revision 1.17 1998/02/16 13:39:46 curt
869 // Miscellaneous weekend tweaks. Fixed? a cache problem that caused whole
870 // tiles to occasionally be missing.
872 // Revision 1.16 1998/02/12 21:59:53 curt
873 // Incorporated code changes contributed by Charlie Hotchkiss
874 // <chotchkiss@namg.us.anritsu.com>
876 // Revision 1.14 1998/02/09 21:30:19 curt
877 // Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
879 // Revision 1.13 1998/02/07 15:29:46 curt
880 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
881 // <chotchkiss@namg.us.anritsu.com>
883 // Revision 1.12 1998/02/01 03:39:55 curt
886 // Revision 1.11 1998/01/31 00:43:27 curt
887 // Added MetroWorks patches from Carmen Volpe.
889 // Revision 1.10 1998/01/29 00:51:40 curt
890 // First pass at tile cache, dynamic tile loading and tile unloading now works.
892 // Revision 1.9 1998/01/27 03:26:44 curt
893 // Playing with new fgPrintf command.
895 // Revision 1.8 1998/01/27 00:48:04 curt
896 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
897 // system and commandline/config file processing code.
899 // Revision 1.7 1998/01/26 15:55:25 curt
900 // Progressing on building dynamic scenery system.
902 // Revision 1.6 1998/01/24 00:03:30 curt
905 // Revision 1.5 1998/01/19 19:27:18 curt
906 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
907 // This should simplify things tremendously.
909 // Revision 1.4 1998/01/19 18:40:38 curt
910 // Tons of little changes to clean up the code and to remove fatal errors
911 // when building with the c++ compiler.
913 // Revision 1.3 1998/01/13 00:23:11 curt
914 // Initial changes to support loading and management of scenery tiles. Note,
915 // there's still a fair amount of work left to be done.
917 // Revision 1.2 1998/01/08 02:22:27 curt
918 // Continue working on basic features.
920 // Revision 1.1 1998/01/07 23:50:51 curt
921 // "area" renamed to "tile"
923 // Revision 1.2 1998/01/07 03:29:29 curt
924 // Given an arbitrary lat/lon, we can now:
925 // generate a unique index for the chunk containing the lat/lon
926 // generate a path name to the chunk file
927 // build a list of the indexes of all the nearby areas.
929 // Revision 1.1 1998/01/07 02:05:48 curt