]> git.mxchange.org Git - flightgear.git/blobdiff - Main/views.cxx
Converted fgFLIGHT to a class.
[flightgear.git] / Main / views.cxx
index 903e694db8ee79185547e208a38a9a8ed19607d4..ae8491f2df8ce17cc8b5fb01fb54243f2dadb8c7 100644 (file)
 #  include <config.h>
 #endif
 
-#include <Debug/fg_debug.h>
-#include <Flight/flight.h>
+#include <Aircraft/aircraft.hxx>
+#include <Cockpit/panel.hxx>
+#include <Debug/logstream.hxx>
 #include <Include/fg_constants.h>
 #include <Math/mat3.h>
+#include <Math/point3d.hxx>
 #include <Math/polar3d.hxx>
 #include <Math/vector.hxx>
 #include <Scenery/scenery.hxx>
@@ -51,112 +53,276 @@ fgVIEW::fgVIEW( void ) {
 
 // Initialize a view structure
 void fgVIEW::Init( void ) {
-    fgPrintf( FG_VIEW, FG_INFO, "Initializing View parameters\n");
+    FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" );
 
     view_offset = 0.0;
     goal_view_offset = 0.0;
 
-    winWidth = 640;  // FG_DEFAULT_WIN_WIDTH
-    winHeight = 480; // FG_DEFAULT_WIN_HEIGHT
+    winWidth = current_options.get_xsize();
+    winHeight = current_options.get_ysize();
     win_ratio = (double) winWidth / (double) winHeight;
-    update_fov = TRUE;
+    update_fov = true;
 }
 
 
 // Update the field of view parameters
 void fgVIEW::UpdateFOV( fgOPTIONS *o ) {
-    double theta_x, theta_y;
+    double fov, theta_x, theta_y;
+
+    fov = o->get_fov();
        
     // printf("win_ratio = %.2f\n", win_ratio);
     // calculate sin() and cos() of fov / 2 in X direction;
-    theta_x = (o->fov * win_ratio * DEG_TO_RAD) / 2.0;
+    theta_x = (fov * win_ratio * DEG_TO_RAD) / 2.0;
     // printf("theta_x = %.2f\n", theta_x);
     sin_fov_x = sin(theta_x);
     cos_fov_x = cos(theta_x);
-    slope_x =  - cos_fov_x / sin_fov_x;
+    slope_x =  -cos_fov_x / sin_fov_x;
     // printf("slope_x = %.2f\n", slope_x);
 
+#if defined( USE_FAST_FOV_CLIP )
+    fov_x_clip = slope_x*cos_fov_x - sin_fov_x;
+#endif // defined( USE_FAST_FOV_CLIP )
+
     // calculate sin() and cos() of fov / 2 in Y direction;
-    theta_y = (o->fov * DEG_TO_RAD) / 2.0;
+    theta_y = (fov * DEG_TO_RAD) / 2.0;
     // printf("theta_y = %.2f\n", theta_y);
     sin_fov_y = sin(theta_y);
     cos_fov_y = cos(theta_y);
     slope_y = cos_fov_y / sin_fov_y;
     // printf("slope_y = %.2f\n", slope_y);
+
+#if defined( USE_FAST_FOV_CLIP )
+    fov_y_clip = -(slope_y*cos_fov_y + sin_fov_y);     
+#endif // defined( USE_FAST_FOV_CLIP )
+}
+
+
+// Basically, this is a modified version of the Mesa gluLookAt()
+// function that's been modified slightly so we can capture the
+// result before sending it off to OpenGL land.
+void fgVIEW::LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
+                    GLdouble centerx, GLdouble centery, GLdouble centerz,
+                    GLdouble upx, GLdouble upy, GLdouble upz ) {
+    GLdouble *m;
+    GLdouble x[3], y[3], z[3];
+    GLdouble mag;
+
+    m = current_view.MODEL_VIEW;
+
+    /* Make rotation matrix */
+
+    /* Z vector */
+    z[0] = eyex - centerx;
+    z[1] = eyey - centery;
+    z[2] = eyez - centerz;
+    mag = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] );
+    if (mag) {  /* mpichler, 19950515 */
+       z[0] /= mag;
+       z[1] /= mag;
+       z[2] /= mag;
+    }
+
+    /* Y vector */
+    y[0] = upx;
+    y[1] = upy;
+    y[2] = upz;
+
+    /* X vector = Y cross Z */
+    x[0] =  y[1]*z[2] - y[2]*z[1];
+    x[1] = -y[0]*z[2] + y[2]*z[0];
+    x[2] =  y[0]*z[1] - y[1]*z[0];
+    
+    /* Recompute Y = Z cross X */
+    y[0] =  z[1]*x[2] - z[2]*x[1];
+    y[1] = -z[0]*x[2] + z[2]*x[0];
+    y[2] =  z[0]*x[1] - z[1]*x[0];
+
+    /* mpichler, 19950515 */
+    /* cross product gives area of parallelogram, which is < 1.0 for
+     * non-perpendicular unit-length vectors; so normalize x, y here
+     */
+
+    mag = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] );
+    if (mag) {
+       x[0] /= mag;
+       x[1] /= mag;
+      x[2] /= mag;
+    }
+
+    mag = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] );
+    if (mag) {
+       y[0] /= mag;
+       y[1] /= mag;
+       y[2] /= mag;
+    }
+
+#define M(row,col)  m[col*4+row]
+    M(0,0) = x[0];  M(0,1) = x[1];  M(0,2) = x[2];  M(0,3) = 0.0;
+    M(1,0) = y[0];  M(1,1) = y[1];  M(1,2) = y[2];  M(1,3) = 0.0;
+    M(2,0) = z[0];  M(2,1) = z[1];  M(2,2) = z[2];  M(2,3) = 0.0;
+    // the following is part of the original gluLookAt(), but we are
+    // commenting it out because we know we are going to be doing a
+    // translation below which will set these values anyways
+    // M(3,0) = 0.0;   M(3,1) = 0.0;   M(3,2) = 0.0;   M(3,3) = 1.0;
+#undef M
+
+    // Translate Eye to Origin
+    // replaces: glTranslated( -eyex, -eyey, -eyez );
+
+    // this has been slightly modified from the original glTranslate()
+    // code because we know that coming into this m[12] = m[13] =
+    // m[14] = 0.0, and m[15] = 1.0;
+    m[12] = m[0] * -eyex + m[4] * -eyey + m[8]  * -eyez /* + m[12] */;
+    m[13] = m[1] * -eyex + m[5] * -eyey + m[9]  * -eyez /* + m[13] */;
+    m[14] = m[2] * -eyex + m[6] * -eyey + m[10] * -eyez /* + m[14] */;
+    m[15] = 1.0 /* m[3] * -eyex + m[7] * -eyey + m[11] * -eyez + m[15] */;
+
+    // xglMultMatrixd( m );
+    xglLoadMatrixd( m );
+}
+
+
+// Update the view volume, position, and orientation
+void fgVIEW::UpdateViewParams( void ) {
+    fgFLIGHT *f;
+    fgLIGHT *l;
+
+    f = current_aircraft.flight;
+    l = &cur_light_params;
+
+    UpdateViewMath(f);
+    UpdateWorldToEye(f);
+    
+    if ((current_options.get_panel_status() != panel_hist) &&                          (current_options.get_panel_status()))
+       {
+           fgPanelReInit( 0, 0, 1024, 768);
+       }
+
+    // if (!o->panel_status) {
+    // xglViewport( 0, (GLint)((winHeight) / 2 ) , 
+    // (GLint)(winWidth), (GLint)(winHeight) / 2 );
+    // Tell GL we are about to modify the projection parameters
+    // xglMatrixMode(GL_PROJECTION);
+    // xglLoadIdentity();
+    // gluPerspective(o->fov, win_ratio / 2.0, 1.0, 100000.0);
+    // } else {
+    if ( ! current_options.get_panel_status() ) {
+       xglViewport(0, 0 , (GLint)(winWidth), (GLint)(winHeight) );
+    } else {
+       xglViewport(0, (GLint)((winHeight)*0.5768), (GLint)(winWidth), 
+                    (GLint)((winHeight)*0.4232) );
+    }
+    // Tell GL we are about to modify the projection parameters
+    xglMatrixMode(GL_PROJECTION);
+    xglLoadIdentity();
+    if ( f->get_Altitude() * FEET_TO_METER - scenery.cur_elev > 10.0 ) {
+       gluPerspective(current_options.get_fov(), win_ratio, 10.0, 100000.0);
+    } else {
+       gluPerspective(current_options.get_fov(), win_ratio, 0.5, 100000.0);
+       // printf("Near ground, minimizing near clip plane\n");
+    }
+    // }
+
+    xglMatrixMode(GL_MODELVIEW);
+    xglLoadIdentity();
+    
+    // set up our view volume (default)
+    LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
+          view_pos.x() + view_forward[0], 
+              view_pos.y() + view_forward[1], 
+              view_pos.z() + view_forward[2],
+              view_up[0], view_up[1], view_up[2]);
+
+    // look almost straight up (testing and eclipse watching)
+    /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
+              view_pos.x() + view_up[0] + .001, 
+              view_pos.y() + view_up[1] + .001, 
+              view_pos.z() + view_up[2] + .001,
+              view_up[0], view_up[1], view_up[2]); */
+
+    // lock view horizontally towards sun (testing)
+    /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
+              view_pos.x() + surface_to_sun[0], 
+              view_pos.y() + surface_to_sun[1], 
+              view_pos.z() + surface_to_sun[2],
+              view_up[0], view_up[1], view_up[2]); */
+
+    // lock view horizontally towards south (testing)
+    /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
+              view_pos.x() + surface_south[0], 
+              view_pos.y() + surface_south[1], 
+              view_pos.z() + surface_south[2],
+              view_up[0], view_up[1], view_up[2]); */
+
+    // set the sun position
+    xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
+
+    panel_hist = current_options.get_panel_status();
 }
 
 
 // Update the view parameters
