]> git.mxchange.org Git - flightgear.git/blob - src/Main/location.hxx
This patch includes the FGLocation class, a few fixes, cleanup in viewer code.
[flightgear.git] / src / Main / location.hxx
1 // location.hxx -- class for determining model location in the flightgear world.
2 //
3 // Written by Jim Wilson,  David Megginson, started April 2002.
4 //                          overhaul started October 2000.
5 //
6 // This file is in the Public Domain, and comes with no warranty.
7
8
9 #ifndef _LOCATION_HXX
10 #define _LOCATION_HXX
11
12
13 #ifndef __cplusplus                                                          
14 # error This library requires C++
15 #endif                                   
16
17 #include <simgear/compiler.h>
18 #include <simgear/constants.h>
19
20 #include <plib/sg.h>            // plib include
21
22 #include "fgfs.hxx"
23
24
25 // Define a structure containing view information
26 class FGLocation
27 {
28
29 public:
30
31     // Constructor
32     FGLocation( void );
33
34     // Destructor
35     virtual ~FGLocation( void );
36
37     //////////////////////////////////////////////////////////////////////
38     // Part 1: standard FGSubsystem implementation.
39     //////////////////////////////////////////////////////////////////////
40
41     virtual void init ();
42     virtual void bind ();
43     virtual void unbind ();
44     void update (int dt);
45
46
47     //////////////////////////////////////////////////////////////////////
48     // Part 2: user settings.
49     //////////////////////////////////////////////////////////////////////
50
51     // Geodetic position of model...
52     virtual double getLongitude_deg () const { return _lon_deg; }
53     virtual double getLatitude_deg () const { return _lat_deg; }
54     virtual double getAltitudeASL_ft () const { return _alt_ft; }
55     virtual void setPosition (double lon_deg, double lat_deg, double alt_ft);
56
57
58     // Reference orientation rotations...
59     //   These are rotations that represent the plane attitude effect on
60     //   the view (in Pilot view).  IE The view frustrum rotates as the plane
61     //   turns, pitches, and rolls.
62     //   In model view (lookat/chaseview) these end up changing the angle that
63     //   the eye is looking at the ojbect (ie the model).
64     //   FIXME: the FGModel class should have its own version of these so that
65     //   it can generate it's own model rotations.
66     virtual double getRoll_deg () const { return _roll_deg; }
67     virtual double getPitch_deg () const {return _pitch_deg; }
68     virtual double getHeading_deg () const {return _heading_deg; }
69     virtual void setOrientation (double roll_deg, double pitch_deg, double heading_deg);
70
71
72     //////////////////////////////////////////////////////////////////////
73     // Part 3: output vectors and matrices in FlightGear coordinates.
74     //////////////////////////////////////////////////////////////////////
75
76     // Vectors and positions...
77
78     // Get zero view_pos
79     virtual float * get_view_pos() { return _relative_view_pos; }
80     // Get the absolute view position in fgfs coordinates.
81     virtual double * get_absolute_view_pos ();
82     // Get zero elev
83     virtual float * get_zero_elev() { return _zero_elev_view_pos; }
84     // Get world up vector
85     virtual float *get_world_up() { return _world_up; }
86     // Get the relative (to scenery center) view position in fgfs coordinates.
87     virtual float * getRelativeViewPos ();
88     // Get the absolute zero-elevation view position in fgfs coordinates.
89     virtual float * getZeroElevViewPos ();
90     // Get surface east vector
91     virtual float *get_surface_east() { return _surface_east; }
92     // Get surface south vector
93     virtual float *get_surface_south() { return _surface_south; }
94
95     // Matrices...
96     virtual const sgMat4 &getTransformMatrix() { if ( _dirty ) { recalc(); }    return TRANS; }
97     virtual const sgMat4 &getCachedTransformMatrix() { return TRANS; }
98     virtual const sgMat4 &getUpMatrix()  { if ( _dirty ) { recalc(); }  return UP; }
99     virtual const sgMat4 &getCachedUpMatrix()  { return UP; }
100
101
102 private:
103
104     //////////////////////////////////////////////////////////////////
105     // private data                                                 //
106     //////////////////////////////////////////////////////////////////
107
108     // flag forcing a recalc of derived view parameters
109     bool _dirty;
110
111     mutable sgdVec3 _absolute_view_pos;
112     mutable sgVec3 _relative_view_pos;
113     mutable sgVec3 _zero_elev_view_pos;
114
115     double _lon_deg;
116     double _lat_deg;
117     double _alt_ft;
118
119     double _roll_deg;
120     double _pitch_deg;
121     double _heading_deg;
122
123     // surface vector heading south
124     sgVec3 _surface_south;
125
126     // surface vector heading east (used to unambiguously align sky
127     // with sun)
128     sgVec3 _surface_east;
129
130     // world up vector (normal to the plane tangent to the earth's
131     // surface at the spot we are directly above
132     sgVec3 _world_up;
133
134     // sg versions of our friendly matrices
135     sgMat4 TRANS, UP;
136
137     //////////////////////////////////////////////////////////////////
138     // private functions                                            //
139     //////////////////////////////////////////////////////////////////
140
141     void recalc ();
142     void recalcPosition (double lon_deg, double lat_deg, double alt_ft) const;
143
144     inline void set_dirty() { _dirty = true; }
145     inline void set_clean() { _dirty = false; }
146
147 };
148
149
150 #endif // _LOCATION_HXX
151
152
153
154
155
156
157
158
159
160
161
162
163