]> git.mxchange.org Git - flightgear.git/blob - src/Main/views.hxx
Rewriting old mat3 stuff with plib's sg library.
[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@infoplane.com
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 <Include/compiler.h>
33
34 #include <list>
35
36 #include <sg.h>                 // plib include
37
38 #include <FDM/flight.hxx>
39 #include <Math/mat3.h>
40 #include <Math/point3d.hxx>
41 #include <Time/fg_time.hxx>
42 #include <Time/light.hxx>
43
44 #include "options.hxx"
45
46 FG_USING_STD(list);
47
48
49 // class FGMat4Wrapper {
50 // public:
51 //     sgMat4 m;
52 // };
53
54 // typedef list < FGMat4Wrapper > sgMat4_list;
55 // typedef sgMat4_list::iterator sgMat4_list_iterator;
56 // typedef sgMat4_list::const_iterator const_sgMat4_list_iterator;
57
58
59 // used in views.cxx and tilemgr.cxx
60 #define USE_FAST_FOV_CLIP 
61
62
63 // Define a structure containing view information
64 class FGView {
65
66 public:
67
68     // the current offset from forward for viewing
69     double view_offset;
70
71     // the goal view offset for viewing (used for smooth view changes)
72     double goal_view_offset;
73
74     // flag forcing update of fov related stuff
75     bool update_fov;
76         
77     // fov of view is specified in the y direction, win_ratio is used to
78     // calculate the fov in the X direction = width/height
79     double win_ratio;
80
81     // width & height of window
82     int winWidth, winHeight;
83
84     // sin and cos of (fov / 2) in Y axis
85     double sin_fov_y, cos_fov_y;
86     double sinlon, coslon;
87
88     // slope of view frustum edge in eye space Y axis
89     double slope_y;
90
91     // sin and cos of (fov / 2) in X axis
92     double sin_fov_x, cos_fov_x;
93
94     // slope of view frustum edge in eye space X axis
95     double slope_x;
96
97 #if defined( USE_FAST_FOV_CLIP )
98     double fov_x_clip, fov_y_clip;
99 #endif // USE_FAST_FOV_CLIP
100
101     // View frustum cull ratio (% of tiles culled ... used for
102     // reporting purposes)
103     double vfc_ratio;
104
105     // Number of triangles rendered;
106     int tris_rendered;
107     int tris_culled;
108
109     // absolute view position
110     Point3D abs_view_pos;
111
112     // view position translated to scenery.center
113     Point3D view_pos;
114
115     // cartesion coordinates of current lon/lat if at sea level
116     // translated to scenery.center
117     Point3D cur_zero_elev;
118
119     // vector in cartesian coordinates from current position to the
120     // postion on the earth's surface the sun is directly over
121     sgVec3 to_sun;
122
123     // surface direction to go to head towards sun
124     sgVec3 surface_to_sun;
125
126     // vector in cartesian coordinates from current position to the
127     // postion on the earth's surface the moon is directly over
128     sgVec3 to_moon;
129   
130     // surface direction to go to head towards moon
131     sgVec3 surface_to_moon;
132
133     // surface vector heading south
134     sgVec3 surface_south;
135
136     // surface vector heading east (used to unambiguously align sky
137     // with sun)
138     sgVec3 surface_east;
139
140     // local up vector (normal to the plane tangent to the earth's
141     // surface at the spot we are directly above
142     sgVec3 local_up;
143
144     // up vector for the view (usually point straight up through the
145     // top of the aircraft
146     MAT3vec view_up;
147     sgVec3 sgview_up;
148
149     // the vector pointing straight out the nose of the aircraft
150     MAT3vec view_forward;
151
152     // Transformation matrix for eye coordinates to aircraft coordinates
153     MAT3mat AIRCRAFT;
154
155     // Transformation matrix for the view direction offset relative to
156     // the AIRCRAFT matrix
157     MAT3mat VIEW_OFFSET;
158     sgMat4 sgVIEW_OFFSET;
159
160     // Current model view matrix;
161     GLfloat MODEL_VIEW[16];
162
163     // sg versions of our friendly matrices
164     sgMat4 sgLOCAL, sgUP, sgVIEW_ROT, sgTRANS, sgVIEW, sgLARC_TO_SSG;
165
166     // queue of view matrices so we can have a follow view
167     // sgMat4_list follow;
168
169 public:
170
171     // Constructor
172     FGView( void );
173
174     // Destructor
175     ~FGView( void );
176
177     // Initialize a view class
178     void Init( void );
179
180     // Update the view volume, position, and orientation
181     void UpdateViewParams( const FGInterface& f );
182
183     // Flag to request that UpdateFOV() be called next time
184     // UpdateViewMath() is run.
185     inline void force_update_fov_math() { update_fov = true; }
186
187     // Update the view parameters
188     void UpdateViewMath( const FGInterface& f );
189
190     // Update the field of view coefficients
191     void UpdateFOV( const fgOPTIONS& o );
192
193     // accessor functions
194     inline double get_view_offset() const { return view_offset; }
195     inline void set_view_offset( double a ) { view_offset = a; }
196     inline void inc_view_offset( double amt ) { view_offset += amt; }
197     inline double get_goal_view_offset() const { return goal_view_offset; }
198     inline void set_goal_view_offset( double a) { goal_view_offset = a; }
199     inline double get_win_ratio() const { return win_ratio; }
200     inline void set_win_ratio( double r ) { win_ratio = r; }
201     inline int get_winWidth() const { return winWidth; }
202     inline void set_winWidth( int w ) { winWidth = w; }
203     inline int get_winHeight() const { return winHeight; }
204     inline void set_winHeight( int h ) { winHeight = h; }
205     inline double get_slope_y() const { return slope_y; }
206     inline double get_slope_x() const { return slope_x; }
207 #if defined( USE_FAST_FOV_CLIP )
208     inline double get_fov_x_clip() const { return fov_x_clip; }
209     inline double get_fov_y_clip() const { return fov_y_clip; }
210 #endif // USE_FAST_FOV_CLIP
211     inline double get_vfc_ratio() const { return vfc_ratio; }
212     inline void set_vfc_ratio(double r) { vfc_ratio = r; }
213     inline int get_tris_rendered() const { return tris_rendered; }
214     inline void set_tris_rendered( int tris) { tris_rendered = tris; }
215     inline int get_tris_culled() const { return tris_culled; }
216     inline void set_tris_culled( int tris) { tris_culled = tris; }
217     inline Point3D get_abs_view_pos() const { return abs_view_pos; }
218     inline Point3D get_view_pos() const { return view_pos; }
219     inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
220     inline float *get_to_sun() { return to_sun; }
221     inline void set_to_sun( float x, float y, float z) {
222         sgSetVec3( to_sun, x, y, z );
223     }
224     inline float *get_surface_to_sun() { return surface_to_sun; }
225     inline void set_surface_to_sun( float x, float y, float z) {
226         sgSetVec3( surface_to_sun, x, y, z );
227     }
228     inline float *get_to_moon() { return to_moon; }
229     inline void set_to_moon( float x, float y, float z) {
230         sgSetVec3( to_moon, x, y, z );
231     }
232     inline float *get_surface_to_moon() { return surface_to_moon; }
233     inline void set_surface_to_moon( float x, float y, float z) {
234         sgSetVec3( surface_to_moon, x, y, z );
235     }
236     inline float *get_surface_south() { return surface_south; }
237     inline float *get_surface_east() { return surface_east; }
238     inline float *get_local_up() { return local_up; }
239     inline double *get_view_forward() { return view_forward; }
240     inline GLfloat *get_MODEL_VIEW() { return MODEL_VIEW; }
241 };
242
243
244 extern FGView pilot_view;
245 extern FGView current_view;
246
247
248 #endif // _VIEWS_HXX
249
250