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/timing/sg_time.hxx>
36 #include <plib/sg.h> // plib include
39 // Define a structure containing view information
44 // flag forcing a recalc of derived view parameters
49 // the current view offset angle from forward (rotated about the
53 // the goal view offset angle (used for smooth view changes)
54 double goal_view_offset;
56 // absolute view position in earth coordinates
59 // view position in opengl world coordinates (this is the
60 // abs_view_pos translated to scenery.center)
63 // radius to sea level from center of the earth (m)
64 double sea_level_radius;
66 // cartesion coordinates of current lon/lat if at sea level
67 // translated to scenery.center
70 // pilot offset from center of gravity. The X axis is positive
71 // out the tail, Y is out the right wing, and Z is positive up.
72 // Distances in meters of course.
75 // vector in cartesian coordinates from current position to the
76 // postion on the earth's surface the sun is directly over
79 // surface direction to go to head towards sun
80 sgVec3 surface_to_sun;
82 // vector in cartesian coordinates from current position to the
83 // postion on the earth's surface the moon is directly over
86 // surface direction to go to head towards moon
87 sgVec3 surface_to_moon;
89 // surface vector heading south
92 // surface vector heading east (used to unambiguously align sky
96 // local up vector (normal to the plane tangent to the earth's
97 // surface at the spot we are directly above
100 // sg versions of our friendly matrices
101 sgMat4 VIEW, VIEW_ROT, UP;
103 inline void set_dirty() { dirty = true; }
104 inline void set_clean() { dirty = false; }
106 // Update the view volume, position, and orientation
107 virtual void update();
115 virtual ~FGViewer( void );
117 // Initialize a view class
118 virtual void init( void );
120 //////////////////////////////////////////////////////////////////////
122 //////////////////////////////////////////////////////////////////////
123 inline void set_view_offset( double a ) {
127 inline void inc_view_offset( double amt ) {
131 inline void set_goal_view_offset( double a) {
133 goal_view_offset = a;
135 inline void set_pilot_offset( float x, float y, float z ) {
137 sgSetVec3( pilot_offset, x, y, z );
139 inline void set_sea_level_radius( double r ) {
140 // data should be in meters from the center of the earth
142 sea_level_radius = r;
145 //////////////////////////////////////////////////////////////////////
146 // accessor functions
147 //////////////////////////////////////////////////////////////////////
148 inline bool is_dirty() const { return dirty; }
149 inline double get_view_offset() const { return view_offset; }
150 inline double get_goal_view_offset() const { return goal_view_offset; }
151 inline float *get_pilot_offset() { return pilot_offset; }
152 inline double get_sea_level_radius() const { return sea_level_radius; }
154 //////////////////////////////////////////////////////////////////////
155 // derived values accessor functions
156 //////////////////////////////////////////////////////////////////////
157 inline double *get_abs_view_pos() {
158 if ( dirty ) { update(); }
161 inline float *get_view_pos() {
162 if ( dirty ) { update(); }
165 inline float *get_zero_elev() {
166 if ( dirty ) { update(); }
169 inline float *get_surface_south() {
170 if ( dirty ) { update(); }
171 return surface_south;
173 inline float *get_surface_east() {
174 if ( dirty ) { update(); }
177 inline float *get_local_up() {
178 if ( dirty ) { update(); }
181 inline const sgVec4 *get_VIEW() {
182 if ( dirty ) { update(); }
185 inline const sgVec4 *get_VIEW_ROT() {
186 if ( dirty ) { update(); }
189 inline const sgVec4 *get_UP() {
190 if ( dirty ) { update(); }
194 //////////////////////////////////////////////////////////////////////
196 //////////////////////////////////////////////////////////////////////
197 inline float *get_to_sun() { return to_sun; }
198 inline void set_to_sun( float x, float y, float z ) {
199 sgSetVec3( to_sun, x, y, z );
201 inline float *get_surface_to_sun() { return surface_to_sun; }
202 inline void set_surface_to_sun( float x, float y, float z) {
203 sgSetVec3( surface_to_sun, x, y, z );
205 inline float *get_to_moon() { return to_moon; }
206 inline void set_to_moon( float x, float y, float z) {
207 sgSetVec3( to_moon, x, y, z );
209 inline float *get_surface_to_moon() { return surface_to_moon; }
210 inline void set_surface_to_moon( float x, float y, float z) {
211 sgSetVec3( surface_to_moon, x, y, z );
216 #endif // _VIEWER_HXX