-void fgVIEW::Update( fgFLIGHT *f ) {
-    fgOPTIONS *o;
-    fgPoint3d p;
+void fgVIEW::UpdateViewMath( fgFLIGHT *f ) {
+    Point3D p;
     MAT3vec vec, forward, v0, minus_z;
     MAT3mat R, TMP, UP, LOCAL, VIEW;
     double ntmp;
 
-    o = &current_options;
-
-    if(update_fov == TRUE) {
+    if(update_fov == true) {
        // printf("Updating fov\n");
-       UpdateFOV(o);
-       update_fov = FALSE;
+       UpdateFOV(&current_options);
+       update_fov = false;
     }
                
-    scenery.center.x = scenery.next_center.x;
-    scenery.center.y = scenery.next_center.y;
-    scenery.center.z = scenery.next_center.z;
+    scenery.center = scenery.next_center;
 
     // printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x,
     //        scenery.center.y, scenery.center.z);
 
     // calculate the cartesion coords of the current lat/lon/0 elev
-    p.lon = FG_Longitude;
-    p.lat = FG_Lat_geocentric;
-    p.radius = FG_Sea_level_radius * FEET_TO_METER;
-
-    cur_zero_elev = fgPolarToCart3d(p);
+    p = Point3D( f->get_Longitude(), 
+                f->get_Lat_geocentric(), 
+                f->get_Sea_level_radius() * FEET_TO_METER );
 
-    cur_zero_elev.x -= scenery.center.x;
-    cur_zero_elev.y -= scenery.center.y;
-    cur_zero_elev.z -= scenery.center.z;
+    cur_zero_elev = fgPolarToCart3d(p) - scenery.center;
 
     // calculate view position in current FG view coordinate system
     // p.lon & p.lat are already defined earlier, p.radius was set to
     // the sea level radius, so now we add in our altitude.
-    if ( FG_Altitude * FEET_TO_METER > 
-        (scenery.cur_elev + 3.758099 * METER_TO_FEET) ) {
-       p.radius += FG_Altitude * FEET_TO_METER;
+    if ( f->get_Altitude() * FEET_TO_METER > 
+        (scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
+       p.setz( p.radius() + f->get_Altitude() * FEET_TO_METER );
     } else {
-       p.radius += scenery.cur_elev + 3.758099 * METER_TO_FEET;
+       p.setz( p.radius() + scenery.cur_elev + 0.5 * METER_TO_FEET );
     }
 
     abs_view_pos = fgPolarToCart3d(p);
+    view_pos = abs_view_pos - scenery.center;
 
-    view_pos.x = abs_view_pos.x - scenery.center.x;
-    view_pos.y = abs_view_pos.y - scenery.center.y;
-    view_pos.z = abs_view_pos.z - scenery.center.z;
-
-    fgPrintf( FG_VIEW, FG_DEBUG, "Absolute view pos = %.4f, %.4f, %.4f\n", 
-          abs_view_pos.x, abs_view_pos.y, abs_view_pos.z);
-    fgPrintf( FG_VIEW, FG_DEBUG, "Relative view pos = %.4f, %.4f, %.4f\n", 
-          view_pos.x, view_pos.y, view_pos.z);
+    FG_LOG( FG_VIEW, FG_DEBUG, "Absolute view pos = "
+           << abs_view_pos.x() << ", " 
+           << abs_view_pos.y() << ", " 
+           << abs_view_pos.z() );
+    FG_LOG( FG_VIEW, FG_DEBUG, "Relative view pos = "
+           << view_pos.x() << ", " << view_pos.y() << ", " << view_pos.z() );
 
     // Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw)
     // from FG_T_local_to_body[3][3]
 
     // Question: Why is the LaRCsim matrix arranged so differently
     // than the one we need???
-    LOCAL[0][0] = FG_T_local_to_body_33;
-    LOCAL[0][1] = -FG_T_local_to_body_32;
-    LOCAL[0][2] = -FG_T_local_to_body_31;
+    LOCAL[0][0] = f->get_T_local_to_body_33();
+    LOCAL[0][1] = -f->get_T_local_to_body_32();
+    LOCAL[0][2] = -f->get_T_local_to_body_31();
     LOCAL[0][3] = 0.0;
-    LOCAL[1][0] = -FG_T_local_to_body_23;
-    LOCAL[1][1] = FG_T_local_to_body_22;
-    LOCAL[1][2] = FG_T_local_to_body_21;
+    LOCAL[1][0] = -f->get_T_local_to_body_23();
+    LOCAL[1][1] = f->get_T_local_to_body_22();
+    LOCAL[1][2] = f->get_T_local_to_body_21();
     LOCAL[1][3] = 0.0;
-    LOCAL[2][0] = -FG_T_local_to_body_13;
-    LOCAL[2][1] = FG_T_local_to_body_12;
-    LOCAL[2][2] = FG_T_local_to_body_11;
+    LOCAL[2][0] = -f->get_T_local_to_body_13();
+    LOCAL[2][1] = f->get_T_local_to_body_12();
+    LOCAL[2][2] = f->get_T_local_to_body_11();
     LOCAL[2][3] = 0.0;
     LOCAL[3][0] = LOCAL[3][1] = LOCAL[3][2] = LOCAL[3][3] = 0.0;
     LOCAL[3][3] = 1.0;
@@ -168,13 +334,13 @@ void fgVIEW::Update( fgFLIGHT *f ) {
         // Theta, and Psi (roll, pitch, yaw)
 
         MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
-       MAT3rotate(R, vec, FG_Phi);
+       MAT3rotate(R, vec, f->get_Phi());
        /* printf("Roll matrix\n"); */
        /* MAT3print(R, stdout); */
 
        MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
        /* MAT3mult_vec(vec, vec, R); */
-       MAT3rotate(TMP, vec, FG_Theta);
+       MAT3rotate(TMP, vec, f->get_Theta());
        /* printf("Pitch matrix\n"); */
        /* MAT3print(TMP, stdout); */
        MAT3mult(R, R, TMP);
@@ -182,7 +348,7 @@ void fgVIEW::Update( fgFLIGHT *f ) {
        MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
        /* MAT3mult_vec(vec, vec, R); */
        /* MAT3rotate(TMP, vec, FG_Psi - FG_PI_2); */
-       MAT3rotate(TMP, vec, -FG_Psi);
+       MAT3rotate(TMP, vec, -f->get_Psi());
        /* printf("Yaw matrix\n");
           MAT3print(TMP, stdout); */
        MAT3mult(LOCAL, R, TMP);
@@ -193,13 +359,13 @@ void fgVIEW::Update( fgFLIGHT *f ) {
     // Derive the local UP transformation matrix based on *geodetic*
     // coordinates
     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
-    MAT3rotate(R, vec, FG_Longitude);     // R = rotate about Z axis
+    MAT3rotate(R, vec, f->get_Longitude());     // R = rotate about Z axis
     // printf("Longitude matrix\n");
     // MAT3print(R, stdout);
 
     MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
     MAT3mult_vec(vec, vec, R);
-    MAT3rotate(TMP, vec, -FG_Latitude);  // TMP = rotate about X axis
+    MAT3rotate(TMP, vec, -f->get_Latitude());  // TMP = rotate about X axis
     // printf("Latitude matrix\n");
     // MAT3print(TMP, stdout);
 
@@ -237,7 +403,7 @@ void fgVIEW::Update( fgFLIGHT *f ) {
     MAT3mult_vec(view_forward, forward, TMP);
 
     // make a vector to the current view position
-    MAT3_SET_VEC(v0, view_pos.x, view_pos.y, view_pos.z);
+    MAT3_SET_VEC(v0, view_pos.x(), view_pos.y(), view_pos.z());
 
     // Given a vector pointing straight down (-Z), map into onto the
     // local plane representing "horizontal".  This should give us the
@@ -269,19 +435,19 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) {
     if(fabs(view_offset)>FG_EPSILON){ 
        // Roll Matrix
        MAT3_SET_HVEC(vec, 0.0, 0.0, -1.0, 1.0);
-       MAT3rotate(R_Phi, vec, FG_Phi);
+       MAT3rotate(R_Phi, vec, f->get_Phi());
        // printf("Roll matrix (Phi)\n");
        // MAT3print(R_Phi, stdout);
 
        // Pitch Matrix
        MAT3_SET_HVEC(vec, 1.0, 0.0, 0.0, 1.0);
-       MAT3rotate(R_Theta, vec, FG_Theta);
+       MAT3rotate(R_Theta, vec, f->get_Theta());
        // printf("\nPitch matrix (Theta)\n");
        // MAT3print(R_Theta, stdout);
 
        // Yaw Matrix
        MAT3_SET_HVEC(vec, 0.0, -1.0, 0.0, 1.0);
-       MAT3rotate(R_Psi, vec, FG_Psi + FG_PI - view_offset );
+       MAT3rotate(R_Psi, vec, f->get_Psi() + FG_PI - view_offset );
        // printf("\nYaw matrix (Psi)\n");
        // MAT3print(R_Psi, stdout);
 
@@ -292,17 +458,17 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) {
     } else { // JUST USE LOCAL_TO_BODY  NHV 5/25/98
        // hey this is even different then LOCAL[][] above ??
         
-       AIRCRAFT[0][0] = -FG_T_local_to_body_22;
-       AIRCRAFT[0][1] = -FG_T_local_to_body_23;
-       AIRCRAFT[0][2] = FG_T_local_to_body_21;
+       AIRCRAFT[0][0] = -f->get_T_local_to_body_22();
+       AIRCRAFT[0][1] = -f->get_T_local_to_body_23();
+       AIRCRAFT[0][2] = f->get_T_local_to_body_21();
        AIRCRAFT[0][3] = 0.0;
-       AIRCRAFT[1][0] = FG_T_local_to_body_32;
-       AIRCRAFT[1][1] = FG_T_local_to_body_33;
-       AIRCRAFT[1][2] = -FG_T_local_to_body_31;
+       AIRCRAFT[1][0] = f->get_T_local_to_body_32();
+       AIRCRAFT[1][1] = f->get_T_local_to_body_33();
+       AIRCRAFT[1][2] = -f->get_T_local_to_body_31();
        AIRCRAFT[1][3] = 0.0;
-       AIRCRAFT[2][0] = FG_T_local_to_body_12;
-       AIRCRAFT[2][1] = FG_T_local_to_body_13;
-       AIRCRAFT[2][2] = -FG_T_local_to_body_11;
+       AIRCRAFT[2][0] = f->get_T_local_to_body_12();
+       AIRCRAFT[2][1] = f->get_T_local_to_body_13();
+       AIRCRAFT[2][2] = -f->get_T_local_to_body_11();
        AIRCRAFT[2][3] = 0.0;
        AIRCRAFT[3][0] = AIRCRAFT[3][1] = AIRCRAFT[3][2] = AIRCRAFT[3][3] = 0.0;
        AIRCRAFT[3][3] = 1.0;
@@ -318,7 +484,7 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) {
     // MAT3print(AIRCRAFT, stdout);
 
     // View position in scenery centered coordinates
-    MAT3_SET_HVEC(vec, view_pos.x, view_pos.y, view_pos.z, 1.0);
+    MAT3_SET_HVEC(vec, view_pos.x(), view_pos.y(), view_pos.z(), 1.0);
     MAT3translate(T_view, vec);
     // printf("\nTranslation matrix\n");
     // MAT3print(T_view, stdout);
@@ -326,14 +492,14 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) {
     // Latitude
     MAT3_SET_HVEC(vec, 1.0, 0.0, 0.0, 1.0);
     // R_Lat = rotate about X axis
-    MAT3rotate(R_Lat, vec, FG_Latitude);
+    MAT3rotate(R_Lat, vec, f->get_Latitude());
     // printf("\nLatitude matrix\n");
     // MAT3print(R_Lat, stdout);
 
     // Longitude
     MAT3_SET_HVEC(vec, 0.0, 0.0, 1.0, 1.0);
     // R_Lon = rotate about Z axis
-    MAT3rotate(R_Lon, vec, FG_Longitude - FG_PI_2 );
+    MAT3rotate(R_Lon, vec, f->get_Longitude() - FG_PI_2 );
     // printf("\nLongitude matrix\n");
     // MAT3print(R_Lon, stdout);
 
@@ -379,91 +545,106 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) {
 }
 
 
-// Destructor
-fgVIEW::~fgVIEW( void ) {
-}
-
-
-// Basically, this is a modified version of the Mesa gluLookAt()
-// function that's been modified slightly so we can capture the result
-// before sending it off to OpenGL land.
-void fg_gluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
-                  GLdouble centerx, GLdouble centery, GLdouble centerz,
-                  GLdouble upx, GLdouble upy, GLdouble upz )
+#if 0
+// Reject non viewable spheres from current View Frustrum by Curt
+// Olson curt@me.umn.edu and Norman Vine nhv@yahoo.com with 'gentle
+// guidance' from Steve Baker sbaker@link.com
+int
+fgVIEW::SphereClip( const Point3D& cp, const double radius )
 {
-    GLdouble *m;
-    GLdouble x[3], y[3], z[3];
-    GLdouble mag;
+    double x1, y1;
 
-    m = current_view.MODEL_VIEW;
-
-    /* Make rotation matrix */
+    MAT3vec eye;       
+    double *mat;
+    double x, y, z;
 
-    /* Z vector */
-    z[0] = eyex - centerx;
-    z[1] = eyey - centery;
-    z[2] = eyez - centerz;
-    mag = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] );
-    if (mag) {  /* mpichler, 19950515 */
-       z[0] /= mag;
-       z[1] /= mag;
-       z[2] /= mag;
+    x = cp->x;
+    y = cp->y;
+    z = cp->z;
+       
+    mat = (double *)(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 + far_plane < 0) )
+    {
+       return 1;
     }
-
-    /* Y vector */
-    y[0] = upx;
-    y[1] = upy;
-    y[2] = upz;
-
-    /* X vector = Y cross Z */
-    x[0] =  y[1]*z[2] - y[2]*z[1];
-    x[1] = -y[0]*z[2] + y[2]*z[0];
-    x[2] =  y[0]*z[1] - y[1]*z[0];
-    
-    /* Recompute Y = Z cross X */
-    y[0] =  z[1]*x[2] - z[2]*x[1];
-    y[1] = -z[0]*x[2] + z[2]*x[0];
-    y[2] =  z[0]*x[1] - z[1]*x[0];
-
-    /* mpichler, 19950515 */
-    /* cross product gives area of parallelogram, which is < 1.0 for
-     * non-perpendicular unit-length vectors; so normalize x, y here
-     */
-
-    mag = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] );
-    if (mag) {
-       x[0] /= mag;
-       x[1] /= mag;
-      x[2] /= mag;
+       
+    // check right and left clip plane (from eye perspective)
+    x1 = radius * fov_x_clip;
+    eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * slope_x;
+    if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) ) {
+       return(1);
     }
-
-    mag = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] );
-    if (mag) {
-       y[0] /= mag;
-       y[1] /= mag;
-       y[2] /= mag;
+       
+    // check bottom and top clip plane (from eye perspective)
+    y1 = radius * fov_y_clip;
+    eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) * slope_y; 
+    if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) ) {
+       return 1;
     }
 
