# include <config.h>
#endif
+#include <ssg.h> // plib include
+
#include <Aircraft/aircraft.hxx>
#include <Cockpit/panel.hxx>
#include <Debug/logstream.hxx>
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;
// Update the field of view coefficients
void FGView::UpdateFOV( const fgOPTIONS& o ) {
+ ssgSetFOV( o.get_fov(), 0.0 );
+
double fov, theta_x, theta_y;
fov = o.get_fov();
}
+// 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.
xglViewport(0, 0 , (GLint)(winWidth), (GLint)(winHeight) );
} else {
xglViewport(0, (GLint)((winHeight)*0.5768), (GLint)(winWidth),
- (GLint)((winHeight)*0.4232) );
+ (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 ) {
+ // ssgSetNearFar( 10.0, 100000.0 );
gluPerspective(current_options.get_fov(), win_ratio, 10.0, 100000.0);
} else {
+ // ssgSetNearFar( 0.5, 100000.0 );
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)
#if !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
xglLoadMatrixf( m );
}
#endif // FG_VIEW_INLINE_OPTIMIZATIONS
-
panel_hist = current_options.get_panel_status();
}
} 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)
// 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);
// 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);