]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/hud_rwy.cxx
In the process of changing, adding and removing files the last few years
[flightgear.git] / src / Cockpit / hud_rwy.cxx
index 0b03774911aca71d052530e9e9dd023111ce2559..c1a938a9fea4f058dcbaa2c6976c3a7b50699f48 100644 (file)
@@ -20,6 +20,8 @@
 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 //
 
+#include <simgear/compiler.h>
+
 #include "hud.hxx"
 
 #include <math.h>
@@ -31,7 +33,7 @@
 #include <Environment/environment_mgr.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/math/polar3d.hxx>
-#include <GL/glu.h>
+#include SG_GLU_H
 #include <ATC/ATCutils.hxx>
 
 runway_instr::runway_instr(int x,
@@ -41,8 +43,6 @@ runway_instr::runway_instr(int x,
                                                   float scale_data,
                                                   bool working):instr_item(x,y,width,height,NULL,scale_data,0,working)
 {
-       runway = get_active_runway();
-       get_rwy_points(points3d);
        stippleOut=0xFFFF;
        stippleCen=0xFFFF;
        arrowScale = 1.0;
@@ -63,7 +63,7 @@ runway_instr::runway_instr(int x,
 }
 
 void runway_instr::draw() {
-       if (!is_broken()) {     
+       if (!is_broken() && get_active_runway(runway)) {        
                glPushAttrib(GL_LINE_STIPPLE | GL_LINE_STIPPLE_PATTERN | GL_LINE_WIDTH);
                float modelView[4][4],projMat[4][4];    
                bool anyLines;
@@ -88,8 +88,6 @@ void runway_instr::draw() {
                }               
                //Set the camera to the cockpit view to get the view of the runway from the cockpit
                ssgSetCamera((sgVec4 *)cockpit_view->get_VIEW());
-               //Get the currently active runway and the 3d points             
-               runway = get_active_runway();
                get_rwy_points(points3d);        
                //Get the current project matrix
                ssgGetProjectionMatrix(projMat);
@@ -148,13 +146,11 @@ void runway_instr::draw() {
        }//if not broken
 }
 
-FGRunway runway_instr::get_active_runway() {
+bool runway_instr::get_active_runway(FGRunway& runway) {
   FGEnvironment stationweather =
       ((FGEnvironmentMgr *)globals->get_subsystem("environment"))->getEnvironment();
   double hdg = stationweather.get_wind_from_heading_deg();  
-  FGRunway runway;
-  globals->get_runways()->search( fgGetString("/sim/presets/airport-id"), int(hdg), &runway);
-  return runway;
+  return globals->get_runways()->search( fgGetString("/sim/presets/airport-id"), int(hdg), &runway);
 }
 
 void runway_instr::get_rwy_points(sgdVec3 *points3d) { 
@@ -166,26 +162,26 @@ void runway_instr::get_rwy_points(sgdVec3 *points3d) {
        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 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);
+       geo_direct_wgs_84(alt,runway._lat,runway._lon,runway._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,runway._lat,runway._lon,runway._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,runway._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,runway._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,runway._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,runway._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++)
@@ -197,7 +193,7 @@ void runway_instr::get_rwy_points(sgdVec3 *points3d) {
        center = currentCenter;
 }
 
-bool runway_instr::drawLine(sgdVec3 a1, sgdVec3 a2, sgdVec3 point1, sgdVec3 point2) {
+bool runway_instr::drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& point1, const sgdVec3& point2) {
        sgdVec3 p1, p2;
        sgdCopyVec3(p1, point1);
        sgdCopyVec3(p2, point2);
@@ -258,7 +254,7 @@ bool runway_instr::drawLine(sgdVec3 a1, sgdVec3 a2, sgdVec3 point1, sgdVec3 poin
     return (p1Valid && p2Valid);
 }
 
-void runway_instr::boundPoint(sgdVec3 v, sgdVec3 m) {
+void runway_instr::boundPoint(const sgdVec3& v, sgdVec3& m) {
        double y = v[1];
        if(m[1] < v[1]) {
                y = location.bottom;
@@ -283,7 +279,7 @@ void runway_instr::boundPoint(sgdVec3 v, sgdVec3 m) {
        }
 }
 
-bool runway_instr::boundOutsidePoints(sgdVec3 v, sgdVec3 m) {
+bool runway_instr::boundOutsidePoints(sgdVec3& v, sgdVec3& m) {
        bool pointsInvalid = (v[1]>location.top && m[1]>location.top) ||
                               (v[1]<location.bottom && m[1]<location.bottom) ||
                                           (v[0]>location.right && m[0]>location.right) ||
@@ -355,11 +351,11 @@ bool runway_instr::boundOutsidePoints(sgdVec3 v, sgdVec3 m) {
 }
 
 void runway_instr::drawArrow() {
-       Point3D ac,rwy;
+       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);
+       rwy.setlat(runway._lat);
+       rwy.setlon(runway._lon);
        float theta = GetHeadingFromTo(ac,rwy);
        theta -= fgGetDouble("/orientation/heading-deg");
        theta = -theta;
@@ -386,7 +382,7 @@ 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),
+       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;