-#define M(row,col)  m[col*4+row]
-    M(0,0) = x[0];  M(0,1) = x[1];  M(0,2) = x[2];  M(0,3) = 0.0;
-    M(1,0) = y[0];  M(1,1) = y[1];  M(1,2) = y[2];  M(1,3) = 0.0;
-    M(2,0) = z[0];  M(2,1) = z[1];  M(2,2) = z[2];  M(2,3) = 0.0;
-    M(3,0) = 0.0;   M(3,1) = 0.0;   M(3,2) = 0.0;   M(3,3) = 1.0;
-#undef M
+    return 0;
+}
+#endif
 
-    // Translate Eye to Origin
-    // replaces: glTranslated( -eyex, -eyey, -eyez );
-    m[12] = m[0] * -eyex + m[4] * -eyey + m[8]  * -eyez + m[12];
-    m[13] = m[1] * -eyex + m[5] * -eyey + m[9]  * -eyez + m[13];
-    m[14] = m[2] * -eyex + m[6] * -eyey + m[10] * -eyez + m[14];
-    m[15] = m[3] * -eyex + m[7] * -eyey + m[11] * -eyez + m[15];
 
-    // xglMultMatrixd( m );
-    xglLoadMatrixd( m );
+// Destructor
+fgVIEW::~fgVIEW( void ) {
 }
 
 
 // $Log$
