]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/views.cxx
Added some early support for a cheezy external view of TuX.
[flightgear.git] / src / Main / views.cxx
index 418b6dcf4e4d8af6d9d1568d2330cd044bfc6aec..23945180bee808eb29e24855dbbd10cb2fd408a5 100644 (file)
@@ -76,6 +76,7 @@ FGView::FGView( void ) {
 void FGView::Init( void ) {
     FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" );
 
+    view_mode = FG_VIEW_FIRST_PERSON;
     view_offset = 0.0;
     goal_view_offset = 0.0;
 
@@ -131,6 +132,16 @@ void FGView::UpdateFOV( const fgOPTIONS& o ) {
 }
 
 
+// Cycle view mode
+void FGView::cycle_view_mode() {
+    if ( view_mode == FG_VIEW_FIRST_PERSON ) {
+       view_mode = FG_VIEW_FOLLOW;
+    } else if ( view_mode == FG_VIEW_FOLLOW ) {
+       view_mode = FG_VIEW_FIRST_PERSON;
+    }
+}
+
+
 // 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.
@@ -239,10 +250,10 @@ void FGView::UpdateViewParams( void ) {
     xglMatrixMode(GL_PROJECTION);
     xglLoadIdentity();
     if ( f->get_Altitude() * FEET_TO_METER - scenery.cur_elev > 10.0 ) {
-       ssgSetNearFar( 10.0, 100000.0 );
+       // ssgSetNearFar( 10.0, 100000.0 );
        gluPerspective(current_options.get_fov(), win_ratio, 10.0, 100000.0);
     } else {
-       ssgSetNearFar( 0.5, 100000.0 );
+       // ssgSetNearFar( 0.5, 100000.0 );
        gluPerspective(current_options.get_fov(), win_ratio, 0.5, 100000.0);
        // printf("Near ground, minimizing near clip plane\n");
     }
@@ -378,7 +389,6 @@ void FGView::UpdateViewParams( void ) {
        xglLoadMatrixf( m );
     }
 #endif // FG_VIEW_INLINE_OPTIMIZATIONS
-       
 
     panel_hist = current_options.get_panel_status();
 }
@@ -601,32 +611,91 @@ void FGView::UpdateViewMath( FGInterface *f ) {
 
     } else {
 
+       // calculate the transformation matrix to go from LaRCsim to ssg
+       sgVec3 vec1;
+       sgSetVec3( vec1, 0.0, 1.0, 0.0 );
+       sgMat4 mat1;
+       sgMakeRotMat4( mat1, 90, vec1 );
+
+       sgVec3 vec2;
+       sgSetVec3( vec2, 1.0, 0.0, 0.0 );
+       sgMat4 mat2;
+       sgMakeRotMat4( mat2, 90, vec2 );
+
+       sgMultMat4( sgLARC_TO_SSG, mat1, mat2 );
+
+       /*
+       cout << "LaRCsim to SSG:" << endl;
+       MAT3mat print;
+       int i;
+       int j;
+       for ( i = 0; i < 4; i++ ) {
+           for ( j = 0; j < 4; j++ ) {
+               print[i][j] = sgLARC_TO_SSG[i][j];
+           }
+       }
+       MAT3print( print, stdout);
+       */
+
        // code to calculate LOCAL matrix calculated from Phi, Theta, and
        // Psi (roll, pitch, yaw) in case we aren't running LaRCsim as our
        // flight model
 
        MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
        MAT3rotate(R, vec, f->get_Phi());
-       /* printf("Roll matrix\n"); */
-       /* MAT3print(R, stdout); */
+       // cout << "Roll matrix" << endl;
+       // MAT3print(R, stdout);
+
+       sgVec3 sgrollvec;
+       sgSetVec3( sgrollvec, 0.0, 0.0, 1.0 );
+       sgMat4 sgPHI;           // roll
+       sgMakeRotMat4( sgPHI, f->get_Phi() * RAD_TO_DEG, sgrollvec );
+
 
        MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
-       /* MAT3mult_vec(vec, vec, R); */
        MAT3rotate(TMP, vec, f->get_Theta());
-       /* printf("Pitch matrix\n"); */
-       /* MAT3print(TMP, stdout); */
+       // cout << "Pitch matrix" << endl;;
+       // MAT3print(TMP, stdout);
        MAT3mult(R, R, TMP);
+       // cout << "tmp rotation matrix, R:" << endl;;
+       // MAT3print(R, stdout);
+
+       sgVec3 sgpitchvec;
+       sgSetVec3( sgpitchvec, 0.0, 1.0, 0.0 );
+       sgMat4 sgTHETA;         // pitch
+       sgMakeRotMat4( sgTHETA, f->get_Theta() * RAD_TO_DEG,
+                      sgpitchvec );
+
+       sgMat4 sgROT;
+       sgMultMat4( sgROT, sgPHI, sgTHETA );
+
 
        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, -f->get_Psi());
-       /* printf("Yaw matrix\n");
-          MAT3print(TMP, stdout); */
+       // cout << "Yaw matrix" << endl;
+       // MAT3print(TMP, stdout);
        MAT3mult(LOCAL, R, TMP);
-       // printf("FG derived LOCAL matrix\n");
+       // cout << "LOCAL matrix:" << endl;
        // MAT3print(LOCAL, stdout);
 
+       sgVec3 sgyawvec;
+       sgSetVec3( sgyawvec, 1.0, 0.0, 0.0 );
+       sgMat4 sgPSI;           // pitch
+       sgMakeRotMat4( sgPSI, -f->get_Psi() * RAD_TO_DEG, sgyawvec );
+
+       sgMultMat4( sgLOCAL, sgROT, sgPSI );
+
+       /*
+       MAT3mat print;
+       int i;
+       int j;
+       for ( i = 0; i < 4; i++ ) {
+           for ( j = 0; j < 4; j++ ) {
+               print[i][j] = sgLOCAL[i][j];
+           }
+       }
+       MAT3print( print, stdout);
+       */
     } // if ( use_larcsim_local_to_body ) 
 
 #if !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
@@ -645,9 +714,26 @@ void FGView::UpdateViewMath( FGInterface *f ) {
     // MAT3print(TMP, stdout);
 
     MAT3mult(UP, R, TMP);
-    // printf("Local up matrix\n");
+    // cout << "Local up matrix" << endl;;
     // MAT3print(UP, stdout);
 
+    sgMakeRotMat4( sgUP, 
+                  f->get_Longitude() * RAD_TO_DEG,
+                  0.0,
+                  -f->get_Latitude() * RAD_TO_DEG );
+    /*
+    cout << "FG derived UP matrix using sg routines" << endl;
+    MAT3mat print;
+    int i;
+    int j;
+    for ( i = 0; i < 4; i++ ) {
+       for ( j = 0; j < 4; j++ ) {
+           print[i][j] = sgUP[i][j];
+       }
+    }
+    MAT3print( print, stdout);
+    */
+
     MAT3_SET_VEC(local_up, 1.0, 0.0, 0.0);
     MAT3mult_vec(local_up, local_up, UP);
 
@@ -662,9 +748,35 @@ void FGView::UpdateViewMath( FGInterface *f ) {
 
     // Calculate the VIEW matrix
     MAT3mult(VIEW, LOCAL, UP);
-    // printf("VIEW matrix\n");
+    // cout << "VIEW matrix" << endl;;
     // MAT3print(VIEW, stdout);
 
+    sgMat4 sgTMP;
+    sgMultMat4( sgTMP, sgLOCAL, sgUP );
+    sgMultMat4( sgVIEW_ROT, sgLARC_TO_SSG, sgTMP );
+
+    sgMakeTransMat4( sgTRANS, view_pos.x(), view_pos.y(), view_pos.z() );
+
+    sgMultMat4( sgVIEW, sgVIEW_ROT, sgTRANS );
+
+    FGMat4Wrapper tmp;
+    sgCopyMat4( tmp.m, sgVIEW );
+    follow.push_back( tmp );
+
+    /*
+    cout << "FG derived VIEW matrix using sg routines" << endl;
+    MAT3mat print;
+    int i;
+    int j;
+    for ( i = 0; i < 4; i++ ) {
+       for ( j = 0; j < 4; j++ ) {
+           print[i][j] = sgVIEW[i][j];
+       }
+    }
+    MAT3print( print, stdout);
+    */
+
+
     // generate the current up, forward, and fwrd-view vectors
     MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
     MAT3mult_vec(view_up, vec, VIEW);