]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/location.hxx
Merge branch 'topic/cloudz' into next
[simgear.git] / simgear / scene / model / 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 //
5 // Copyright (C) 2002  Jim Wilson, David Megginson
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _SG_LOCATION_HXX
25 #define _SG_LOCATION_HXX
26
27
28 #ifndef __cplusplus
29 # error This library requires C++
30 #endif
31
32 #include <simgear/compiler.h>
33 #include <simgear/constants.h>
34 #include <simgear/math/point3d.hxx>
35
36 #include <plib/sg.h>            // plib include
37
38
39 // Define a structure containing view information
40 class SGLocation
41 {
42
43 public:
44     // Constructor
45     SGLocation( void );
46
47     // Destructor
48     virtual ~SGLocation( void );
49
50     //////////////////////////////////////////////////////////////////////
51     // Part 2: user settings.
52     //////////////////////////////////////////////////////////////////////
53
54     // Geodetic position of model...
55     virtual double getLongitude_deg () const { return _lon_deg; }
56     virtual double getLatitude_deg () const { return _lat_deg; }
57     virtual double getAltitudeASL_ft () const { return _alt_ft; }
58     virtual void setPosition (double lon_deg, double lat_deg, double alt_ft);
59
60
61     // Reference orientation rotations...
62     //   These are rotations that represent the plane attitude effect on
63     //   the view (in Pilot view).  IE The view frustrum rotates as the plane
64     //   turns, pitches, and rolls.
65     //   In model view (lookat/chaseview) these end up changing the angle that
66     //   the eye is looking at the ojbect (ie the model).
67     //   FIXME: the FGModel class should have its own version of these so that
68     //   it can generate it's own model rotations.
69     virtual double getRoll_deg () const { return _roll_deg; }
70     virtual double getPitch_deg () const {return _pitch_deg; }
71     virtual double getHeading_deg () const {return _heading_deg; }
72     virtual void setOrientation (double roll_deg, double pitch_deg, double heading_deg);
73
74
75     //////////////////////////////////////////////////////////////////////
76     // Part 3: output vectors and matrices in FlightGear coordinates.
77     //////////////////////////////////////////////////////////////////////
78
79     // Vectors and positions...
80     
81     //! Get the absolute view position in fgfs coordinates.
82     virtual double * get_absolute_view_pos( );
83     
84     //! Return the position relative to the given scenery center.
85     virtual float * get_view_pos( const Point3D& scenery_center );
86     float * get_view_pos( const SGVec3d& sc )
87     { return get_view_pos(Point3D(sc[0], sc[1], sc[2])); }
88     
89     // Get world up vector
90     virtual float *get_world_up()
91     { recalcAbsolutePosition(); return _world_up; }
92     
93     // Get surface east vector
94     virtual float *get_surface_east()
95     { recalcAbsolutePosition(); return _surface_east; }
96     
97     // Get surface south vector
98     virtual float *get_surface_south()
99     { recalcAbsolutePosition(); return _surface_south; }
100     
101     // Elevation of ground under location (based on scenery output)...
102     void set_cur_elev_m ( double elev )      { _cur_elev_m = elev; }
103     inline double get_cur_elev_m ()          { return _cur_elev_m; }
104     
105     // Matrices...
106     virtual const sgVec4 *getTransformMatrix() {
107         recalcOrientation();
108         return TRANS;
109     }
110     virtual const sgVec4 *getCachedTransformMatrix() { return TRANS; }
111     
112     virtual const sgVec4 *getUpMatrix(const Point3D& scenery_center)  {
113         recalcAbsolutePosition();
114         return UP;
115     }
116     const sgVec4 *getUpMatrix( const SGVec3d& sc )
117     { return getUpMatrix(Point3D(sc[0], sc[1], sc[2])); }
118
119     virtual const sgVec4 *getCachedUpMatrix() { return UP; }
120
121 private:
122
123     //////////////////////////////////////////////////////////////////
124     // private data                                                 //
125     //////////////////////////////////////////////////////////////////
126
127     // flag forcing a recalc of derived view parameters
128     mutable bool _orientation_dirty, _position_dirty;
129
130     mutable sgdVec3 _absolute_view_pos;
131     mutable sgVec3 _relative_view_pos;
132
133     double _lon_deg;
134     double _lat_deg;
135     double _alt_ft;
136
137     double _roll_deg;
138     double _pitch_deg;
139     double _heading_deg;
140
141     // elevation of ground under this location...
142     double _cur_elev_m;
143
144     // surface vector heading south
145     mutable sgVec3 _surface_south;
146
147     // surface vector heading east (used to unambiguously align sky
148     // with sun)
149     mutable sgVec3 _surface_east;
150
151     // world up vector (normal to the plane tangent to the earth's
152     // surface at the spot we are directly above)
153     mutable sgVec3 _world_up;
154
155     // sg versions of our friendly matrices
156     mutable sgMat4 TRANS, UP;
157
158     //////////////////////////////////////////////////////////////////
159     // private functions                                            //
160     //////////////////////////////////////////////////////////////////
161
162     void recalcOrientation() const;
163     void recalcAbsolutePosition() const;
164 };
165
166
167 #endif // _SG_LOCATION_HXX