1 // location.hxx -- class for determining model location in the flightgear world.
3 // Written by Jim Wilson, David Megginson, started April 2002.
4 // overhaul started October 2000.
6 // This file is in the Public Domain, and comes with no warranty.
14 # error This library requires C++
17 #include <simgear/compiler.h>
18 #include <simgear/constants.h>
20 #include <plib/sg.h> // plib include
25 // Define a structure containing view information
35 virtual ~FGLocation( void );
37 //////////////////////////////////////////////////////////////////////
38 // Part 1: standard FGSubsystem implementation.
39 //////////////////////////////////////////////////////////////////////
43 virtual void unbind ();
47 //////////////////////////////////////////////////////////////////////
48 // Part 2: user settings.
49 //////////////////////////////////////////////////////////////////////
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);
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);
72 //////////////////////////////////////////////////////////////////////
73 // Part 3: output vectors and matrices in FlightGear coordinates.
74 //////////////////////////////////////////////////////////////////////
76 // Vectors and positions...
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 ();
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; }
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; }
104 //////////////////////////////////////////////////////////////////
106 //////////////////////////////////////////////////////////////////
108 // flag forcing a recalc of derived view parameters
111 mutable sgdVec3 _absolute_view_pos;
112 mutable sgVec3 _relative_view_pos;
113 mutable sgVec3 _zero_elev_view_pos;
123 // surface vector heading south
124 sgVec3 _surface_south;
126 // surface vector heading east (used to unambiguously align sky
128 sgVec3 _surface_east;
130 // world up vector (normal to the plane tangent to the earth's
131 // surface at the spot we are directly above
134 // sg versions of our friendly matrices
137 //////////////////////////////////////////////////////////////////
138 // private functions //
139 //////////////////////////////////////////////////////////////////
142 void recalcPosition (double lon_deg, double lat_deg, double alt_ft) const;
144 inline void set_dirty() { _dirty = true; }
145 inline void set_clean() { _dirty = false; }
150 #endif // _LOCATION_HXX