]> git.mxchange.org Git - flightgear.git/blob - src/Main/viewmgr.cxx
proper sound orientation(?) and comment out velocity since it messes with OpenAL...
[flightgear.git] / src / Main / viewmgr.cxx
1 // viewmgr.cxx -- class for managing all the views in the flightgear world.
2 //
3 // Written by Curtis Olson, started October 2000.
4 //   partially rewritten by Jim Wilson March 2002
5 //
6 // Copyright (C) 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
7 //
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.
12 //
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.
17 //
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 // $Id$
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "viewmgr.hxx"
29
30 #include <string.h>             // strcmp
31
32 #include <simgear/compiler.h>
33 #include <simgear/sound/soundmgr_openal.hxx>
34 #include <Model/acmodel.hxx>
35 #include <Main/viewer.hxx>
36 #include <Main/fg_props.hxx>
37
38 // Constructor
39 FGViewMgr::FGViewMgr( void ) :
40   axis_long(0),
41   axis_lat(0),
42   view_number(fgGetNode("/sim/current-view/view-number", true)),
43   config_list(fgGetNode("/sim", true)->getChildren("view")),
44   current(0)
45 {
46     smgr = globals->get_soundmgr();
47 }
48
49 // Destructor
50 FGViewMgr::~FGViewMgr( void ) {
51 }
52
53 void
54 FGViewMgr::init ()
55 {
56   double aspect_ratio_multiplier
57       = fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
58
59   for (unsigned int i = 0; i < config_list.size(); i++) {
60     SGPropertyNode *n = config_list[i];
61
62     // find out if this is an internal view (e.g. in cockpit, low near plane)
63     bool internal = n->getBoolValue("internal", false);
64
65     // FIXME:
66     // this is assumed to be an aircraft model...we will need to read
67     // model-from-type as well.
68
69     // find out if this is a model we are looking from...
70     bool from_model = n->getBoolValue("config/from-model");
71     int from_model_index = n->getIntValue("config/from-model-idx");
72
73     double x_offset_m = n->getDoubleValue("config/x-offset-m");
74     double y_offset_m = n->getDoubleValue("config/y-offset-m");
75     double z_offset_m = n->getDoubleValue("config/z-offset-m");
76
77     double heading_offset_deg = n->getDoubleValue("config/heading-offset-deg");
78     n->setDoubleValue("config/heading-offset-deg", heading_offset_deg);
79     double pitch_offset_deg = n->getDoubleValue("config/pitch-offset-deg");
80     n->setDoubleValue("config/pitch-offset-deg", pitch_offset_deg);
81     double roll_offset_deg = n->getDoubleValue("config/roll-offset-deg");
82     n->setDoubleValue("config/roll-offset-deg", roll_offset_deg);
83
84     double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
85     double near_m = n->getDoubleValue("config/ground-level-nearplane-m");
86
87     // supporting two types "lookat" = 1 and "lookfrom" = 0
88     const char *type = n->getStringValue("type");
89     if (!strcmp(type, "lookat")) {
90
91       bool at_model = n->getBoolValue("config/at-model");
92       int at_model_index = n->getIntValue("config/at-model-idx");
93
94       double damp_roll = n->getDoubleValue("config/at-model-roll-damping");
95       double damp_pitch = n->getDoubleValue("config/at-model-pitch-damping");
96       double damp_heading = n->getDoubleValue("config/at-model-heading-damping");
97
98       double target_x_offset_m = n->getDoubleValue("config/target-x-offset-m");
99       double target_y_offset_m = n->getDoubleValue("config/target-y-offset-m");
100       double target_z_offset_m = n->getDoubleValue("config/target-z-offset-m");
101
102       add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
103                               at_model, at_model_index,
104                               damp_roll, damp_pitch, damp_heading,
105                               x_offset_m, y_offset_m,z_offset_m,
106                               heading_offset_deg, pitch_offset_deg,
107                               roll_offset_deg, fov_deg, aspect_ratio_multiplier,
108                               target_x_offset_m, target_y_offset_m,
109                               target_z_offset_m, near_m, internal ));
110     } else {
111       add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index,
112                               false, 0, 0.0, 0.0, 0.0,
113                               x_offset_m, y_offset_m, z_offset_m,
114                               heading_offset_deg, pitch_offset_deg,
115                               roll_offset_deg, fov_deg, aspect_ratio_multiplier,
116                               0, 0, 0, near_m, internal ));
117     }
118   }
119
120   copyToCurrent();
121 }
122
123 void
124 FGViewMgr::reinit ()
125 {
126   // reset offsets and fov to configuration defaults
127   for (unsigned int i = 0; i < config_list.size(); i++) {
128     SGPropertyNode *n = config_list[i];
129     setView(i);
130
131     fgSetDouble("/sim/current-view/x-offset-m",
132         n->getDoubleValue("config/x-offset-m"));
133     fgSetDouble("/sim/current-view/y-offset-m",
134         n->getDoubleValue("config/y-offset-m"));
135     fgSetDouble("/sim/current-view/z-offset-m",
136         n->getDoubleValue("config/z-offset-m"));
137     fgSetDouble("/sim/current-view/pitch-offset-deg",
138         n->getDoubleValue("config/pitch-offset-deg"));
139     fgSetDouble("/sim/current-view/heading-offset-deg",
140         n->getDoubleValue("config/heading-offset-deg"));
141     fgSetDouble("/sim/current-view/roll-offset-deg",
142         n->getDoubleValue("config/roll-offset-deg"));
143
144     double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
145     if (fov_deg < 10.0)
146       fov_deg = 55.0;
147     fgSetDouble("/sim/current-view/field-of-view", fov_deg);
148
149     // target offsets for lookat mode only...
150     fgSetDouble("/sim/current-view/target-x-offset-m",
151         n->getDoubleValue("config/target-x-offset-m"));
152     fgSetDouble("/sim/current-view/target-y-offset-m",
153         n->getDoubleValue("config/target-y-offset-m"));
154     fgSetDouble("/sim/current-view/target-z-offset-m",
155         n->getDoubleValue("config/target-z-offset-m"));
156   }
157   setView(0);
158 }
159
160 typedef double (FGViewMgr::*double_getter)() const;
161
162 void
163 FGViewMgr::bind ()
164 {
165   // these are bound to the current view properties
166   fgTie("/sim/current-view/heading-offset-deg", this,
167         &FGViewMgr::getViewHeadingOffset_deg,
168         &FGViewMgr::setViewHeadingOffset_deg);
169   fgSetArchivable("/sim/current-view/heading-offset-deg");
170   fgTie("/sim/current-view/goal-heading-offset-deg", this,
171         &FGViewMgr::getViewGoalHeadingOffset_deg,
172         &FGViewMgr::setViewGoalHeadingOffset_deg);
173   fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
174   fgTie("/sim/current-view/pitch-offset-deg", this,
175         &FGViewMgr::getViewPitchOffset_deg,
176         &FGViewMgr::setViewPitchOffset_deg);
177   fgSetArchivable("/sim/current-view/pitch-offset-deg");
178   fgTie("/sim/current-view/goal-pitch-offset-deg", this,
179         &FGViewMgr::getGoalViewPitchOffset_deg,
180         &FGViewMgr::setGoalViewPitchOffset_deg);
181   fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
182   fgTie("/sim/current-view/roll-offset-deg", this,
183         &FGViewMgr::getViewRollOffset_deg,
184         &FGViewMgr::setViewRollOffset_deg);
185   fgSetArchivable("/sim/current-view/roll-offset-deg");
186   fgTie("/sim/current-view/goal-roll-offset-deg", this,
187         &FGViewMgr::getGoalViewRollOffset_deg,
188         &FGViewMgr::setGoalViewRollOffset_deg);
189   fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
190
191   fgTie("/sim/current-view/view-number", this,
192                       &FGViewMgr::getView, &FGViewMgr::setView);
193   fgSetArchivable("/sim/current-view/view-number", FALSE);
194
195   fgTie("/sim/current-view/axes/long", this,
196         (double_getter)0, &FGViewMgr::setViewAxisLong);
197   fgSetArchivable("/sim/current-view/axes/long");
198
199   fgTie("/sim/current-view/axes/lat", this,
200         (double_getter)0, &FGViewMgr::setViewAxisLat);
201   fgSetArchivable("/sim/current-view/axes/lat");
202
203   fgTie("/sim/current-view/field-of-view", this,
204         &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
205   fgSetArchivable("/sim/current-view/field-of-view");
206
207   fgTie("/sim/current-view/aspect-ratio-multiplier", this,
208         &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
209   fgSetArchivable("/sim/current-view/field-of-view");
210
211   fgTie("/sim/current-view/ground-level-nearplane-m", this,
212         &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
213   fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
214
215   SGPropertyNode *n = fgGetNode("/sim/current-view", true);
216   n->tie("viewer-x-m", SGRawValuePointer<double>(&abs_viewer_position[0]));
217   n->tie("viewer-y-m", SGRawValuePointer<double>(&abs_viewer_position[1]));
218   n->tie("viewer-z-m", SGRawValuePointer<double>(&abs_viewer_position[2]));
219 }
220
221 void
222 FGViewMgr::unbind ()
223 {
224   // FIXME:
225   // need to redo these bindings to the new locations (move to viewer?)
226   fgUntie("/sim/current-view/heading-offset-deg");
227   fgUntie("/sim/current-view/goal-heading-offset-deg");
228   fgUntie("/sim/current-view/pitch-offset-deg");
229   fgUntie("/sim/current-view/goal-pitch-offset-deg");
230   fgUntie("/sim/current-view/field-of-view");
231   fgUntie("/sim/current-view/aspect-ratio-multiplier");
232   fgUntie("/sim/current-view/view-number");
233   fgUntie("/sim/current-view/axes/long");
234   fgUntie("/sim/current-view/axes/lat");
235   fgUntie("/sim/current-view/ground-level-nearplane-m");
236   fgUntie("/sim/current-view/viewer-x-m");
237   fgUntie("/sim/current-view/viewer-y-m");
238   fgUntie("/sim/current-view/viewer-z-m");
239 }
240
241 void
242 FGViewMgr::update (double dt)
243 {
244   FGViewer * view = get_current_view();
245   if (view == 0)
246     return;
247
248   FGViewer *loop_view = (FGViewer *)get_view(current);
249   SGPropertyNode *n = config_list[current];
250   double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
251
252   // Set up view location and orientation
253
254   if (!n->getBoolValue("config/from-model")) {
255     lon_deg = fgGetDouble(n->getStringValue("config/eye-lon-deg-path"));
256     lat_deg = fgGetDouble(n->getStringValue("config/eye-lat-deg-path"));
257     alt_ft = fgGetDouble(n->getStringValue("config/eye-alt-ft-path"));
258     roll_deg = fgGetDouble(n->getStringValue("config/eye-roll-deg-path"));
259     pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path"));
260     heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path"));
261
262     loop_view->setPosition(lon_deg, lat_deg, alt_ft);
263     loop_view->setOrientation(roll_deg, pitch_deg, heading_deg);
264   } else {
265     // force recalc in viewer
266     loop_view->set_dirty();
267   }
268
269   // if lookat (type 1) then get target data...
270   if (loop_view->getType() == FG_LOOKAT) {
271     if (!n->getBoolValue("config/from-model")) {
272       lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path"));
273       lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path"));
274       alt_ft = fgGetDouble(n->getStringValue("config/target-alt-ft-path"));
275       roll_deg = fgGetDouble(n->getStringValue("config/target-roll-deg-path"));
276       pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path"));
277       heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path"));
278
279       loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft);
280       loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
281     } else {
282       loop_view->set_dirty();
283     }
284   }
285
286   setViewXOffset_m(fgGetDouble("/sim/current-view/x-offset-m"));
287   setViewYOffset_m(fgGetDouble("/sim/current-view/y-offset-m"));
288   setViewZOffset_m(fgGetDouble("/sim/current-view/z-offset-m"));
289
290   setViewTargetXOffset_m(fgGetDouble("/sim/current-view/target-x-offset-m"));
291   setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m"));
292   setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m"));
293
294   // Update the current view
295   do_axes();
296   view->update(dt);
297   abs_viewer_position = loop_view->getViewPosition();
298
299   // update audio listener values
300   // set the viewer posotion in Cartesian coordinates in meters
301   SGVec3d offs = SGVec3d( loop_view->getXOffset_m(),
302                           loop_view->getYOffset_m(),
303                           loop_view->getZOffset_m());
304   smgr->set_position_offset( offs );
305   smgr->set_position_geod( loop_view->getPosition() );
306
307   smgr->set_orientation( loop_view->getViewOrientation(),
308                          loop_view->getViewOrientationOffset() );
309
310   // get the model velocity
311   SGVec3f velocity = SGVec3f::zeros();
312   if ( !stationary() ) {
313     velocity = globals->get_aircraft_model()->getVelocity();
314   }
315   smgr->set_velocity(velocity);
316 }
317
318 void
319 FGViewMgr::copyToCurrent()
320 {
321     SGPropertyNode *n = config_list[current];
322     fgSetString("/sim/current-view/name", n->getStringValue("name"));
323     fgSetString("/sim/current-view/type", n->getStringValue("type"));
324
325     // copy certain view config data for default values
326     fgSetDouble("/sim/current-view/config/heading-offset-deg",
327                 n->getDoubleValue("config/default-heading-offset-deg"));
328     fgSetDouble("/sim/current-view/config/pitch-offset-deg",
329                 n->getDoubleValue("config/pitch-offset-deg"));
330     fgSetDouble("/sim/current-view/config/roll-offset-deg",
331                 n->getDoubleValue("config/roll-offset-deg"));
332     fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
333                 n->getDoubleValue("config/default-field-of-view-deg"));
334     fgSetBool("/sim/current-view/config/from-model",
335                 n->getBoolValue("config/from-model"));
336
337     // copy view data
338     fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
339     fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
340     fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
341
342     fgSetDouble("/sim/current-view/goal-heading-offset-deg",
343                 get_current_view()->getGoalHeadingOffset_deg());
344     fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
345                 get_current_view()->getGoalPitchOffset_deg());
346     fgSetDouble("/sim/current-view/goal-roll-offset-deg",
347                 get_current_view()->getRollOffset_deg());
348     fgSetDouble("/sim/current-view/heading-offset-deg",
349                 get_current_view()->getHeadingOffset_deg());
350     fgSetDouble("/sim/current-view/pitch-offset-deg",
351                 get_current_view()->getPitchOffset_deg());
352     fgSetDouble("/sim/current-view/roll-offset-deg",
353                 get_current_view()->getRollOffset_deg());
354     fgSetDouble("/sim/current-view/target-x-offset-m",
355                 get_current_view()->getTargetXOffset_m());
356     fgSetDouble("/sim/current-view/target-y-offset-m",
357                 get_current_view()->getTargetYOffset_m());
358     fgSetDouble("/sim/current-view/target-z-offset-m",
359                 get_current_view()->getTargetZOffset_m());
360     fgSetBool("/sim/current-view/internal",
361                 get_current_view()->getInternal());
362 }
363
364 void FGViewMgr::clear()
365 {
366   views.clear();
367 }
368
369 FGViewer*
370 FGViewMgr::get_current_view()
371 {
372         if ( current < (int)views.size() ) {
373             return views[current];
374         } else {
375             return NULL;
376         }
377 }
378
379 const FGViewer*
380 FGViewMgr::get_current_view() const
381 {
382         if ( current < (int)views.size() ) {
383             return views[current];
384         } else {
385             return NULL;
386         }
387 }
388
389
390 FGViewer*
391 FGViewMgr::get_view( int i )
392 {
393         if ( i < 0 ) { i = 0; }
394         if ( i >= (int)views.size() ) { i = views.size() - 1; }
395         return views[i];
396 }
397
398 const FGViewer*
399 FGViewMgr::get_view( int i ) const
400 {
401         if ( i < 0 ) { i = 0; }
402         if ( i >= (int)views.size() ) { i = views.size() - 1; }
403         return views[i];
404 }
405
406 FGViewer*
407 FGViewMgr::next_view()
408 {
409         setView((current+1 < (int)views.size()) ? (current + 1) : 0);
410         view_number->fireValueChanged();
411         return views[current];
412 }
413
414 FGViewer*
415 FGViewMgr::prev_view()
416 {
417         setView((0 < current) ? (current - 1) : (views.size() - 1));
418         view_number->fireValueChanged();
419         return views[current];
420 }
421
422 void
423 FGViewMgr::add_view( FGViewer * v )
424 {
425   views.push_back(v);
426   v->init();
427 }
428     
429 double
430 FGViewMgr::getViewHeadingOffset_deg () const
431 {
432   const FGViewer * view = get_current_view();
433   return (view == 0 ? 0 : view->getHeadingOffset_deg());
434 }
435
436 void
437 FGViewMgr::setViewHeadingOffset_deg (double offset)
438 {
439   FGViewer * view = get_current_view();
440   if (view != 0) {
441     view->setGoalHeadingOffset_deg(offset);
442     view->setHeadingOffset_deg(offset);
443   }
444 }
445
446 double
447 FGViewMgr::getViewGoalHeadingOffset_deg () const
448 {
449   const FGViewer * view = get_current_view();
450   return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
451 }
452
453 void
454 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
455 {
456   FGViewer * view = get_current_view();
457   if (view != 0)
458     view->setGoalHeadingOffset_deg(offset);
459 }
460
461 double
462 FGViewMgr::getViewPitchOffset_deg () const
463 {
464   const FGViewer * view = get_current_view();
465   return (view == 0 ? 0 : view->getPitchOffset_deg());
466 }
467
468 void
469 FGViewMgr::setViewPitchOffset_deg (double tilt)
470 {
471   FGViewer * view = get_current_view();
472   if (view != 0) {
473     view->setGoalPitchOffset_deg(tilt);
474     view->setPitchOffset_deg(tilt);
475   }
476 }
477
478 double
479 FGViewMgr::getGoalViewPitchOffset_deg () const
480 {
481   const FGViewer * view = get_current_view();
482   return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
483 }
484
485 void
486 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
487 {
488   FGViewer * view = get_current_view();
489   if (view != 0)
490     view->setGoalPitchOffset_deg(tilt);
491 }
492
493 double
494 FGViewMgr::getViewRollOffset_deg () const
495 {
496   const FGViewer * view = get_current_view();
497   return (view == 0 ? 0 : view->getRollOffset_deg());
498 }
499
500 void
501 FGViewMgr::setViewRollOffset_deg (double tilt)
502 {
503   FGViewer * view = get_current_view();
504   if (view != 0) {
505     view->setGoalRollOffset_deg(tilt);
506     view->setRollOffset_deg(tilt);
507   }
508 }
509
510 double
511 FGViewMgr::getGoalViewRollOffset_deg () const
512 {
513   const FGViewer * view = get_current_view();
514   return (view == 0 ? 0 : view->getGoalRollOffset_deg());
515 }
516
517 void
518 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
519 {
520   FGViewer * view = get_current_view();
521   if (view != 0)
522     view->setGoalRollOffset_deg(tilt);
523 }
524
525 double
526 FGViewMgr::getViewXOffset_m () const
527 {
528   const FGViewer * view = get_current_view();
529   if (view != 0) {
530     return ((FGViewer *)view)->getXOffset_m();
531   } else {
532     return 0;
533   }
534 }
535
536 void
537 FGViewMgr::setViewXOffset_m (double x)
538 {
539   FGViewer * view = get_current_view();
540   if (view != 0) {
541     view->setXOffset_m(x);
542   }
543 }
544
545 double
546 FGViewMgr::getViewYOffset_m () const
547 {
548   const FGViewer * view = get_current_view();
549   if (view != 0) {
550     return ((FGViewer *)view)->getYOffset_m();
551   } else {
552     return 0;
553   }
554 }
555
556 void
557 FGViewMgr::setViewYOffset_m (double y)
558 {
559   FGViewer * view = get_current_view();
560   if (view != 0) {
561     view->setYOffset_m(y);
562   }
563 }
564
565 double
566 FGViewMgr::getViewZOffset_m () const
567 {
568   const FGViewer * view = get_current_view();
569   if (view != 0) {
570     return ((FGViewer *)view)->getZOffset_m();
571   } else {
572     return 0;
573   }
574 }
575
576 void
577 FGViewMgr::setViewZOffset_m (double z)
578 {
579   FGViewer * view = get_current_view();
580   if (view != 0) {
581     view->setZOffset_m(z);
582   }
583 }
584
585 bool
586 FGViewMgr::stationary () const
587 {
588   const FGViewer * view = get_current_view();
589   if (view != 0) {
590     if (((FGViewer *)view)->getXOffset_m() == 0.0 &&
591         ((FGViewer *)view)->getYOffset_m() == 0.0 &&
592         ((FGViewer *)view)->getZOffset_m() == 0.0)
593       return true;
594   }
595
596   return false;
597 }
598
599 double
600 FGViewMgr::getViewTargetXOffset_m () const
601 {
602   const FGViewer * view = get_current_view();
603   if (view != 0) {
604     return ((FGViewer *)view)->getTargetXOffset_m();
605   } else {
606     return 0;
607   }
608 }
609
610 void
611 FGViewMgr::setViewTargetXOffset_m (double x)
612 {
613   FGViewer * view = get_current_view();
614   if (view != 0) {
615     view->setTargetXOffset_m(x);
616   }
617 }
618
619 double
620 FGViewMgr::getViewTargetYOffset_m () const
621 {
622   const FGViewer * view = get_current_view();
623   if (view != 0) {
624     return ((FGViewer *)view)->getTargetYOffset_m();
625   } else {
626     return 0;
627   }
628 }
629
630 void
631 FGViewMgr::setViewTargetYOffset_m (double y)
632 {
633   FGViewer * view = get_current_view();
634   if (view != 0) {
635     view->setTargetYOffset_m(y);
636   }
637 }
638
639 double
640 FGViewMgr::getViewTargetZOffset_m () const
641 {
642   const FGViewer * view = get_current_view();
643   if (view != 0) {
644     return ((FGViewer *)view)->getTargetZOffset_m();
645   } else {
646     return 0;
647   }
648 }
649
650 void
651 FGViewMgr::setViewTargetZOffset_m (double z)
652 {
653   FGViewer * view = get_current_view();
654   if (view != 0) {
655     view->setTargetZOffset_m(z);
656   }
657 }
658
659 int
660 FGViewMgr::getView () const
661 {
662   return ( current );
663 }
664
665 void
666 FGViewMgr::setView (int newview)
667 {
668   // negative numbers -> set view with node index -newview
669   if (newview < 0) {
670     for (int i = 0; i < (int)config_list.size(); i++) {
671       int index = -config_list[i]->getIndex();
672       if (index == newview)
673         newview = i;
674     }
675     if (newview < 0)
676       return;
677   }
678
679   // if newview number too low wrap to last view...
680   if (newview < 0)
681     newview = (int)views.size() - 1;
682
683   // if newview number to high wrap to zero...
684   if (newview >= (int)views.size())
685     newview = 0;
686
687   // set new view
688   set_view(newview);
689   // copy in view data
690   copyToCurrent();
691
692   // Copy the fdm's position into the SGLocation which is shared with
693   // some views ...
694   globals->get_aircraft_model()->update(0);
695   // Do the update ...
696   update(0);
697 }
698
699
700 double
701 FGViewMgr::getFOV_deg () const
702 {
703   const FGViewer * view = get_current_view();
704   return (view == 0 ? 0 : view->get_fov());
705 }
706
707 void
708 FGViewMgr::setFOV_deg (double fov)
709 {
710   FGViewer * view = get_current_view();
711   if (view != 0)
712     view->set_fov(fov);
713 }
714
715 double
716 FGViewMgr::getARM_deg () const
717 {
718   const FGViewer * view = get_current_view();
719   return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
720 }
721
722 void
723 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
724 {
725   FGViewer * view = get_current_view();
726   if (view != 0)
727     view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
728 }
729
730 double
731 FGViewMgr::getNear_m () const
732 {
733   const FGViewer * view = get_current_view();
734   return (view == 0 ? 0.5f : view->getNear_m());
735 }
736
737 void
738 FGViewMgr::setNear_m (double near_m)
739 {
740   FGViewer * view = get_current_view();
741   if (view != 0)
742     view->setNear_m(near_m);
743 }
744
745 void
746 FGViewMgr::setViewAxisLong (double axis)
747 {
748   axis_long = axis;
749 }
750
751 void
752 FGViewMgr::setViewAxisLat (double axis)
753 {
754   axis_lat = axis;
755 }
756
757 void
758 FGViewMgr::do_axes ()
759 {
760                                 // Take no action when hat is centered
761   if ( ( axis_long <  0.01 ) &&
762        ( axis_long > -0.01 ) &&
763        ( axis_lat  <  0.01 ) &&
764        ( axis_lat  > -0.01 )
765      )
766     return;
767
768   double viewDir = 999;
769
770   /* Do all the quick and easy cases */
771   if (axis_long < 0) {          // Longitudinal axis forward
772     if (axis_lat == axis_long)
773       viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
774     else if (axis_lat == - axis_long)
775       viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
776     else if (axis_lat == 0)
777       viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
778   } else if (axis_long > 0) {   // Longitudinal axis backward
779     if (axis_lat == - axis_long)
780       viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
781     else if (axis_lat == axis_long)
782       viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
783     else if (axis_lat == 0)
784       viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
785   } else if (axis_long == 0) {  // Longitudinal axis neutral
786     if (axis_lat < 0)
787       viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
788     else if (axis_lat > 0)
789       viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
790     else return; /* And assertion failure maybe? */
791   }
792
793                                 // Do all the difficult cases
794   if ( viewDir > 900 )
795     viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
796   if ( viewDir < -1 ) viewDir += 360;
797
798   get_current_view()->setGoalHeadingOffset_deg(viewDir);
799 }