]> git.mxchange.org Git - flightgear.git/blob - src/Main/views.hxx
Updates to JSBsim from Jon's CVS.
[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     // accessor functions
155     inline double get_view_offset() const { return view_offset; }
156     inline void set_view_offset( double a ) { view_offset = a; }
157     inline void inc_view_offset( double amt ) { view_offset += amt; }
158     inline double get_goal_view_offset() const { return goal_view_offset; }
159     inline void set_goal_view_offset( double a) { goal_view_offset = a; }
160     inline double get_win_ratio() const { return win_ratio; }
161     inline void set_win_ratio( double r ) { win_ratio = r; }
162     inline int get_winWidth() const { return winWidth; }
163     inline void set_winWidth( int w ) { winWidth = w; }
164     inline int get_winHeight() const { return winHeight; }
165     inline void set_winHeight( int h ) { winHeight = h; }
166     inline Point3D get_abs_view_pos() const { return abs_view_pos; }
167     inline Point3D get_view_pos() const { return view_pos; }
168     inline float *get_pilot_offset() { return pilot_offset; }
169     inline void set_pilot_offset( float x, float y, float z ) {
170         sgSetVec3( pilot_offset, x, y, z );
171     }
172     inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
173     inline float *get_to_sun() { return to_sun; }
174     inline void set_to_sun( float x, float y, float z ) {
175         sgSetVec3( to_sun, x, y, z );
176     }
177     inline float *get_surface_to_sun() { return surface_to_sun; }
178     inline void set_surface_to_sun( float x, float y, float z) {
179         sgSetVec3( surface_to_sun, x, y, z );
180     }
181     inline float *get_to_moon() { return to_moon; }
182     inline void set_to_moon( float x, float y, float z) {
183         sgSetVec3( to_moon, x, y, z );
184     }
185     inline float *get_surface_to_moon() { return surface_to_moon; }
186     inline void set_surface_to_moon( float x, float y, float z) {
187         sgSetVec3( surface_to_moon, x, y, z );
188     }
189     inline float *get_surface_south() { return surface_south; }
190     inline float *get_surface_east() { return surface_east; }
191     inline float *get_local_up() { return local_up; }
192     inline float *get_view_forward() { return view_forward; }
193 };
194
195
196 extern FGView pilot_view;
197 extern FGView current_view;
198
199
200 #endif // _VIEWS_HXX
201
202