+// Revision 1.28  1998/12/03 01:17:20  curt
+// Converted fgFLIGHT to a class.
+//
+// Revision 1.27  1998/11/16 14:00:06  curt
+// Added pow() macro bug work around.
+// Added support for starting FGFS at various resolutions.
+// Added some initial serial port support.
+// Specify default log levels in main().
+//
+// Revision 1.26  1998/11/09 23:39:25  curt
+// Tweaks for the instrument panel.
+//
+// Revision 1.25  1998/11/06 21:18:15  curt
+// Converted to new logstream debugging facility.  This allows release
+// builds with no messages at all (and no performance impact) by using
+// the -DFG_NDEBUG flag.
+//
+// Revision 1.24  1998/10/18 01:17:19  curt
+// Point3D tweaks.
+//
+// Revision 1.23  1998/10/17 01:34:26  curt
+// C++ ifying ...
+//
+// Revision 1.22  1998/10/16 00:54:03  curt
+// Converted to Point3D class.
+//
+// Revision 1.21  1998/09/17 18:35:33  curt
+// Added F8 to toggle fog and F9 to toggle texturing.
+//
+// Revision 1.20  1998/09/08 15:04:35  curt
+// Optimizations by Norman Vine.
+//
+// Revision 1.19  1998/08/20 20:32:34  curt
+// Reshuffled some of the code in and around views.[ch]xx
+//
+// Revision 1.18  1998/07/24 21:57:02  curt
+// Set near clip plane to 0.5 meters when close to the ground.  Also, let the view get a bit closer to the ground before hitting the hard limit.
+//
+// Revision 1.17  1998/07/24 21:39:12  curt
+// Debugging output tweaks.
+// Cast glGetString to (char *) to avoid compiler errors.
+// Optimizations to fgGluLookAt() by Norman Vine.
+//
+// Revision 1.16  1998/07/13 21:01:41  curt
+// Wrote access functions for current fgOPTIONS.
+//
 // Revision 1.15  1998/07/12 03:14:43  curt
 // Added ground collision detection.
 // Did some serious horsing around to be able to "hug" the ground properly