]> git.mxchange.org Git - flightgear.git/blobdiff - Scenery/tilemgr.cxx
C++ ifying ...
[flightgear.git] / Scenery / tilemgr.cxx
index 7d5d82ea5227cd99873f7285be922cf39a1e9658..09e81d18f1b4886e27c18c94d09073f1ebe245e0 100644 (file)
 #include <GL/glut.h>
 #include <XGL/xgl.h>
 
-#include <Aircraft/aircraft.h>
+#include <Aircraft/aircraft.hxx>
 
 #include <Bucket/bucketutils.h>
 #include <Debug/fg_debug.h>
 #include <Include/fg_constants.h>
-#include <Include/fg_types.h>
 #include <Main/options.hxx>
 #include <Main/views.hxx>
-#include <Math/fg_geodesy.h>
+#include <Math/fg_geodesy.hxx>
 #include <Math/mat3.h>
+#include <Math/point3d.hxx>
 #include <Math/polar3d.hxx>
 #include <Math/vector.hxx>
-#include <Weather/weather.h>
+#include <Objects/material.hxx>
+#include <Objects/obj.hxx>
+#include <Weather/weather.hxx>
 
-#include "material.hxx"
-#include "obj.hxx"
 #include "scenery.hxx"
+#include "tile.hxx"
 #include "tilecache.hxx"
 
 
+// to test clipping speedup in fgTileMgrRender()
+#if defined ( USE_FAST_FOV_CLIP )
+  // #define TEST_FOV_CLIP
+  // #define TEST_ELEV
+#endif
+
+
 #define FG_LOCAL_X_Y         81  // max(o->tile_diameter) ** 2
 
 #define FG_SQUARE( X ) ( (X) * (X) )
 
+#ifdef WIN32
+#  define FG_MEM_COPY(to,from,n)       memcpy(to, from, n)
+#else
+#  define FG_MEM_COPY(to,from,n)       bcopy(from, to, n)
+#endif
 
 // closest (potentially viewable) tiles, centered on current tile.
 // This is an array of pointers to cache indexes.
@@ -84,9 +97,9 @@ void fgTileMgrLoadTile( fgBUCKET *p, int *index) {
           p->lon, p->lat, p->x, p->y);
     
     // if not in cache, load tile into the next available slot
