]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/hud_rwy.cxx
Merge branch 'jmt/acinclude'
[flightgear.git] / src / Cockpit / hud_rwy.cxx
index f050619cf0110f5a27e8f71cf724a97c8cbadc97..0f7866619ac7607efc9212312b53aa2c12af93c4 100644 (file)
 #include <Aircraft/aircraft.hxx>
 #include <Environment/environment.hxx>
 #include <Environment/environment_mgr.hxx>
-#include <simgear/math/sg_geodesy.hxx>
-#include <simgear/math/polar3d.hxx>
-#include SG_GLU_H
-#include <ATC/ATCutils.hxx>
+#include <ATCDCL/ATCutils.hxx>
+#include <Main/viewer.hxx>
+
+#include <osg/GLU>
 
 
 // int x, int y, int width, int height, float scale_data, bool working)
@@ -60,7 +60,7 @@ runway_instr::runway_instr(const SGPropertyNode *node) :
     drawIA(arrowScale > 0 ? true : false),
     drawIAAlways(arrowScale > 0 ? node->getBoolValue("arrow_always") : false)
 {
-    SG_LOG(SG_INPUT, SG_INFO, "Done reading runway instrument "
+    SG_LOG(SG_INPUT, SG_BULK, "Done reading runway instrument "
             << node->getStringValue("name", "[unnamed]"));
 
     view[0] = 0;
@@ -81,7 +81,7 @@ runway_instr::runway_instr(const SGPropertyNode *node) :
 
 void runway_instr::draw()
 {
-    if (!is_broken() && get_active_runway(runway)) {
+    if (!is_broken() && (runway = get_active_runway())) {
         glPushAttrib(GL_LINE_STIPPLE | GL_LINE_STIPPLE_PATTERN | GL_LINE_WIDTH);
         float modelView[4][4], projMat[4][4];
         bool anyLines;
@@ -105,13 +105,16 @@ void runway_instr::draw()
             globals->get_viewmgr()->copyToCurrent();
         }
         //Set the camera to the cockpit view to get the view of the runway from the cockpit
-        ssgSetCamera((sgVec4 *)cockpit_view->get_VIEW());
+        // OSGFIXME
+//         ssgSetCamera((sgVec4 *)cockpit_view->get_VIEW());
         get_rwy_points(points3d);
         //Get the current project matrix
-        ssgGetProjectionMatrix(projMat);
+        // OSGFIXME
+//         ssgGetProjectionMatrix(projMat);
 //        const sgVec4 *viewMat = globals->get_current_view()->get_VIEW();
         //Get the current model view matrix (cockpit view)
-        ssgGetModelviewMatrix(modelView);
+        // OSGFIXME
+//         ssgGetModelviewMatrix(modelView);
         //Create a rotation matrix to correct for any offsets (other than default offsets) to the model view matrix
         sgMat4 xy; //rotation about the Rxy, negate the sin's on Ry
         xy[0][0] = cYaw;         xy[1][0] = 0.0f;   xy[2][0] = -sYaw;        xy[3][0] = 0.0f;
@@ -164,59 +167,49 @@ void runway_instr::draw()
             curr_view->setGoalPitchOffset_deg(gpo);
         }
         //Set the camera back to the current view
-        ssgSetCamera((sgVec4 *)curr_view);
+        // OSGFIXME
+//         ssgSetCamera((sgVec4 *)curr_view);
         glPopAttrib();
     }//if not broken
 }
 
 
-bool runway_instr::get_active_runway(FGRunway& runway)
+FGRunway* runway_instr::get_active_runway()
 {
-    FGEnvironment stationweather =
-            ((FGEnvironmentMgr *)globals->get_subsystem("environment"))->getEnvironment();
-    double hdg = stationweather.get_wind_from_heading_deg();
-    return globals->get_runways()->search(fgGetString("/sim/presets/airport-id"), int(hdg), &runway);
+  const FGAirport* apt = fgFindAirportID(fgGetString("/sim/presets/airport-id"));
+  if (!apt) return NULL;
+  
+  return apt->getActiveRunwayForUsage();
 }
 
 
 void runway_instr::get_rwy_points(sgdVec3 *points3d)
 {
-    static Point3D center = globals->get_scenery()->get_center();
-
-    //Get the current tile center
-    Point3D currentCenter = globals->get_scenery()->get_center();
-    Point3D tileCenter = currentCenter;
-    if (center != currentCenter) //if changing tiles
-        tileCenter = center; //use last center
     double alt = current_aircraft.fdm_state->get_Runway_altitude() * SG_FEET_TO_METER;
-    double length = (runway._length / 2.0) * SG_FEET_TO_METER;
-    double width = (runway._width / 2.0) * SG_FEET_TO_METER;
-    double frontLat, frontLon, backLat, backLon,az, tempLat, tempLon;
-
-    geo_direct_wgs_84(alt, runway._lat, runway._lon, runway._heading, length, &backLat, &backLon, &az);
+    double length = runway->lengthM() * 0.5;
+    double width = runway->widthM() * 0.5;
+    double frontLat = 0.0, frontLon = 0.0, backLat = 0.0, backLon = 0.0, az = 0.0, tempLat = 0.0, tempLon = 0.0;
+    double runwayLon = runway->geod().getLongitudeDeg(),
+      runwayLat = runway->geod().getLatitudeDeg();
+    double heading = runway->headingDeg();
+    
+    geo_direct_wgs_84(alt, runwayLat, runwayLon, heading, length, &backLat, &backLon, &az);
     sgGeodToCart(backLat * SG_DEGREES_TO_RADIANS, backLon * SG_DEGREES_TO_RADIANS, alt, points3d[4]);
 
-    geo_direct_wgs_84(alt, runway._lat, runway._lon, runway._heading + 180, length, &frontLat, &frontLon, &az);
+    geo_direct_wgs_84(alt, runwayLat, runwayLon, heading + 180, length, &frontLat, &frontLon, &az);
     sgGeodToCart(frontLat * SG_DEGREES_TO_RADIANS, frontLon * SG_DEGREES_TO_RADIANS, alt, points3d[5]);
 
-    geo_direct_wgs_84(alt, backLat, backLon, runway._heading + 90, width, &tempLat, &tempLon, &az);
+    geo_direct_wgs_84(alt, backLat, backLon, heading + 90, width, &tempLat, &tempLon, &az);
     sgGeodToCart(tempLat * SG_DEGREES_TO_RADIANS, tempLon * SG_DEGREES_TO_RADIANS, alt, points3d[0]);
 
-    geo_direct_wgs_84(alt, backLat, backLon, runway._heading - 90, width, &tempLat, &tempLon, &az);
+    geo_direct_wgs_84(alt, backLat, backLon, heading - 90, width, &tempLat, &tempLon, &az);
     sgGeodToCart(tempLat * SG_DEGREES_TO_RADIANS, tempLon * SG_DEGREES_TO_RADIANS, alt, points3d[1]);
 
-    geo_direct_wgs_84(alt, frontLat, frontLon, runway._heading - 90, width, &tempLat, &tempLon, &az);
+    geo_direct_wgs_84(alt, frontLat, frontLon, heading - 90, width, &tempLat, &tempLon, &az);
     sgGeodToCart(tempLat * SG_DEGREES_TO_RADIANS, tempLon * SG_DEGREES_TO_RADIANS, alt, points3d[2]);
 
-    geo_direct_wgs_84(alt, frontLat, frontLon, runway._heading + 90, width, &tempLat, &tempLon, &az);
+    geo_direct_wgs_84(alt, frontLat, frontLon, heading + 90, width, &tempLat, &tempLon, &az);
     sgGeodToCart(tempLat * SG_DEGREES_TO_RADIANS, tempLon * SG_DEGREES_TO_RADIANS, alt, points3d[3]);
-
-    for (int i = 0; i < 6; i++) {
-        points3d[i][0] -= tileCenter.x();
-        points3d[i][1] -= tileCenter.y();
-        points3d[i][2] -= tileCenter.z();
-    }
-    center = currentCenter;
 }
 
 
@@ -392,12 +385,10 @@ bool runway_instr::boundOutsidePoints(sgdVec3& v, sgdVec3& m)
 
 void runway_instr::drawArrow()
 {
-    Point3D ac(0.0), rwy(0.0);
-    ac.setlat(current_aircraft.fdm_state->get_Latitude_deg());
-    ac.setlon(current_aircraft.fdm_state->get_Longitude_deg());
-    rwy.setlat(runway._lat);
-    rwy.setlon(runway._lon);
-    float theta = GetHeadingFromTo(ac, rwy);
+    SGGeod acPos(SGGeod::fromDeg(
+        fgGetDouble("/position/longitude-deg"), 
+        fgGetDouble("/position/latitude-deg")));
+    float theta = SGGeodesy::courseDeg(acPos, runway->geod());
     theta -= fgGetDouble("/orientation/heading-deg");
     theta = -theta;
     glMatrixMode(GL_MODELVIEW);
@@ -425,13 +416,11 @@ void runway_instr::drawArrow()
 void runway_instr::setLineWidth()
 {
     //Calculate the distance from the runway, A
-    double course, distance;
-    calc_gc_course_dist(Point3D(runway._lon * SGD_DEGREES_TO_RADIANS,
-            runway._lat * SGD_DEGREES_TO_RADIANS, 0.0),
-            Point3D(current_aircraft.fdm_state->get_Longitude(),
-            current_aircraft.fdm_state->get_Latitude(), 0.0 ),
-            &course, &distance);
-    distance *= SG_METER_TO_NM;
+    SGGeod acPos(SGGeod::fromDeg(
+        fgGetDouble("/position/longitude-deg"), 
+        fgGetDouble("/position/latitude-deg")));
+    double distance = SGGeodesy::distanceNm(acPos, runway->geod());
+    
     //Get altitude above runway, B
     double alt_nm = get_agl();
     static const SGPropertyNode *startup_units_node = fgGetNode("/sim/startup/units");
@@ -441,7 +430,7 @@ void runway_instr::setLineWidth()
     else
         alt_nm *= SG_METER_TO_NM;
 
-    //Calculate distance away from runway, C = v(A²+B²)
+    //Calculate distance away from runway, C = v(A≤+B≤)
     distance = sqrt(alt_nm * alt_nm + distance*distance);
     if (distance < scaleDist)
         glLineWidth(1.0 + ((lnScale - 1) * ((scaleDist - distance) / scaleDist)));