]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/NavDisplay.cxx
ITM radio calculations are only considered valid
[flightgear.git] / src / Instrumentation / NavDisplay.cxx
index 83de81bbf8b4100fbe1c4a045568c10f8aae1294..62081537a238abcb50d060d65b67b4815a4a45b9 100644 (file)
@@ -233,8 +233,8 @@ public:
         if (stretchSymbol) {
             stretchY2 = node->getFloatValue("y2");
             stretchY3 = node->getFloatValue("y3");
-            stretchV2 = node->getFloatValue("v2");
-            stretchV3 = node->getFloatValue("v3");
+            stretchV2 = node->getFloatValue("v2") / texSize;
+            stretchV3 = node->getFloatValue("v3") / texSize;
         }
       
         return true;
@@ -443,7 +443,8 @@ NavDisplay::init ()
     
     osg::StateSet *stateSet = _geom->getOrCreateStateSet();
     stateSet->setTextureAttributeAndModes(0, _symbolTexture.get());
-    
+    stateSet->setDataVariance(osg::Object::STATIC);
+  
     // Initially allocate space for 128 quads
     _vertices = new osg::Vec2Array;
     _vertices->setDataVariance(osg::Object::DYNAMIC);
@@ -657,7 +658,7 @@ void NavDisplay::addSymbolToScene(SymbolInstance* sym)
     verts[3] = osg::Vec2(def->xy0.x(), def->xy1.y());
     
     if (def->rotateToHeading) {
-        osg::Matrixf m(degRotation(sym->headingDeg));
+        osg::Matrixf m(degRotation(sym->headingDeg - _view_heading));
         for (int i=0; i<4; ++i) {
             verts[i] = mult(verts[i], m);
         }
@@ -685,7 +686,7 @@ void NavDisplay::addSymbolToScene(SymbolInstance* sym)
         stretchVerts[2] = osg::Vec2(def->xy1.x(), def->stretchY3);
         stretchVerts[3] = osg::Vec2(def->xy0.x(), def->stretchY3);
         
-        osg::Matrixf m(degRotation(sym->headingDeg));
+        osg::Matrixf m(degRotation(sym->headingDeg - _view_heading));
         for (int i=0; i<4; ++i) {
             stretchVerts[i] = mult(stretchVerts[i], m);
         }
@@ -1012,8 +1013,17 @@ void NavDisplay::foundPositionedItem(FGPositioned* pos)
     computePositionedPropsAndHeading(pos, vars, heading);
     
     osg::Vec2 projected = projectGeod(pos->geod());
+    if (pos->type() == FGPositioned::RUNWAY) {
+        FGRunway* rwy = (FGRunway*) pos;
+        projected = projectGeod(rwy->threshold());
+    }
+    
     BOOST_FOREACH(SymbolDef* r, rules) {
-        addSymbolInstance(projected, heading, r, vars);
+        SymbolInstance* ins = addSymbolInstance(projected, heading, r, vars);
+        if (pos->type() == FGPositioned::RUNWAY) {
+            FGRunway* rwy = (FGRunway*) pos;
+            ins->endPos = projectGeod(rwy->end());
+        }
     }
 }
 
@@ -1023,6 +1033,7 @@ void NavDisplay::computePositionedPropsAndHeading(FGPositioned* pos, SGPropertyN
     nd->setStringValue("name", pos->name());
     nd->setDoubleValue("elevation-ft", pos->elevation());
     nd->setIntValue("heading-deg", 0);
+    heading = 0.0;
     
     switch (pos->type()) {
     case FGPositioned::VOR:
@@ -1032,11 +1043,12 @@ void NavDisplay::computePositionedPropsAndHeading(FGPositioned* pos, SGPropertyN
         nd->setDoubleValue("frequency-mhz", nav->get_freq());
         
         if (pos == _nav1Station) {
-            nd->setIntValue("heading-deg", _navRadio1Node->getDoubleValue("radials/target-radial-deg"));
+            heading = _navRadio1Node->getDoubleValue("radials/target-radial-deg");
         } else if (pos == _nav2Station) {
-            nd->setIntValue("heading-deg", _navRadio2Node->getDoubleValue("radials/target-radial-deg"));
+            heading = _navRadio2Node->getDoubleValue("radials/target-radial-deg");
         }
         
+        nd->setIntValue("heading-deg", heading);
         break;
     }
 
@@ -1048,7 +1060,8 @@ void NavDisplay::computePositionedPropsAndHeading(FGPositioned* pos, SGPropertyN
         
     case FGPositioned::RUNWAY: {
         FGRunway* rwy = static_cast<FGRunway*>(pos);
-        nd->setDoubleValue("heading-deg", rwy->headingDeg());
+        heading = rwy->headingDeg();
+        nd->setDoubleValue("heading-deg", heading);
         nd->setIntValue("length-ft", rwy->lengthFt());
         nd->setStringValue("airport", rwy->airport()->ident());
         break;
@@ -1122,6 +1135,16 @@ void NavDisplay::computePositionedState(FGPositioned* pos, string_set& states)
     } // FGPositioned::Type switch
 }
 
+static string mapAINodeToType(SGPropertyNode* model)
+{
+  // assume all multiplayer items are aircraft for the moment. Not ideal.
+  if (!strcmp(model->getName(), "multiplayer")) {
+    return "ai-aircraft";
+  }
+  
+  return string("ai-") + model->getName();
+}
+
 void NavDisplay::processAI()
 {
     SGPropertyNode *ai = fgGetNode("/ai/models", true);
@@ -1136,7 +1159,7 @@ void NavDisplay::processAI()
         string_set ss;
         computeAIStates(model, ss);        
         SymbolDefVector rules;
-        findRules(string("ai-") + model->getName(), ss, rules);
+        findRules(mapAINodeToType(model), ss, rules);
         if (rules.empty()) {
             return; // no rules matched, we can skip this item
         }
@@ -1159,14 +1182,15 @@ void NavDisplay::processAI()
 void NavDisplay::computeAIStates(const SGPropertyNode* ai, string_set& states)
 {
     int threatLevel = ai->getIntValue("tcas/threat-level",-1);
-    if (threatLevel >= 0) {
-        states.insert("tcas");
-      
-        std::ostringstream os;
-        os << "tcas-threat-level-" << threatLevel;
-        states.insert(os.str());
-    }
-    
+    if (threatLevel < 1)
+      threatLevel = 0;
+  
+    states.insert("tcas");
+  
+    std::ostringstream os;
+    os << "tcas-threat-level-" << threatLevel;
+    states.insert(os.str());
+
     double vspeed = ai->getDoubleValue("velocities/vertical-speed-fps");
     if (vspeed < -3.0) {
         states.insert("descending");
@@ -1175,15 +1199,15 @@ void NavDisplay::computeAIStates(const SGPropertyNode* ai, string_set& states)
     }
 }
 
-bool NavDisplay::addSymbolInstance(const osg::Vec2& proj, double heading, SymbolDef* def, SGPropertyNode* vars)
+SymbolInstance* NavDisplay::addSymbolInstance(const osg::Vec2& proj, double heading, SymbolDef* def, SGPropertyNode* vars)
 {
     if (isProjectedClipped(proj)) {
-        return false;
+        return NULL;
     }
     
     SymbolInstance* sym = new SymbolInstance(proj, heading, def, vars);
     _symbols.push_back(sym);
-    return true;
+    return sym;
 }
 
 bool NavDisplay::isProjectedClipped(const osg::Vec2& projected) const