]> git.mxchange.org Git - flightgear.git/blob - src/Main/location.hxx
Fix for vanishing-model problem: models are drawn in the same scene
[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 //
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _LOCATION_HXX
25 #define _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
35 #include <plib/sg.h>            // plib include
36
37 #include "fgfs.hxx"
38
39
40 // Define a structure containing view information
41 class FGLocation
42 {
43
44 public:
45
46     // Constructor
47     FGLocation( void );
48
49     // Destructor
50     virtual ~FGLocation( void );
51
52     //////////////////////////////////////////////////////////////////////
53     // Part 1: standard FGSubsystem implementation.
54     //////////////////////////////////////////////////////////////////////
55
56     virtual void init ();
57     virtual void bind ();
58     virtual void unbind ();
59     void update (int dt);
60
61
62     //////////////////////////////////////////////////////////////////////
63     // Part 2: user settings.
64     //////////////////////////////////////////////////////////////////////
65
66     // Geodetic position of model...
67     virtual double getLongitude_deg () const { return _lon_deg; }
68     virtual double getLatitude_deg () const { return _lat_deg; }
69     virtual double getAltitudeASL_ft () const { return _alt_ft; }
70     virtual void setPosition (double lon_deg, double lat_deg, double alt_ft);
71
72
73     // Reference orientation rotations...
74     //   These are rotations that represent the plane attitude effect on
75     //   the view (in Pilot view).  IE The view frustrum rotates as the plane
76     //   turns, pitches, and rolls.
77     //   In model view (lookat/chaseview) these end up changing the angle that
78     //   the eye is looking at the ojbect (ie the model).
79     //   FIXME: the FGModel class should have its own version of these so that
80     //   it can generate it's own model rotations.
81     virtual double getRoll_deg () const { return _roll_deg; }
82     virtual double getPitch_deg () const {return _pitch_deg; }
83     virtual double getHeading_deg () const {return _heading_deg; }
84     virtual void setOrientation (double roll_deg, double pitch_deg, double heading_deg);
85
86
87     //////////////////////////////////////////////////////////////////////
88     // Part 3: output vectors and matrices in FlightGear coordinates.
89     //////////////////////////////////////////////////////////////////////
90
91     // Vectors and positions...
92
93     // Get zero view_pos
94     virtual float * get_view_pos() { return _relative_view_pos; }
95     // Get the absolute view position in fgfs coordinates.
96     virtual double * get_absolute_view_pos ();
97     // Get zero elev
98     virtual float * get_zero_elev() { return _zero_elev_view_pos; }
99     // Get world up vector
100     virtual float *get_world_up() { return _world_up; }
101     // Get the relative (to scenery center) view position in fgfs coordinates.
102     virtual float * getRelativeViewPos ();
103     // Get the absolute zero-elevation view position in fgfs coordinates.
104     virtual float * getZeroElevViewPos ();
105     // Get surface east vector
106     virtual float *get_surface_east() { return _surface_east; }
107     // Get surface south vector
108     virtual float *get_surface_south() { return _surface_south; }
109
110     // Matrices...
111     virtual const sgVec4 * getTransformMatrix() { if ( _dirty ) { recalc(); }   return TRANS; }
112     virtual const sgVec4 * getCachedTransformMatrix() { return TRANS; }
113     virtual const sgVec4 * getUpMatrix()  { if ( _dirty ) { recalc(); } return UP; }
114     virtual const sgVec4 * getCachedUpMatrix()  { return UP; }
115
116
117 private:
118
119     //////////////////////////////////////////////////////////////////
120     // private data                                                 //
121     //////////////////////////////////////////////////////////////////
122
123     // flag forcing a recalc of derived view parameters
124     bool _dirty;
125
126     mutable sgdVec3 _absolute_view_pos;
127     mutable sgVec3 _relative_view_pos;
128     mutable sgVec3 _zero_elev_view_pos;
129
130     double _lon_deg;
131     double _lat_deg;
132     double _alt_ft;
133
134     double _roll_deg;
135     double _pitch_deg;
136     double _heading_deg;
137
138     // surface vector heading south
139     sgVec3 _surface_south;
140
141     // surface vector heading east (used to unambiguously align sky
142     // with sun)
143     sgVec3 _surface_east;
144
145     // world up vector (normal to the plane tangent to the earth's
146     // surface at the spot we are directly above
147     sgVec3 _world_up;
148
149     // sg versions of our friendly matrices
150     sgMat4 TRANS, UP;
151
152     //////////////////////////////////////////////////////////////////
153     // private functions                                            //
154     //////////////////////////////////////////////////////////////////
155
156     void recalc ();
157     void recalcPosition (double lon_deg, double lat_deg, double alt_ft) const;
158
159     inline void set_dirty() { _dirty = true; }
160     inline void set_clean() { _dirty = false; }
161
162 };
163
164
165 #endif // _LOCATION_HXX
166
167
168
169
170
171
172
173
174
175
176
177
178
179