]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCProjection.cxx
Moved some of the low level scene graph construction code over to simgear.
[flightgear.git] / src / ATC / ATCProjection.cxx
1 // ATCProjection.cxx - A convienience projection class for the ATC/AI system.
2 //
3 // Written by David Luff, started 2002.
4 //
5 // Copyright (C) 2002  David C Luff - david.luff@nottingham.ac.uk
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 #include "ATCProjection.hxx"
22 #include <math.h>
23 #include <simgear/constants.h>
24
25 #define DCL_PI  3.1415926535f
26 //#define SG_PI  ((SGfloat) M_PI)
27 #define DCL_DEGREES_TO_RADIANS  (DCL_PI/180.0)
28 #define DCL_RADIANS_TO_DEGREES  (180.0/DCL_PI)
29
30 FGATCProjection::FGATCProjection() {
31     origin.setlat(0.0);
32     origin.setlon(0.0);
33     origin.setelev(0.0);
34     correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
35 }
36
37 FGATCProjection::~FGATCProjection() {
38 }
39
40 void FGATCProjection::Init(Point3D centre) {
41     origin = centre;
42     correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
43 }
44
45 Point3D FGATCProjection::ConvertToLocal(Point3D pt) {
46     double delta_lat = pt.lat() - origin.lat();
47     double delta_lon = pt.lon() - origin.lon();
48
49     double y = sin(delta_lat * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
50     double x = sin(delta_lon * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * correction_factor;
51
52     return(Point3D(x,y,0.0));
53 }
54
55 Point3D FGATCProjection::ConvertFromLocal(Point3D pt) {
56     return(Point3D(0,0,0));
57 }
58
59 /**********************************************************************************/
60
61 FGATCAlignedProjection::FGATCAlignedProjection() {
62     origin.setlat(0.0);
63     origin.setlon(0.0);
64     origin.setelev(0.0);
65     correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
66 }
67
68 FGATCAlignedProjection::~FGATCAlignedProjection() {
69 }
70
71 void FGATCAlignedProjection::Init(Point3D centre, double heading) {
72     origin = centre;
73     theta = heading * DCL_DEGREES_TO_RADIANS;
74     correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
75 }
76
77 Point3D FGATCAlignedProjection::ConvertToLocal(Point3D pt) {
78     // convert from lat/lon to orthogonal
79     double delta_lat = pt.lat() - origin.lat();
80     double delta_lon = pt.lon() - origin.lon();
81     double y = sin(delta_lat * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
82     double x = sin(delta_lon * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * correction_factor;
83     //cout << "Before alignment, x = " << x << " y = " << y << '\n';
84
85     // Align
86     double xbar = x;
87     x = x*cos(theta) - y*sin(theta);
88     y = (xbar*sin(theta)) + (y*cos(theta));
89     //cout << "After alignment, x = " << x << " y = " << y << '\n';
90
91     return(Point3D(x,y,0.0));
92 }
93
94 Point3D FGATCAlignedProjection::ConvertFromLocal(Point3D pt) {
95     return(Point3D(0,0,0));
96 }