1
0
Fork 0
flightgear/src/ATCDCL/ATCProjection.cxx
frohlich a99ea1c7b5 Port over remaining Point3D usage to the more type and unit safe SG* classes.
Remove leftover headers from plib/sg.

Modified Files:
 	src/AIModel/AIBase.cxx
 	src/AIModel/AIFlightPlanCreateCruise.cxx
 	src/ATCDCL/AIEntity.cxx src/ATCDCL/AIEntity.hxx
 	src/ATCDCL/AIGAVFRTraffic.cxx src/ATCDCL/AIGAVFRTraffic.hxx
 	src/ATCDCL/AILocalTraffic.cxx src/ATCDCL/AILocalTraffic.hxx
 	src/ATCDCL/AIMgr.cxx src/ATCDCL/ATC.hxx
 	src/ATCDCL/ATCDialog.cxx src/ATCDCL/ATCProjection.cxx
 	src/ATCDCL/ATCProjection.hxx src/ATCDCL/ATCutils.cxx
 	src/ATCDCL/ATCutils.hxx src/ATCDCL/approach.cxx
 	src/ATCDCL/commlist.cxx src/ATCDCL/ground.cxx
	src/ATCDCL/ground.hxx src/ATCDCL/tower.cxx
 	src/ATCDCL/tower.hxx src/Airports/calc_loc.cxx
 	src/Airports/dynamics.cxx src/Airports/groundnetwork.cxx
 	src/Airports/parking.cxx src/Airports/runwayprefs.cxx
 	src/Airports/simple.cxx src/Cockpit/cockpit.cxx
 	src/Cockpit/hud.hxx src/Cockpit/hud_card.cxx
 	src/Cockpit/hud_rwy.cxx src/Environment/environment.cxx
 	src/FDM/UFO.cxx src/FDM/SP/MagicCarpet.cxx src/GUI/dialog.hxx
 	src/Instrumentation/HUD/HUD.hxx
 	src/Instrumentation/HUD/HUD_runway.cxx
 	src/Instrumentation/KLN89/kln89.cxx src/Main/fg_init.cxx
 	src/Main/viewer.cxx src/Main/viewmgr.cxx
 	src/Model/panelnode.cxx src/MultiPlayer/mpmessages.hxx
 	src/Scenery/tilemgr.cxx src/Traffic/SchedFlight.cxx
 	src/Traffic/TrafficMgr.cxx
2009-03-18 08:00:08 +01:00

79 lines
2.8 KiB
C++

// ATCProjection.cxx - A convienience projection class for the ATC/AI system.
//
// Written by David Luff, started 2002.
//
// Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "ATCProjection.hxx"
#include <math.h>
#include <simgear/constants.h>
FGATCAlignedProjection::FGATCAlignedProjection() {
_origin.setLatitudeRad(0);
_origin.setLongitudeRad(0);
_origin.setElevationM(0);
_correction_factor = cos(_origin.getLatitudeRad());
}
FGATCAlignedProjection::FGATCAlignedProjection(const SGGeod& centre, double heading) {
_origin = centre;
_theta = heading * SG_DEGREES_TO_RADIANS;
_correction_factor = cos(_origin.getLatitudeRad());
}
FGATCAlignedProjection::~FGATCAlignedProjection() {
}
void FGATCAlignedProjection::Init(const SGGeod& centre, double heading) {
_origin = centre;
_theta = heading * SG_DEGREES_TO_RADIANS;
_correction_factor = cos(_origin.getLatitudeRad());
}
SGVec3d FGATCAlignedProjection::ConvertToLocal(const SGGeod& pt) {
// convert from lat/lon to orthogonal
double delta_lat = pt.getLatitudeRad() - _origin.getLatitudeRad();
double delta_lon = pt.getLongitudeRad() - _origin.getLongitudeRad();
double y = sin(delta_lat) * SG_EQUATORIAL_RADIUS_M;
double x = sin(delta_lon) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
// Align
if(_theta != 0.0) {
double xbar = x;
x = x*cos(_theta) - y*sin(_theta);
y = (xbar*sin(_theta)) + (y*cos(_theta));
}
return SGVec3d(x, y, pt.getElevationM());
}
SGGeod FGATCAlignedProjection::ConvertFromLocal(const SGVec3d& pt) {
// de-align
double thi = _theta * -1.0;
double x = pt.x()*cos(thi) - pt.y()*sin(thi);
double y = (pt.x()*sin(thi)) + (pt.y()*cos(thi));
// convert from orthogonal to lat/lon
double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M);
double delta_lon = asin(x / SG_EQUATORIAL_RADIUS_M) / _correction_factor;
return SGGeod::fromRadM(_origin.getLongitudeRad()+delta_lon, _origin.getLatitudeRad()+delta_lat, pt.z());
}