1 // views.hxx -- data structures and routines for managing and view parameters.
3 // Written by Curtis Olson, started August 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@flightgear.org
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.
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.
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.
29 # error This library requires C++
32 #include <simgear/compiler.h>
33 #include <simgear/math/point3d.hxx>
34 #include <simgear/timing/sg_time.hxx>
38 #include <plib/sg.h> // plib include
40 #include <FDM/flight.hxx>
41 #include <Time/light.hxx>
43 #include "options.hxx"
48 #define FG_FOV_MIN 0.1
49 #define FG_FOV_MAX 179.9
52 // Define a structure containing view information
57 // the current offset from forward for viewing
60 // the goal view offset for viewing (used for smooth view changes)
61 double goal_view_offset;
63 // flag forcing update of fov related stuff
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
70 // width & height of window
71 int winWidth, winHeight;
73 // absolute view position
76 // view position translated to scenery.center
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.
84 // cartesion coordinates of current lon/lat if at sea level
85 // translated to scenery.center
86 Point3D cur_zero_elev;
88 // vector in cartesian coordinates from current position to the
89 // postion on the earth's surface the sun is directly over
92 // surface direction to go to head towards sun
93 sgVec3 surface_to_sun;
95 // vector in cartesian coordinates from current position to the
96 // postion on the earth's surface the moon is directly over
99 // surface direction to go to head towards moon
100 sgVec3 surface_to_moon;
102 // surface vector heading south
103 sgVec3 surface_south;
105 // surface vector heading east (used to unambiguously align sky
109 // local up vector (normal to the plane tangent to the earth's
110 // surface at the spot we are directly above
113 // up vector for the view (usually point straight up through the
114 // top of the aircraft
117 // the vector pointing straight out the nose of the aircraft
120 // Transformation matrix for eye coordinates to aircraft coordinates
123 // Transformation matrix for the view direction offset relative to
124 // the AIRCRAFT matrix
127 // sg versions of our friendly matrices
128 sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
138 // Initialize a view class
141 // Update the view volume, position, and orientation
142 void UpdateViewParams( const FGInterface& f );
144 // Flag to request that UpdateFOV() be called next time
145 // UpdateViewMath() is run.
146 inline void force_update_fov_math() { update_fov = true; }
148 // Update the view parameters
149 void UpdateViewMath( const FGInterface& f );
151 // Update the field of view coefficients
152 void UpdateFOV( const fgOPTIONS& o );
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 );
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 );
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 );
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 );
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 );
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; }
196 extern FGView pilot_view;
197 extern FGView current_view;