]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/model.cxx
Somewhere along the line in the recent changes some std::cout were
[flightgear.git] / src / Main / model.cxx
index 32237ee4a68d55aef7d9a869c85a18b815539071..8016f97ca3b6e5da9ac240e6d5158405ad210257 100644 (file)
@@ -94,13 +94,13 @@ FGAircraftModel::init ()
                                // Load animations
   vector<SGPropertyNode *> animation_nodes =
     props.getChildren("animation");
-  for (int i = 0; i < animation_nodes.size(); i++) {
+  for (unsigned int i = 0; i < animation_nodes.size(); i++) {
     vector<SGPropertyNode *> name_nodes =
       animation_nodes[i]->getChildren("object-name");
     if (name_nodes.size() < 1) {
       SG_LOG(SG_INPUT, SG_ALERT, "No object-name given for transformation");
     } else {
-      for (int j = 0; j < name_nodes.size(); j++) {
+      for (unsigned int j = 0; j < name_nodes.size(); j++) {
        _animations.push_back(read_animation(name_nodes[j]->getStringValue(),
                                             animation_nodes[i]));
       }
@@ -150,10 +150,12 @@ FGAircraftModel::update (int dt)
   long elapsed_ms = (_current_timestamp - _last_timestamp) / 1000;
   _last_timestamp.stamp();
 
-  if (globals->get_viewmgr()->get_current() == 0) {
+  int view_number = globals->get_viewmgr()->get_current();
+
+  if (view_number == 0 && !fgGetBool("/sim/view/internal")) {
     _selector->select(false);
   } else {
-    for (int i = 0; i < _animations.size(); i++)
+    for (unsigned int i = 0; i < _animations.size(); i++)
       do_animation(_animations[i], elapsed_ms);
 
     _selector->select(true);
@@ -171,14 +173,57 @@ FGAircraftModel::update (int dt)
     
     sgMat4 sgTUX;
     sgCopyMat4( sgTUX, sgROT );
-    sgPostMultMat4( sgTUX, pilot_view->get_VIEW_ROT() );
-    sgPostMultMat4( sgTUX, sgTRANS );
-    
+    sgMat4 VIEW_ROT;
+    sgCopyMat4( VIEW_ROT, pilot_view->get_VIEW_ROT());
+    if (view_number == 0) {
+                               // FIXME: orientation is not applied
+                               // correctly when view is not forward
+      sgMakeRotMat4( sgROT, -pilot_view->get_view_offset()
+                    * SGD_RADIANS_TO_DEGREES, pilot_view->get_world_up() );
+
+      /* Warning lame hack from Wilson ahead */
+      /* get the pitch value */
+      sgVec3 rph;
+      sgCopyVec3(rph, pilot_view->get_rph());
+      /* double it to counter the value already in the VIEW_ROT */
+      float pitch = rph[1] * 2;
+      /* make a ROT matrix 
+         with the values waited by the X coordinate from the offset 
+         rotation see sgROT above
+      */
+      sgMat4 PunROT;
+      PunROT[0][0] = SG_ONE;
+      PunROT[0][1] = SG_ZERO;
+      PunROT[0][2] = SG_ZERO;
+      PunROT[0][3] = SG_ZERO;
+      PunROT[1][0] = SG_ZERO;
+      PunROT[1][1] = cos((1 - sgROT[0][0]) * -pitch);
+      PunROT[1][2] = -sin((1 - sgROT[0][0]) * -pitch);
+      PunROT[1][3] = SG_ZERO;
+      PunROT[2][0] = SG_ZERO;
+      PunROT[2][1] = sin((1 - sgROT[0][0]) * -pitch);
+      PunROT[2][2] = cos((1 - sgROT[0][0]) * -pitch);
+      PunROT[2][3] = SG_ZERO;
+      PunROT[3][0] = SG_ZERO;
+      PunROT[3][1] = SG_ZERO;
+      PunROT[3][2] = SG_ZERO;
+      PunROT[3][3] = SG_ONE;
+
+      sgPostMultMat4( sgTUX, PunROT );
+      sgPostMultMat4( sgTUX, VIEW_ROT );
+      sgPostMultMat4( sgTUX, sgROT );
+      sgPostMultMat4( sgTUX, sgTRANS );
+      /* end lame hack */
+
+    } else {
+      sgPostMultMat4( sgTUX, VIEW_ROT );
+      sgPostMultMat4( sgTUX, sgTRANS );
+    }
+
     sgCoord tuxpos;
     sgSetCoord( &tuxpos, sgTUX );
     _position->setTransform( &tuxpos );
   }
-
 }
 
 FGAircraftModel::Animation