]> git.mxchange.org Git - flightgear.git/blobdiff - Scenery/tilemgr.cxx
Modifications to incorporate Jon S. Berndts flight model code.
[flightgear.git] / Scenery / tilemgr.cxx
index 7c63f048b3966befe939cb100599216178dce0d9..858966c04fa5d9219457a59b8e5726a9c7613f57 100644 (file)
@@ -130,10 +130,10 @@ static double point_line_dist_squared( const Point3D& tc, const Point3D& vp,
 // explicitely.  lat & lon are in radians.  abs_view_pos in meters.
 // Returns result in meters.
 double
-fgTileMgrCurElev( const fgBUCKET& p ) {
+fgTileMgrCurElevNEW( const fgBUCKET& p ) {
     fgTILE *t;
     fgFRAGMENT *frag_ptr;
-    Point3D abs_view_pos = current_view.abs_view_pos;
+    Point3D abs_view_pos = current_view.get_abs_view_pos();
     Point3D earth_center(0.0);
     Point3D result;
     MAT3vec local_up;
@@ -217,7 +217,8 @@ fgTileMgrCurElev( const fgBUCKET& p ) {
        }
     }
 
-    cout << "(new) no terrain intersection found\n";
+    FG_LOG( FG_TERRAIN, FG_INFO, "(new) no terrain intersection found" );
+
     return 0.0;
 }
 
@@ -227,7 +228,7 @@ fgTileMgrCurElev( const fgBUCKET& p ) {
 // explicitely.  lat & lon are in radians.  abs_view_pos in meters.
 // Returns result in meters.
 double
-fgTileMgrCurElevOLD( double lon, double lat, const Point3D& abs_view_pos ) {
+fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ) {
     fgTILECACHE *c;
     fgTILE *t;
     // fgVIEW *v;
@@ -247,6 +248,8 @@ fgTileMgrCurElevOLD( double lon, double lat, const Point3D& abs_view_pos ) {
     local_up[1] = abs_view_pos.y();
     local_up[2] = abs_view_pos.z();
 
+    FG_LOG( FG_TERRAIN, FG_DEBUG, "Absolute view pos = " << abs_view_pos );
+
     // Find current translation offset
     fgBucketFind(lon * RAD_TO_DEG, lat * RAD_TO_DEG, &p);
     index = c->exists(p);
@@ -259,8 +262,6 @@ fgTileMgrCurElevOLD( double lon, double lat, const Point3D& abs_view_pos ) {
 
     scenery.next_center = t->center;
     
-    // earth_center = Point3D(0.0, 0.0, 0.0);
-
     FG_LOG( FG_TERRAIN, FG_DEBUG, 
            "Pos = (" << lon * RAD_TO_DEG << ", " << lat * RAD_TO_DEG
            << ")  Current bucket = " << p 
@@ -322,7 +323,8 @@ fgTileMgrCurElevOLD( double lon, double lat, const Point3D& abs_view_pos ) {
        }
     }
 
-    cout << "(old) no terrain intersection found\n";
+    FG_LOG( FG_TERRAIN, FG_INFO, "(old) no terrain intersection found" );
+
     return 0.0;
 }
 
@@ -331,14 +333,14 @@ fgTileMgrCurElevOLD( double lon, double lat, const Point3D& abs_view_pos ) {
 // the chunk isn't already in the cache, then read it from disk.
 int fgTileMgrUpdate( void ) {
     fgTILECACHE *c;
-    fgFLIGHT *f;
+    FGInterface *f;
     fgBUCKET p1, p2;
     static fgBUCKET p_last = {-1000, 0, 0, 0};
     int tile_diameter;
     int i, j, dw, dh;
 
     c = &global_tile_cache;
-    f = current_aircraft.flight;
+    f = current_aircraft.fdm_state;
 
     tile_diameter = current_options.get_tile_diameter();
 
@@ -354,6 +356,7 @@ int fgTileMgrUpdate( void ) {
        // First time through, initialize the system and load all
        // relavant tiles
 
+       FG_LOG( FG_TERRAIN, FG_INFO, "Updating Tile list for " << p1 );
        FG_LOG( FG_TERRAIN, FG_INFO, "  First time through ... " );
        FG_LOG( FG_TERRAIN, FG_INFO, "  Updating Tile list for " << p1 );
        FG_LOG( FG_TERRAIN, FG_INFO, "  Loading " 
@@ -443,7 +446,12 @@ int fgTileMgrUpdate( void ) {
     }
 
     // find our current elevation (feed in the current bucket to save work)
-    scenery.cur_elev = fgTileMgrCurElev( p1 );
+    Point3D geod_pos = Point3D( f->get_Longitude(), f->get_Latitude(), 0.0);
+    Point3D tmp_abs_view_pos = fgGeodToCart(geod_pos);
+
+    scenery.cur_elev = 
+       fgTileMgrCurElev( f->get_Longitude(), f->get_Latitude(), 
+                         tmp_abs_view_pos );
 
     p_last.lon = p1.lon;
     p_last.lat = p1.lat;
@@ -471,30 +479,32 @@ static int viewable( const Point3D& cp, double radius ) {
     y = cp.y();
     z = cp.z();
        
-    mat = (double *)(current_view.WORLD_TO_EYE);
+    mat = (double *)(current_view.get_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) )
+       ( eye[2] + radius + current_weather.get_visibility() < 0) )
     {
        return(0);
     }
        
-    eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * current_view.slope_x;
+    eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12])
+       * current_view.get_slope_x();
 
     // check right and left clip plane (from eye perspective)
-    x1 = radius * current_view.fov_x_clip;
+    x1 = radius * current_view.get_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;
+    eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) 
+       * current_view.get_slope_y();
 
     // check bottom and top clip plane (from eye perspective)
-    y1 = radius * current_view.fov_y_clip;
+    y1 = radius * current_view.get_fov_y_clip();
     if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) )
     {
        return(0);
@@ -526,7 +536,7 @@ static int viewable( const Point3D& cp, double radius ) {
     }
 
     // Check far clip plane
-    if ( eye[2] + radius < -current_weather.visibility ) {
+    if ( eye[2] + radius < -current_weather.get_visibility() ) {
        return(0);
     }
 
@@ -641,10 +651,10 @@ update_tile_geometry( fgTILE *t, GLdouble *MODEL_VIEW)
 
 // Render the local tiles
 void fgTileMgrRender( void ) {
-    fgFLIGHT *f;
+    FGInterface *f;
     fgTILECACHE *c;
     fgTILE *t;
-    fgVIEW *v;
+    FGView *v;
     Point3D frag_offset;
     fgFRAGMENT *frag_ptr;
     fgMATERIAL *mtl_ptr;
@@ -655,7 +665,7 @@ void fgTileMgrRender( void ) {
     int drawn = 0;
 
     c = &global_tile_cache;
-    f = current_aircraft.flight;
+    f = current_aircraft.fdm_state;
     v = &current_view;
 
     tile_diameter = current_options.get_tile_diameter();
@@ -684,7 +694,7 @@ void fgTileMgrRender( void ) {
            
            // Calculate the model_view transformation matrix for this tile
            // This is equivalent to doing a glTranslatef(x, y, z);
-           t->UpdateViewMatrix( v->MODEL_VIEW );
+           t->UpdateViewMatrix( v->get_MODEL_VIEW() );
 
            // xglPushMatrix();
            // xglTranslatef(t->offset.x, t->offset.y, t->offset.z);
@@ -731,9 +741,9 @@ void fgTileMgrRender( void ) {
     }
 
     if ( (drawn + culled) > 0 ) {
-       v->vfc_ratio = (double)culled / (double)(drawn + culled);
+       v->set_vfc_ratio( (double)culled / (double)(drawn + culled) );
     } else {
-       v->vfc_ratio = 0.0;
+       v->set_vfc_ratio( 0.0 );
     }
     // printf("drawn = %d  culled = %d  saved = %.2f\n", drawn, culled, 
     //        v->vfc_ratio);
@@ -748,6 +758,22 @@ void fgTileMgrRender( void ) {
 
 
 // $Log$
+// Revision 1.53  1999/02/05 21:29:16  curt
+// Modifications to incorporate Jon S. Berndts flight model code.
+//
+// Revision 1.52  1999/01/27 04:49:48  curt
+// Fixes so that the sim can start out at an airport below sea level.
+//
+// Revision 1.51  1998/12/09 18:50:33  curt
+// Converted "class fgVIEW" to "class FGView" and updated to make data
+// members private and make required accessor functions.
+//
+// Revision 1.50  1998/12/06 13:51:25  curt
+// Turned "struct fgWEATHER" into "class FGWeather".
+//
+// Revision 1.49  1998/12/05 15:54:26  curt
+// Renamed class fgFLIGHT to class FGState as per request by JSB.
+//
 // Revision 1.48  1998/12/05 14:20:21  curt
 // Looking into a terrain intersection problem.
 //