1 // viewer.hxx -- class for managing a viewer in the flightgear world.
3 // Written by Curtis Olson, started August 1997.
4 // overhaul started October 2000.
6 // Copyright (C) 1997 - 2000 Curtis L. Olson - curt@flightgear.org
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.
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.
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.
30 # error This library requires C++
33 #include <simgear/compiler.h>
34 #include <simgear/math/point3d.hxx>
35 #include <simgear/timing/sg_time.hxx>
39 #include <plib/sg.h> // plib include
41 #include <FDM/flight.hxx>
42 #include <Time/light.hxx>
44 #include "options.hxx"
49 #define FG_FOV_MIN 0.1
50 #define FG_FOV_MAX 179.9
53 // Define a structure containing view information
58 // the current view offset angle from forward (rotated about the
62 // the goal view offset angle (used for smooth view changes)
63 double goal_view_offset;
65 // flag forcing update of fov related stuff
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
72 // width & height of window
73 int winWidth, winHeight;
75 // absolute view position in earth coordinates
78 // view position in opengl world coordinates (this is the
79 // abs_view_pos translated to scenery.center)
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.
87 // cartesion coordinates of current lon/lat if at sea level
88 // translated to scenery.center
89 Point3D cur_zero_elev;
91 // vector in cartesian coordinates from current position to the
92 // postion on the earth's surface the sun is directly over
95 // surface direction to go to head towards sun
96 sgVec3 surface_to_sun;
98 // vector in cartesian coordinates from current position to the
99 // postion on the earth's surface the moon is directly over
102 // surface direction to go to head towards moon
103 sgVec3 surface_to_moon;
105 // surface vector heading south
106 sgVec3 surface_south;
108 // surface vector heading east (used to unambiguously align sky
112 // local up vector (normal to the plane tangent to the earth's
113 // surface at the spot we are directly above
116 // up vector for the view (usually point straight up through the
117 // top of the aircraft
120 // the vector pointing straight out the nose of the aircraft
123 // Transformation matrix for eye coordinates to aircraft coordinates
126 // Transformation matrix for the view direction offset relative to
127 // the AIRCRAFT matrix
130 // sg versions of our friendly matrices
131 sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
141 // Initialize a view class
144 // Update the view volume, position, and orientation
145 void UpdateViewParams( const FGInterface& f );
147 // Flag to request that UpdateFOV() be called next time
148 // UpdateViewMath() is run.
149 inline void force_update_fov_math() { update_fov = true; }
151 // Update the view parameters
152 void UpdateViewMath( const FGInterface& f );
154 // Update the field of view coefficients
155 void UpdateFOV( const fgOPTIONS& o );
157 // Transform a vector from world coordinates to the local plane
158 void CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src);
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 );
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 );
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 );
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 );
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 );
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; }
200 inline const sgVec4 *get_VIEW() { return VIEW; }
201 inline const sgVec4 *get_VIEW_ROT() { return VIEW_ROT; }
204 #endif // _VIEWER_HXX