]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/panel.cxx
Cosmetic changes.
[flightgear.git] / src / Cockpit / panel.cxx
index 11d69e04618543e41e34dc2ff44e4afac48fa9aa..3ddc6b453437244d703d9b5df1a6bab27df507e0 100644 (file)
 #define WIN_W 1024
 #define WIN_H 768
 
-#ifdef NONE
-#pragma warn A sloppy coder has defined NONE as a macro!!!
-#undef NONE
+#if defined( NONE ) && defined( _MSC_VER )
+#  pragma message( "A sloppy coder has defined NONE as a macro!!!" )
+#  undef NONE
+#elif defined( NONE )
+#  pragma warn A sloppy coder has defined NONE as a macro!!!
+#  undef NONE
 #endif
 
 
@@ -171,6 +174,7 @@ FGPanel::FGPanel ()
     _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
     _x_offset(0), _y_offset(0), _view_height(int(WIN_H * 0.4232)),
     _bound(false),
+    _jitter(0.0),
     _xsize_node(fgGetNode("/sim/startup/xsize", true)),
     _ysize_node(fgGetNode("/sim/startup/ysize", true))
 {
@@ -226,6 +230,8 @@ FGPanel::bind ()
   fgSetArchivable("/sim/panel/x-offset");
   fgTie("/sim/panel/y-offset", &_y_offset);
   fgSetArchivable("/sim/panel/y-offset");
+  fgTie("/sim/panel/jitter", &_jitter);
+  fgSetArchivable("/sim/panel/jitter");
   _bound = true;
 }
 
@@ -250,8 +256,9 @@ void
 FGPanel::update ()
 {
                                // Do nothing if the panel isn't visible.
-    if (!fgPanelVisible())
+    if ( !fgPanelVisible() ) {
         return;
+    }
 
                                // If the mouse is down, do something
     if (_mouseDown) {
@@ -275,6 +282,31 @@ FGPanel::update ()
 void
 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
 {
+                               // Calculate accelerations
+                               // and jiggle the panel accordingly
+                               // The factors and bounds are just
+                               // initial guesses; using sqrt smooths
+                               // out the spikes.
+  double x_offset = _x_offset;
+  double y_offset = _y_offset;
+
+  if (_jitter != 0.0) {
+    double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
+    double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
+    double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
+
+    double a_zx_pilot = a_z_pilot - a_x_pilot;
+    
+    int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter)) *
+                  (a_y_pilot < 0 ? -1 : 1);
+    int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter)) *
+                  (a_zx_pilot < 0 ? -1 : 1);
+
+                               // adjustments in screen coordinates
+    x_offset += x_adjust;
+    y_offset += y_adjust;
+  }
+
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();
@@ -285,7 +317,7 @@ FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
   glPushMatrix();
   glLoadIdentity();
 
-  glTranslated(_x_offset, _y_offset, 0);
+  glTranslated(x_offset, y_offset, 0);
 
                                // Draw the background
   glEnable(GL_TEXTURE_2D);
@@ -317,7 +349,7 @@ FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
   for ( ; current != end; current++) {
     FGPanelInstrument * instr = *current;
     glLoadIdentity();
-    glTranslated(_x_offset, _y_offset, 0);
+    glTranslated(x_offset, y_offset, 0);
     glTranslated(instr->getXPos(), instr->getYPos(), 0);
     instr->draw();
   }