]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/views.cxx
Return to glider model ...
[flightgear.git] / src / Main / views.cxx
index d7f692add7700ccd791a16bdfedc475226063b8d..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();
 }
@@ -508,8 +518,6 @@ void FGView::UpdateViewMath( FGInterface *f ) {
     MAT3mat R, TMP, UP, LOCAL, VIEW;
     double ntmp;
 
-    sgMat4 sgLOCAL, sgUP, sgVIEW;
-
     if ( update_fov ) {
        // printf("Updating fov\n");
        UpdateFOV( current_options );
@@ -603,38 +611,81 @@ 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);
-       // cout << "FG derived LOCAL matrix using MAT3 routines" << endl;
+       // cout << "LOCAL matrix:" << endl;
        // MAT3print(LOCAL, stdout);
 
-       sgMakeRotMat4( sgLOCAL, 
-                      f->get_Psi() * RAD_TO_DEG,
-                      f->get_Phi() * RAD_TO_DEG,
-                      f->get_Theta() * RAD_TO_DEG );
+       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 );
+
        /*
-       cout << "FG derived LOCAL matrix using sg routines" << endl;
        MAT3mat print;
        int i;
        int j;
@@ -644,15 +695,6 @@ void FGView::UpdateViewMath( FGInterface *f ) {
            }
        }
        MAT3print( print, stdout);
-
-       sgMat4 sgIDENT;
-       sgMakeIdentMat4( sgIDENT );
-       for ( i = 0; i < 4; i++ ) {
-           for ( j = 0; j < 4; j++ ) {
-               print[i][j] = sgIDENT[i][j];
-           }
-       }
-       MAT3print( print, stdout);
        */
     } // if ( use_larcsim_local_to_body ) 
 
@@ -706,10 +748,22 @@ void FGView::UpdateViewMath( FGInterface *f ) {
 
     // Calculate the VIEW matrix
     MAT3mult(VIEW, LOCAL, UP);
-    cout << "VIEW matrix" << endl;;
-    MAT3print(VIEW, stdout);
+    // 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, sgLOCAL, sgUP );
+    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;
@@ -720,6 +774,8 @@ void FGView::UpdateViewMath( FGInterface *f ) {
        }
     }
     MAT3print( print, stdout);
+    */
+
 
     // generate the current up, forward, and fwrd-view vectors
     MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);