]> git.mxchange.org Git - flightgear.git/blob - src/Main/views.hxx
Added code to put aircraft at the end of the runway closest to the desired
[flightgear.git] / src / Main / views.hxx
1 // views.hxx -- data structures and routines for managing and view parameters.
2 //
3 // Written by Curtis Olson, started August 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@flightgear.org
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 _VIEWS_HXX
25 #define _VIEWS_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32 #include <simgear/compiler.h>
33 #include <simgear/math/point3d.hxx>
34 #include <simgear/timing/sg_time.hxx>
35
36 #include <list>
37
38 #include <plib/sg.h>            // plib include
39
40 #include <FDM/flight.hxx>
41 #include <Time/light.hxx>
42
43 #include "options.hxx"
44
45 FG_USING_STD(list);
46
47
48 #define FG_FOV_MIN 0.1
49 #define FG_FOV_MAX 179.9
50
51
52 // Define a structure containing view information
53 class FGView {
54
55 public:
56
57     // the current offset from forward for viewing
58     double view_offset;
59
60     // the goal view offset for viewing (used for smooth view changes)
61     double goal_view_offset;
62
63     // flag forcing update of fov related stuff
64     bool update_fov;
65         
66     // fov of view is specified in the y direction, win_ratio is used to
67     // calculate the fov in the X direction = width / height
68     double win_ratio;
69
70     // width & height of window
71     int winWidth, winHeight;
72
73     // absolute view position
74     Point3D abs_view_pos;
75
76     // view position translated to scenery.center
77     Point3D view_pos;
78
79     // pilot offset from center of gravity.  The X axis is positive
80     // out the tail, Y is out the right wing, and Z is positive up.
81     // Distances in meters of course.
82     sgVec3 pilot_offset;
83
84     // cartesion coordinates of current lon/lat if at sea level
85     // translated to scenery.center
86     Point3D cur_zero_elev;
87
88     // vector in cartesian coordinates from current position to the
89     // postion on the earth's surface the sun is directly over
90     sgVec3 to_sun;
91
92     // surface direction to go to head towards sun
93     sgVec3 surface_to_sun;
94
95     // vector in cartesian coordinates from current position to the
96     // postion on the earth's surface the moon is directly over
97     sgVec3 to_moon;
98   
99     // surface direction to go to head towards moon
100     sgVec3 surface_to_moon;
101
102     // surface vector heading south
103     sgVec3 surface_south;
104
105     // surface vector heading east (used to unambiguously align sky
106     // with sun)
107     sgVec3 surface_east;
108
109     // local up vector (normal to the plane tangent to the earth's
110     // surface at the spot we are directly above
111     sgVec3 local_up;
112
113     // up vector for the view (usually point straight up through the
114     // top of the aircraft
115     sgVec3 view_up;
116
117     // the vector pointing straight out the nose of the aircraft
118     sgVec3 view_forward;
119
120     // Transformation matrix for eye coordinates to aircraft coordinates
121     // sgMat4 AIRCRAFT;
122
123     // Transformation matrix for the view direction offset relative to
124     // the AIRCRAFT matrix
125     sgMat4 VIEW_OFFSET;
126
127     // sg versions of our friendly matrices
128     sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
129
130 public:
131
132     // Constructor
133     FGView( void );
134
135     // Destructor
136     ~FGView( void );
137
138     // Initialize a view class
139     void Init( void );
140
141     // Update the view volume, position, and orientation
142     void UpdateViewParams( const FGInterface& f );
143
144     // Flag to request that UpdateFOV() be called next time
145     // UpdateViewMath() is run.
146     inline void force_update_fov_math() { update_fov = true; }
147
148     // Update the view parameters
149     void UpdateViewMath( const FGInterface& f );
150
151     // Update the field of view coefficients
152     void UpdateFOV( const fgOPTIONS& o );
153
154     // Transform a vector from world coordinates to the local plane
155     void CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src);
156
157     // accessor functions
158     inline double get_view_offset() const { return view_offset; }
159     inline void set_view_offset( double a ) { view_offset = a; }
160     inline void inc_view_offset( double amt ) { view_offset += amt; }
161     inline double get_goal_view_offset() const { return goal_view_offset; }
162     inline void set_goal_view_offset( double a) { goal_view_offset = a; }
163     inline double get_win_ratio() const { return win_ratio; }
164     inline void set_win_ratio( double r ) { win_ratio = r; }
165     inline int get_winWidth() const { return winWidth; }
166     inline void set_winWidth( int w ) { winWidth = w; }
167     inline int get_winHeight() const { return winHeight; }
168     inline void set_winHeight( int h ) { winHeight = h; }
169     inline Point3D get_abs_view_pos() const { return abs_view_pos; }
170     inline Point3D get_view_pos() const { return view_pos; }
171     inline float *get_pilot_offset() { return pilot_offset; }
172     inline void set_pilot_offset( float x, float y, float z ) {
173         sgSetVec3( pilot_offset, x, y, z );
174     }
175     inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
176     inline float *get_to_sun() { return to_sun; }
177     inline void set_to_sun( float x, float y, float z ) {
178         sgSetVec3( to_sun, x, y, z );
179     }
180     inline float *get_surface_to_sun() { return surface_to_sun; }
181     inline void set_surface_to_sun( float x, float y, float z) {
182         sgSetVec3( surface_to_sun, x, y, z );
183     }
184     inline float *get_to_moon() { return to_moon; }
185     inline void set_to_moon( float x, float y, float z) {
186         sgSetVec3( to_moon, x, y, z );
187     }
188     inline float *get_surface_to_moon() { return surface_to_moon; }
189     inline void set_surface_to_moon( float x, float y, float z) {
190         sgSetVec3( surface_to_moon, x, y, z );
191     }
192     inline float *get_surface_south() { return surface_south; }
193     inline float *get_surface_east() { return surface_east; }
194     inline float *get_local_up() { return local_up; }
195     inline float *get_view_forward() { return view_forward; }
196 };
197
198
199 extern FGView pilot_view;
200 extern FGView current_view;
201
202
203 #endif // _VIEWS_HXX
204
205