-    if ( (*index = c->Exists(p)) < 0 ) {
-       *index = c->NextAvail();
-       c->EntryFillIn(*index, p);
+    if ( (*index = c->exists(p)) < 0 ) {
+       *index = c->next_avail();
+       c->fill_in(*index, p);
     }
 
     fgPrintf( FG_TERRAIN, FG_DEBUG, "Selected cache index of %d\n", *index);
@@ -127,7 +140,7 @@ int fgTileMgrUpdate( void ) {
                  tile_diameter * tile_diameter);
 
        // wipe/initialize tile cache
-       c->Init();
+       c->init();
 
        // build the local area list and update cache
        for ( j = 0; j < tile_diameter; j++ ) {
@@ -218,14 +231,14 @@ int fgTileMgrUpdate( void ) {
 
 
 // Calculate shortest distance from point to line
-static double point_line_dist_squared( fgPoint3d *tc, fgPoint3d *vp, 
+static double point_line_dist_squared( const Point3D& tc, const Point3D& vp, 
                                       MAT3vec d )
 {
     MAT3vec p, p0;
     double dist;
 
-    p[0] = tc->x; p[1] = tc->y; p[2] = tc->z;
-    p0[0] = vp->x; p0[1] = vp->y; p0[2] = vp->z;
+    p[0] = tc.x(); p[1] = tc.y(); p[2] = tc.z();
+    p0[0] = vp.x(); p0[1] = vp.y(); p0[2] = vp.z();
 
     dist = fgPointLineSquared(p, p0, d);
 
@@ -236,21 +249,73 @@ static double point_line_dist_squared( fgPoint3d *tc, fgPoint3d *vp,
 
 
 // Calculate if point/radius is inside view frustum
-static int viewable( fgPoint3d *cp, double radius ) {
+static int viewable( const Point3D& cp, double radius ) {
+    int viewable = 1; // start by assuming it's viewable
+    double x1, y1;
+
+/********************************/
+#if defined( USE_FAST_FOV_CLIP ) // views.hxx
+/********************************/
+       
+    MAT3vec eye;       
+    double *mat;
+    double x, y, z;
+
+    x = cp.x();
+    y = cp.y();
+    z = cp.z();
+       
+    mat = (double *)(current_view.WORLD_TO_EYE);
+       
+    eye[2] =  x*mat[2] + y*mat[6] + z*mat[10] + mat[14];
+       
+    // Check near and far clip plane
+    if( ( eye[2] > radius ) ||
+       ( eye[2] + radius + current_weather.visibility < 0) )
+    {
+       return(0);
+    }
+       
+    eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * current_view.slope_x;
+
+    // check right and left clip plane (from eye perspective)
+    x1 = radius * current_view.fov_x_clip;
+    if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) )
+    {
+       return(0);
+    }
+       
+    eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) * current_view.slope_y;
+
+    // check bottom and top clip plane (from eye perspective)
+    y1 = radius * current_view.fov_y_clip;
+    if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) )
+    {
+       return(0);
+    }
+
+/********************************/     
+#else // DO NOT USE_FAST_FOV_CLIP
+/********************************/     
+
     fgVIEW *v;
     MAT3hvec world, eye;
-    int viewable = 1; // start by assuming it's viewable
-    double x0, x1, y1, slope;
+    double x0, slope;
 
     v = &current_view;
 
     MAT3_SET_HVEC(world, cp->x, cp->y, cp->z, 1.0);
-    MAT3mult_vec(eye, world, v->WORLD_TO_EYE);
+    // MAT3mult_vec(eye, world, v->WORLD_TO_EYE);
     // printf( "\nworld -> eye = %.2f %.2f %.2f  radius = %.2f\n", 
     //         eye[0], eye[1], eye[2], radius);
 
+    // Use lazy evaluation for calculating eye hvec.
+#define vec world
+#define mat v->WORLD_TO_EYE
+    eye[2] = vec[0]*mat[0][2]+vec[1]*mat[1][2]+vec[2]*mat[2][2]+mat[3][2];
+
     // Check near clip plane
-    if ( eye[2] - radius > 0.0 ) {
+    if ( eye[2] > radius ) {
        return(0);
     }
 
@@ -264,82 +329,214 @@ static int viewable( fgPoint3d *cp, double radius ) {
     x1 = v->cos_fov_x * radius;
     y1 = v->sin_fov_x * radius;
     slope = v->slope_x;
-    x0 = x1 - y1 / slope;
+    eye[0] = vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0];
 
-    // printf("(r) x1 = %.2f  y1 = %.2f\n", x1, y1);
-    // printf("eye[0] = %.2f  eye[2] = %.2f\n", eye[0], eye[2]);
-    // printf("(r) x0 = %.2f  slope_x = %.2f  radius = %.2f\n", 
-    //        x0, slope, radius);
-
-    if ( eye[2] > slope * (eye[0] - x0) ) {
-       return(0);
+    if ( eye[2] > ((slope * (eye[0] - x1)) + y1) ) {
+       return( false );
     }
 
     // check left clip plane (from eye perspective)
-    x1 = -x1;
-    slope = -slope;
-    x0 = x1 - y1 / slope;
-
-    // printf("(r) x1 = %.2f  y1 = %.2f\n", x1, y1);
-    // printf("eye[0] = %.2f  eye[2] = %.2f\n", eye[0], eye[2]);
-    // printf("(r) x0 = %.2f  slope_x = %.2f  radius = %.2f\n", 
-    //        x0, slope, radius);
-
-    if ( eye[2] > slope * (eye[0] - x0) ) {
-       return(0);
+    if ( eye[2] > -((slope * (eye[0] + x1)) - y1) ) {
+       return( false );
     }
 
     // check bottom clip plane (from eye perspective)
     x1 = -(v->cos_fov_y) * radius;
     y1 = v->sin_fov_y * radius;
     slope = v->slope_y;
-    x0 = x1 - y1 / slope;
-
-    // printf("(r) x1 = %.2f  y1 = %.2f\n", x1, y1);
-    // printf("eye[1] = %.2f  eye[2] = %.2f\n", eye[1], eye[2]);
-    // printf("(r) x0 = %.2f  slope_y = %.2f  radius = %.2f\n", 
-    //       x0, slope, radius);
+    eye[1] = vec[0]*mat[0][1]+vec[1]*mat[1][1]+vec[2]*mat[2][1]+mat[3][1];
+#undef vec
+#undef mat
 
-    if ( eye[2] > slope * (eye[1] - x0) ) {
-       return(0);
+    if ( eye[2] > ((slope * (eye[1] - x1)) + y1) ) {
+       return( false );
     }
 
     // check top clip plane (from eye perspective)
-    x1 = -x1;
-    slope = -slope;
-    x0 = x1 - y1 / slope;
+    if ( eye[2] > -((slope * (eye[1] + x1)) - y1) ) {
+       return( false );
+    }
 
-    // printf("(r) x1 = %.2f  y1 = %.2f\n", x1, y1);
-    // printf("eye[1] = %.2f  eye[2] = %.2f\n", eye[1], eye[2]);
-    // printf("(r) x0 = %.2f  slope_y = %.2f  radius = %.2f\n", 
-    //        x0, slope, radius);
+#endif // defined( USE_FAST_FOV_CLIP )
+       
+    return(viewable);
+}
 
-    if ( eye[2] > slope * (eye[1] - x0) ) {
-       return(0);
+
+// NEW 
+
+// inrange() IS THIS POINT WITHIN POSSIBLE VIEWING RANGE ?
+//     calculate distance from vertical tangent line at
+//     current position to center of object.
+//     this is equivalent to
+//     dist = point_line_dist_squared( &(t->center), &(v->abs_view_pos), 
+//                                     v->local_up );
+//     if ( dist < FG_SQUARE(t->bounding_radius) ) {
+//
+// the compiler should inline this for us
+
+static int
+inrange( const double radius, const Point3D& center, const Point3D& vp,
+        const MAT3vec up)
+{
+    MAT3vec u, u1, v;
+    // double tmp;
+       
+    // u = p - p0
+    u[0] = center.x() - vp.x();
+    u[1] = center.y() - vp.y();
+    u[2] = center.z() - vp.z();
+       
+    // calculate the projection, u1, of u along d.
+    // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
+       
+    MAT3_SCALE_VEC(u1, up,
+                  (MAT3_DOT_PRODUCT(u, up) / MAT3_DOT_PRODUCT(up, up)) );
+    
+    // v = u - u1 = vector from closest point on line, p1, to the
+    // original point, p.
+    MAT3_SUB_VEC(v, u, u1);
+       
+    return( FG_SQUARE(radius) >= MAT3_DOT_PRODUCT(v, v));
+}
+
+
+// Determine scenery altitude.  Normally this just happens when we
+// render the scene, but we'd also like to be able to do this
+// explicitely.  lat & lon are in radians.  abs_view_pos in meters.
+// Returns result in meters.
+double fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ) {
+    fgTILECACHE *c;
+    fgTILE *t;
+    // fgVIEW *v;
+    fgFRAGMENT *frag_ptr;
+    fgBUCKET p;
+    Point3D earth_center, result;
+    Point3D pp;
+    MAT3vec local_up;
+    list < fgFRAGMENT > :: iterator current;
+    list < fgFRAGMENT > :: iterator last;
+    double dist, lat_geod, alt, sea_level_r;
+    // double x, y, z;
+    int index;
+
+    c = &global_tile_cache;
+    // v = &current_view;
+
+    local_up[0] = abs_view_pos.x();
+    local_up[1] = abs_view_pos.y();
+    local_up[2] = abs_view_pos.z();
+
+    // Find current translation offset
+    fgBucketFind(lon * RAD_TO_DEG, lat * RAD_TO_DEG, &p);
+    index = c->exists(&p);
+    t = c->get_tile(index);
+
+    scenery.next_center = t->center;
+    
+    earth_center.setvals(0.0, 0.0, 0.0);
+
+    fgPrintf( FG_TERRAIN, FG_DEBUG, 
+             "Pos = (%.2f, %.2f) Current bucket = %d %d %d %d  Index = %ld\n", 
+             lon * RAD_TO_DEG, lat * RAD_TO_DEG,
+             p.lon, p.lat, p.x, p.y, fgBucketGenIndex(&p) );
+
+    // calculate tile offset
+    // x = (t->offset.x = t->center.x - scenery.center.x);
+    // y = (t->offset.y = t->center.y - scenery.center.y);
+    // z = (t->offset.z = t->center.z - scenery.center.z);
+    
+    // calc current terrain elevation calculate distance from
+    // vertical tangent line at current position to center of
+    // tile.
+       
+    /* printf("distance squared = %.2f, bounding radius = %.2f\n", 
+       point_line_dist_squared(&(t->offset), &(v->view_pos), 
+       v->local_up), t->bounding_radius); */
+
+    dist = point_line_dist_squared( t->center, abs_view_pos, local_up );
+    if ( dist < FG_SQUARE(t->bounding_radius) ) {
+
+       // traverse fragment list for tile
+       current = t->fragment_list.begin();
+       last = t->fragment_list.end();
+
+       for ( ; current != last; ++current ) {
+           frag_ptr = &(*current);
+           /* printf("distance squared = %.2f, bounding radius = %.2f\n", 
+              point_line_dist_squared( &(frag_ptr->center), 
+              &abs_view_pos), local_up),
+              frag_ptr->bounding_radius); */
+
+           dist = point_line_dist_squared( frag_ptr->center,
+                                           abs_view_pos,
+                                           local_up);
+           if ( dist <= FG_SQUARE(frag_ptr->bounding_radius) ) {
+               if ( frag_ptr->intersect( abs_view_pos, 
+                                         earth_center, 0, result ) ) {
+                   // compute geocentric coordinates of tile center
+                   pp = fgCartToPolar3d(result);
+                   // convert to geodetic coordinates
+                   fgGeocToGeod(pp.lat(), pp.radius(), &lat_geod, 
+                                &alt, &sea_level_r);
+                   // printf("alt = %.2f\n", alt);
+                   // exit since we found an intersection
+                   return(alt);
+               }
+           }
+       }
     }
 
-    return(viewable);
+    printf("no terrain intersection found\n");
+    return(0);
+}
+
+
+// NEW for legibility
+
+// update this tile's geometry for current view
+// The Compiler should inline this
+static void
+update_tile_geometry( fgTILE *t, GLdouble *MODEL_VIEW)
+{
+    GLdouble *m;
+    double x, y, z;
+       
+    // calculate tile offset
+    t->offset = t->center - scenery.center;
+
+    x = t->offset.x();
+    y = t->offset.y();
+    z = t->offset.z();
+       
+    m = t->model_view;
+       
+    // Calculate the model_view transformation matrix for this tile
+    FG_MEM_COPY( m, MODEL_VIEW, 16*sizeof(GLdouble) );
+    
+    // This is equivalent to doing a glTranslatef(x, y, z);
+    m[12] += (m[0]*x + m[4]*y + m[8] *z);
+    m[13] += (m[1]*x + m[5]*y + m[9] *z);
+    m[14] += (m[2]*x + m[6]*y + m[10]*z);
+    // m[15] += (m[3]*x + m[7]*y + m[11]*z);
+    // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
+    // so m[15] is unchanged
 }
 
 
 // Render the local tiles
 void fgTileMgrRender( void ) {
-    fgTILECACHE *c;
     fgFLIGHT *f;
-    fgTILE *t, *last_tile_ptr;
+    fgTILECACHE *c;
+    fgTILE *t;
     fgVIEW *v;
-    fgBUCKET p;
-    fgPoint3d frag_offset, pp;
-    fgPoint3d earth_center, result;
+    Point3D frag_offset;
     fgFRAGMENT *frag_ptr;
     fgMATERIAL *mtl_ptr;
-    GLdouble *m;
-    double dist, min_dist, lat_geod, alt, sea_level_r;
-    double x, y, z;
     list < fgFRAGMENT > :: iterator current;
     list < fgFRAGMENT > :: iterator last;
-    int i, j, size;
-    int tile_diameter, textures;
+    int i;
+    int tile_diameter;
     int index;
     int culled = 0;
     int drawn = 0;
@@ -349,101 +546,31 @@ void fgTileMgrRender( void ) {
     v = &current_view;
 
     tile_diameter = current_options.get_tile_diameter();
-    textures = current_options.get_textures();
-
-    // Find current translation offset
-    fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p);
-    index = c->Exists(&p);
-    t = c->GetTile(index);
-
-    scenery.next_center.x = t->center.x;
-    scenery.next_center.y = t->center.y;
-    scenery.next_center.z = t->center.z;
-
-    earth_center.x = 0.0;
-    earth_center.y = 0.0;
-    earth_center.z = 0.0;
-
-    fgPrintf( FG_TERRAIN, FG_DEBUG, 
-             "Pos = (%.2f, %.2f) Current bucket = %d %d %d %d  Index = %ld\n", 
-             FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG,
-             p.lon, p.lat, p.x, p.y, fgBucketGenIndex(&p) );
 
+    scenery.cur_elev = fgTileMgrCurElev( FG_Longitude, FG_Latitude, 
+                                        v->abs_view_pos );
     // initialize the transient per-material fragment lists
     material_mgr.init_transient_material_lists();
-    min_dist = 100000.0;
-
+   
     // Pass 1
     // traverse the potentially viewable tile list
     for ( i = 0; i < (tile_diameter * tile_diameter); i++ ) {
        index = tiles[i];
        // fgPrintf( FG_TERRAIN, FG_DEBUG, "Index = %d\n", index);
-       t = c->GetTile(index);
+       t = c->get_tile(index);
 
        // calculate tile offset
-       x = (t->offset.x = t->center.x - scenery.center.x);
-       y = (t->offset.y = t->center.y - scenery.center.y);
-       z = (t->offset.z = t->center.z - scenery.center.z);
-
-       m = t->model_view;
-       for ( j = 0; j < 16; j++ ) {
-           m[j] = v->MODEL_VIEW[j];
-       }
-
-       // Calculate the model_view transformation matrix for this tile
-       // This is equivalent to doing a glTranslatef(x, y, z);
-       m[12] = m[0] * x + m[4] * y + m[8]  * z + m[12];
-       m[13] = m[1] * x + m[5] * y + m[9]  * z + m[13];
-       m[14] = m[2] * x + m[6] * y + m[10] * z + m[14];
-       m[15] = m[3] * x + m[7] * y + m[11] * z + m[15];
-
-       // temp ... calc current terrain elevation
-       // calculate distance from vertical tangent line at
-       // current position to center of tile.
-       
-       /* printf("distance squared = %.2f, bounding radius = %.2f\n", 
-              point_line_dist_squared(&(t->offset), &(v->view_pos), 
-              v->local_up), t->bounding_radius); */
-
-       dist = point_line_dist_squared( &(t->center), &(v->abs_view_pos), 
-                                       v->local_up );
-       if ( dist < FG_SQUARE(t->bounding_radius) ) {
-
-           // traverse fragment list for tile
-           current = t->fragment_list.begin();
-           last = t->fragment_list.end();
-
-           while ( current != last ) {
-               frag_ptr = &(*current);
-               current++;
-               /* printf("distance squared = %.2f, bounding radius = %.2f\n", 
-                      point_line_dist_squared( &(frag_ptr->center), 
-                                       &(v->abs_view_pos), v->local_up),
-                      frag_ptr->bounding_radius); */
-
-               dist = point_line_dist_squared( &(frag_ptr->center), 
-                                       &(v->abs_view_pos), v->local_up);
-               if ( dist <= FG_SQUARE(frag_ptr->bounding_radius) ) {
-                   if ( frag_ptr->intersect( &(v->abs_view_pos), 
-                                             &earth_center, 0, &result ) ) {
-                       // compute geocentric coordinates of tile center
-                       pp = fgCartToPolar3d(result);
-                       // convert to geodetic coordinates
-                       fgGeocToGeod(pp.lat, pp.radius, &lat_geod, 
-                                    &alt, &sea_level_r);
-                       // printf("alt = %.2f\n", alt);
-                       scenery.cur_elev = alt;
-                       // exit this loop since we found an intersection
-                       break;
-                   }
-               }
-           }
-       }
+       t->SetOffset( scenery.center );
 
        // Course (tile based) culling
-       if ( viewable(&(t->offset), t->bounding_radius) ) {
+       if ( viewable(t->offset, t->bounding_radius) ) {
            // at least a portion of this tile could be viewable
            
+           // Calculate the model_view transformation matrix for this tile
+           // This is equivalent to doing a glTranslatef(x, y, z);
+           t->UpdateViewMatrix( v->MODEL_VIEW );
+
            // xglPushMatrix();
            // xglTranslatef(t->offset.x, t->offset.y, t->offset.z);
 
@@ -451,28 +578,22 @@ void fgTileMgrRender( void ) {
            current = t->fragment_list.begin();
            last = t->fragment_list.end();
 
-           while ( current != last ) {
+           for ( ; current != last; ++current ) {
                frag_ptr = &(*current);
-               current++;
                
                if ( frag_ptr->display_list >= 0 ) {
                    // Fine (fragment based) culling
-                   frag_offset.x = frag_ptr->center.x - scenery.center.x;
-                   frag_offset.y = frag_ptr->center.y - scenery.center.y;
-                   frag_offset.z = frag_ptr->center.z - scenery.center.z;
+                   frag_offset = frag_ptr->center - scenery.center;
 
-                   if ( viewable(&frag_offset, frag_ptr->bounding_radius*2) ) {
+                   if ( viewable(frag_offset, frag_ptr->bounding_radius*2) ) {
                        // add to transient per-material property fragment list
                        // frag_ptr->tile_offset.x = t->offset.x;
                        // frag_ptr->tile_offset.y = t->offset.y;
                        // frag_ptr->tile_offset.z = t->offset.z;
 
-                       mtl_ptr = (fgMATERIAL *)(frag_ptr->material_ptr);
+                       mtl_ptr = frag_ptr->material_ptr;
                        // printf(" lookup = %s\n", mtl_ptr->texture_name);
-                       if ( mtl_ptr->list_size < FG_MAX_MATERIAL_FRAGS ) {
-                           mtl_ptr->list[mtl_ptr->list_size] = frag_ptr;
-                           (mtl_ptr->list_size)++;
-                       } else {
+                       if ( ! mtl_ptr->append_sort_list( frag_ptr ) ) {
                            fgPrintf( FG_TERRAIN, FG_ALERT,
                                      "Overran material sorting array\n" );
                        }
@@ -505,65 +626,81 @@ void fgTileMgrRender( void ) {
     // Pass 2
     // traverse the transient per-material fragment lists and render
     // out all fragments for each material property.
-    map < string, fgMATERIAL, less<string> > :: iterator mapcurrent = 
-       material_mgr.material_map.begin();
-    map < string, fgMATERIAL, less<string> > :: iterator maplast = 
-       material_mgr.material_map.end();
-
     xglPushMatrix();
-
-    while ( mapcurrent != maplast ) {
-        // (char *)key = (*mapcurrent).first;
-        // (fgMATERIAL)value = (*mapcurrent).second;
-       mtl_ptr = &(*mapcurrent).second;
-
-       last_tile_ptr = NULL;
-
-       size = mtl_ptr->list_size;
-       if ( size > 0 ) {
-           if ( textures ) {
-#ifdef GL_VERSION_1_1
-               xglBindTexture(GL_TEXTURE_2D, mtl_ptr->texture_id);
-#elif GL_EXT_texture_object
-               xglBindTextureEXT(GL_TEXTURE_2D, mtl_ptr->texture_id);
-#else
-#  error port me
-#endif
-           } else {
-               xglMaterialfv (GL_FRONT, GL_AMBIENT, mtl_ptr->ambient);
-               xglMaterialfv (GL_FRONT, GL_DIFFUSE, mtl_ptr->diffuse);
-           }
-
-           // printf("traversing = %s, size = %d\n", 
-           //       mtl_ptr->texture_name, size);
-           for ( i = 0; i < size; i++ ) {
-               frag_ptr = mtl_ptr->list[i];
-               
-               if ( frag_ptr->tile_ptr == last_tile_ptr ) {
-                   // same tile as last time, no transform necessary
-               } else {
-                   // new tile, new translate
-                   // xglLoadMatrixf( frag_ptr->matrix );
-                   t = (fgTILE *)(frag_ptr->tile_ptr);
-                   xglLoadMatrixd(t->model_view );
-               }
-           
-               // Woohoo!!!  We finally get to draw something!
-               // printf("  display_list = %d\n", frag_ptr->display_list);
-               xglCallList(frag_ptr->display_list);
-
-               last_tile_ptr = (fgTILE *)(frag_ptr->tile_ptr);
-           }
-       }
-
-        *mapcurrent++;
-    }
-
+    material_mgr.render_fragments();
     xglPopMatrix();
 }
 
 
 // $Log$
+// Revision 1.40  1998/10/17 01:34:28  curt
+// C++ ifying ...
+//
+// Revision 1.39  1998/10/16 00:55:50  curt
+// Converted to Point3D class.
+//
+// Revision 1.38  1998/09/17 18:36:18  curt
+// Tweaks and optimizations by Norman Vine.
+//
+// Revision 1.37  1998/09/15 01:36:45  curt
+// cleaned up my fragment.num_faces hack :-) to use the STL (no need in
+// duplicating work.)
+// Tweaked fgTileMgrRender() do not calc tile matrix unless necessary.
+// removed some unneeded stuff from fgTileMgrCurElev()
+//
+// Revision 1.36  1998/09/14 12:45:26  curt
+// minor tweaks.
+//
+// Revision 1.35  1998/09/10 19:07:16  curt
+// /Simulator/Objects/fragment.hxx
+//   Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
+//
+// ./Simulator/Objects/material.cxx
+// ./Simulator/Objects/material.hxx
+//   Made fgMATERIAL and fgMATERIAL_MGR bona fide classes with private
+//   data members - that should keep the rabble happy :)
+//
+// ./Simulator/Scenery/tilemgr.cxx
+//   In viewable() delay evaluation of eye[0] and eye[1] in until they're
+//   actually needed.
+//   Change to fgTileMgrRender() to call fgMATERIAL_MGR::render_fragments()
+//   method.
+//
+// ./Include/fg_stl_config.h
+// ./Include/auto_ptr.hxx
+//   Added support for g++ 2.7.
+//   Further changes to other files are forthcoming.
+//
+// Brief summary of changes required for g++ 2.7.
+//   operator->() not supported by iterators: use (*i).x instead of i->x
+//   default template arguments not supported,
+//   <functional> doesn't have mem_fun_ref() needed by callbacks.
+//   some std include files have different names.
+//   template member functions not supported.
+//
+// Revision 1.34  1998/09/09 20:58:09  curt
+// Tweaks to loop constructs with STL usage.
+//
+// Revision 1.33  1998/09/08 15:05:10  curt
+// Optimization by Norman Vine.
+//
+// Revision 1.32  1998/08/25 16:52:44  curt
+// material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
+//   ../Objects
+//
+// Revision 1.31  1998/08/24 20:11:40  curt
+// Tweaks ...
+//
+// Revision 1.30  1998/08/22  14:49:59  curt
+// Attempting to iron out seg faults and crashes.
+// Did some shuffling to fix a initialization order problem between view
+// position, scenery elevation.
+//
+// Revision 1.29  1998/08/20 15:12:06  curt
+// Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
+// the need for "void" pointers and casts.
+// Quick hack to count the number of scenery polygons that are being drawn.
+//
 // Revision 1.28  1998/08/12 21:13:06  curt
 // material.cxx: don't load textures if they are disabled
 // obj.cxx: optimizations from Norman Vine