]> git.mxchange.org Git - flightgear.git/blob - src/Main/viewer.hxx
334ecb68c778e3e4f8fda3507bb5004285b742e6
[flightgear.git] / src / Main / viewer.hxx
1 // viewer.hxx -- class for managing a viewer in the flightgear world.
2 //
3 // Written by Curtis Olson, started August 1997.
4 //                          overhaul started October 2000.
5 //
6 // Copyright (C) 1997 - 2000  Curtis L. Olson  - curt@flightgear.org
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23
24
25 #ifndef _VIEWER_HXX
26 #define _VIEWER_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33 #include <simgear/compiler.h>
34 #include <simgear/math/point3d.hxx>
35 #include <simgear/timing/sg_time.hxx>
36
37 #include <list>
38
39 #include <plib/sg.h>            // plib include
40
41 #include <FDM/flight.hxx>
42 #include <Time/light.hxx>
43
44 #include "options.hxx"
45
46 FG_USING_STD(list);
47
48
49 #define FG_FOV_MIN 0.1
50 #define FG_FOV_MAX 179.9
51
52
53 // Define a structure containing view information
54 class FGViewer {
55
56 private:
57
58     // the current view offset angle from forward (rotated about the
59     // view_up vector)
60     double view_offset;
61
62     // the goal view offset angle  (used for smooth view changes)
63     double goal_view_offset;
64
65     // flag forcing update of fov related stuff
66     bool update_fov;
67         
68     // fov of view is specified in the X direction, win_ratio is used to
69     // calculate the fov in the Y direction.  fov(y) = fov(x) * win_ratio
70     double win_ratio;
71
72     // width & height of window
73     int winWidth, winHeight;
74
75     // absolute view position in earth coordinates
76     Point3D abs_view_pos;
77
78     // view position in opengl world coordinates (this is the
79     // abs_view_pos translated to scenery.center)
80     Point3D view_pos;
81
82     // pilot offset from center of gravity.  The X axis is positive
83     // out the tail, Y is out the right wing, and Z is positive up.
84     // Distances in meters of course.
85     sgVec3 pilot_offset;
86
87     // cartesion coordinates of current lon/lat if at sea level
88     // translated to scenery.center
89     Point3D cur_zero_elev;
90
91     // vector in cartesian coordinates from current position to the
92     // postion on the earth's surface the sun is directly over
93     sgVec3 to_sun;
94
95     // surface direction to go to head towards sun
96     sgVec3 surface_to_sun;
97
98     // vector in cartesian coordinates from current position to the
99     // postion on the earth's surface the moon is directly over
100     sgVec3 to_moon;
101   
102     // surface direction to go to head towards moon
103     sgVec3 surface_to_moon;
104
105     // surface vector heading south
106     sgVec3 surface_south;
107
108     // surface vector heading east (used to unambiguously align sky
109     // with sun)
110     sgVec3 surface_east;
111
112     // local up vector (normal to the plane tangent to the earth's
113     // surface at the spot we are directly above
114     sgVec3 local_up;
115
116     // up vector for the view (usually point straight up through the
117     // top of the aircraft
118     sgVec3 view_up;
119
120     // the vector pointing straight out the nose of the aircraft
121     sgVec3 view_forward;
122
123     // Transformation matrix for eye coordinates to aircraft coordinates
124     // sgMat4 AIRCRAFT;
125
126     // Transformation matrix for the view direction offset relative to
127     // the AIRCRAFT matrix
128     sgMat4 VIEW_OFFSET;
129
130     // sg versions of our friendly matrices
131     sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
132
133 public:
134
135     // Constructor
136     FGViewer( void );
137
138     // Destructor
139     ~FGViewer( void );
140
141     // Initialize a view class
142     void Init( void );
143
144     // Update the view volume, position, and orientation
145     void UpdateViewParams( const FGInterface& f );
146
147     // Flag to request that UpdateFOV() be called next time
148     // UpdateViewMath() is run.
149     inline void force_update_fov_math() { update_fov = true; }
150
151     // Update the view parameters
152     void UpdateViewMath( const FGInterface& f );
153
154     // Update the field of view coefficients
155     void UpdateFOV( const FGOptions *o );
156
157     // Transform a vector from world coordinates to the local plane
158     void CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src);
159
160     // accessor functions
161     inline double get_view_offset() const { return view_offset; }
162     inline void set_view_offset( double a ) { view_offset = a; }
163     inline void inc_view_offset( double amt ) { view_offset += amt; }
164     inline double get_goal_view_offset() const { return goal_view_offset; }
165     inline void set_goal_view_offset( double a) { goal_view_offset = a; }
166     inline double get_win_ratio() const { return win_ratio; }
167     inline void set_win_ratio( double r ) { win_ratio = r; }
168     inline int get_winWidth() const { return winWidth; }
169     inline void set_winWidth( int w ) { winWidth = w; }
170     inline int get_winHeight() const { return winHeight; }
171     inline void set_winHeight( int h ) { winHeight = h; }
172     inline Point3D get_abs_view_pos() const { return abs_view_pos; }
173     inline Point3D get_view_pos() const { return view_pos; }
174     inline float *get_pilot_offset() { return pilot_offset; }
175     inline void set_pilot_offset( float x, float y, float z ) {
176         sgSetVec3( pilot_offset, x, y, z );
177     }
178     inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
179     inline float *get_to_sun() { return to_sun; }
180     inline void set_to_sun( float x, float y, float z ) {
181         sgSetVec3( to_sun, x, y, z );
182     }
183     inline float *get_surface_to_sun() { return surface_to_sun; }
184     inline void set_surface_to_sun( float x, float y, float z) {
185         sgSetVec3( surface_to_sun, x, y, z );
186     }
187     inline float *get_to_moon() { return to_moon; }
188     inline void set_to_moon( float x, float y, float z) {
189         sgSetVec3( to_moon, x, y, z );
190     }
191     inline float *get_surface_to_moon() { return surface_to_moon; }
192     inline void set_surface_to_moon( float x, float y, float z) {
193         sgSetVec3( surface_to_moon, x, y, z );
194     }
195     inline float *get_surface_south() { return surface_south; }
196     inline float *get_surface_east() { return surface_east; }
197     inline float *get_local_up() { return local_up; }
198     inline float *get_view_forward() { return view_forward; }
199
200     inline const sgVec4 *get_VIEW() { return VIEW; }
201     inline const sgVec4 *get_VIEW_ROT() { return VIEW_ROT; }
202 };
203
204 #endif // _VIEWER_HXX
205
206