1 // location.hxx -- class for determining model location in the flightgear world.
3 // Written by Jim Wilson, David Megginson, started April 2002.
5 // Copyright (C) 2002 Jim Wilson, David Megginson
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.
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.
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.
29 # error This library requires C++
32 #include <simgear/compiler.h>
33 #include <simgear/constants.h>
34 #include <simgear/math/point3d.hxx>
36 #include <plib/sg.h> // plib include
41 // Define a structure containing view information
51 virtual ~FGLocation( void );
53 //////////////////////////////////////////////////////////////////////
54 // Part 1: standard FGSubsystem implementation.
55 //////////////////////////////////////////////////////////////////////
59 virtual void unbind ();
63 //////////////////////////////////////////////////////////////////////
64 // Part 2: user settings.
65 //////////////////////////////////////////////////////////////////////
67 // Geodetic position of model...
68 virtual double getLongitude_deg () const { return _lon_deg; }
69 virtual double getLatitude_deg () const { return _lat_deg; }
70 virtual double getAltitudeASL_ft () const { return _alt_ft; }
71 virtual void setPosition (double lon_deg, double lat_deg, double alt_ft);
74 // Reference orientation rotations...
75 // These are rotations that represent the plane attitude effect on
76 // the view (in Pilot view). IE The view frustrum rotates as the plane
77 // turns, pitches, and rolls.
78 // In model view (lookat/chaseview) these end up changing the angle that
79 // the eye is looking at the ojbect (ie the model).
80 // FIXME: the FGModel class should have its own version of these so that
81 // it can generate it's own model rotations.
82 virtual double getRoll_deg () const { return _roll_deg; }
83 virtual double getPitch_deg () const {return _pitch_deg; }
84 virtual double getHeading_deg () const {return _heading_deg; }
85 virtual void setOrientation (double roll_deg, double pitch_deg, double heading_deg);
88 //////////////////////////////////////////////////////////////////////
89 // Part 3: output vectors and matrices in FlightGear coordinates.
90 //////////////////////////////////////////////////////////////////////
92 // Vectors and positions...
95 virtual float * get_view_pos() { return _relative_view_pos; }
96 // Get the absolute view position in fgfs coordinates.
97 virtual double * get_absolute_view_pos ();
99 virtual float * get_zero_elev() { return _zero_elev_view_pos; }
100 // Get world up vector
101 virtual float *get_world_up() { return _world_up; }
102 // Get the relative (to scenery center) view position in fgfs coordinates.
103 virtual float * getRelativeViewPos ();
104 // Get the absolute zero-elevation view position in fgfs coordinates.
105 virtual float * getZeroElevViewPos ();
106 // Get surface east vector
107 virtual float *get_surface_east() { return _surface_east; }
108 // Get surface south vector
109 virtual float *get_surface_south() { return _surface_south; }
110 // Elevation of ground under location (based on scenery output)...
111 void set_cur_elev_m ( double elev ) { _cur_elev_m = elev; }
112 inline double get_cur_elev_m () { return _cur_elev_m; }
113 // Interface to current buckets for use with tilemgr...
114 void set_tile_center ( Point3D tile_center ) { _tile_center = tile_center; }
115 inline Point3D get_tile_center () { return _tile_center; }
118 virtual const sgVec4 * getTransformMatrix() { if ( _dirty ) { recalc(); } return TRANS; }
119 virtual const sgVec4 * getCachedTransformMatrix() { return TRANS; }
120 virtual const sgVec4 * getUpMatrix() { if ( _dirty ) { recalc(); } return UP; }
121 virtual const sgVec4 * getCachedUpMatrix() { return UP; }
126 //////////////////////////////////////////////////////////////////
128 //////////////////////////////////////////////////////////////////
130 // flag forcing a recalc of derived view parameters
133 mutable sgdVec3 _absolute_view_pos;
134 mutable sgVec3 _relative_view_pos;
135 mutable sgVec3 _zero_elev_view_pos;
145 // elevation of ground under this location...
147 Point3D _tile_center;
149 // surface vector heading south
150 sgVec3 _surface_south;
152 // surface vector heading east (used to unambiguously align sky
154 sgVec3 _surface_east;
156 // world up vector (normal to the plane tangent to the earth's
157 // surface at the spot we are directly above
160 // sg versions of our friendly matrices
163 //////////////////////////////////////////////////////////////////
164 // private functions //
165 //////////////////////////////////////////////////////////////////
168 void recalcPosition (double lon_deg, double lat_deg, double alt_ft) const;
170 inline void set_dirty() { _dirty = true; }
171 inline void set_clean() { _dirty = false; }
176 #endif // _LOCATION_HXX