]> git.mxchange.org Git - flightgear.git/blob - src/Main/viewmgr.cxx
6074dcf95119fac9f1005a602c9ac081f6913c6b
[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   smgr->set_position( abs_viewer_position );
302   smgr->set_orientation(loop_view->getViewOrientation());
303
304   // get the model velocity for the in-cockpit view
305   SGVec3d velocity = SGVec3d(0,0,0);
306   if ( !stationary() ) {
307     FGAircraftModel *aircraft = globals->get_aircraft_model();
308     velocity = aircraft->getVelocity();
309   }
310   smgr->set_velocity(velocity);
311 }
312
313 void
314 FGViewMgr::copyToCurrent()
315 {
316     SGPropertyNode *n = config_list[current];
317     fgSetString("/sim/current-view/name", n->getStringValue("name"));
318     fgSetString("/sim/current-view/type", n->getStringValue("type"));
319
320     // copy certain view config data for default values
321     fgSetDouble("/sim/current-view/config/heading-offset-deg",
322                 n->getDoubleValue("config/default-heading-offset-deg"));
323     fgSetDouble("/sim/current-view/config/pitch-offset-deg",
324                 n->getDoubleValue("config/pitch-offset-deg"));
325     fgSetDouble("/sim/current-view/config/roll-offset-deg",
326                 n->getDoubleValue("config/roll-offset-deg"));
327     fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
328                 n->getDoubleValue("config/default-field-of-view-deg"));
329     fgSetBool("/sim/current-view/config/from-model",
330                 n->getBoolValue("config/from-model"));
331
332     // copy view data
333     fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
334     fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
335     fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
336
337     fgSetDouble("/sim/current-view/goal-heading-offset-deg",
338                 get_current_view()->getGoalHeadingOffset_deg());
339     fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
340                 get_current_view()->getGoalPitchOffset_deg());
341     fgSetDouble("/sim/current-view/goal-roll-offset-deg",
342                 get_current_view()->getRollOffset_deg());
343     fgSetDouble("/sim/current-view/heading-offset-deg",
344                 get_current_view()->getHeadingOffset_deg());
345     fgSetDouble("/sim/current-view/pitch-offset-deg",
346                 get_current_view()->getPitchOffset_deg());
347     fgSetDouble("/sim/current-view/roll-offset-deg",
348                 get_current_view()->getRollOffset_deg());
349     fgSetDouble("/sim/current-view/target-x-offset-m",
350                 get_current_view()->getTargetXOffset_m());
351     fgSetDouble("/sim/current-view/target-y-offset-m",
352                 get_current_view()->getTargetYOffset_m());
353     fgSetDouble("/sim/current-view/target-z-offset-m",
354                 get_current_view()->getTargetZOffset_m());
355     fgSetBool("/sim/current-view/internal",
356                 get_current_view()->getInternal());
357 }
358
359 void FGViewMgr::clear()
360 {
361   views.clear();
362 }
363
364 FGViewer*
365 FGViewMgr::get_current_view()
366 {
367         if ( current < (int)views.size() ) {
368             return views[current];
369         } else {
370             return NULL;
371         }
372 }
373
374 const FGViewer*
375 FGViewMgr::get_current_view() const
376 {
377         if ( current < (int)views.size() ) {
378             return views[current];
379         } else {
380             return NULL;
381         }
382 }
383
384
385 FGViewer*
386 FGViewMgr::get_view( int i )
387 {
388         if ( i < 0 ) { i = 0; }
389         if ( i >= (int)views.size() ) { i = views.size() - 1; }
390         return views[i];
391 }
392
393 const FGViewer*
394 FGViewMgr::get_view( int i ) const
395 {
396         if ( i < 0 ) { i = 0; }
397         if ( i >= (int)views.size() ) { i = views.size() - 1; }
398         return views[i];
399 }
400
401 FGViewer*
402 FGViewMgr::next_view()
403 {
404         setView((current+1 < (int)views.size()) ? (current + 1) : 0);
405         view_number->fireValueChanged();
406         return views[current];
407 }
408
409 FGViewer*
410 FGViewMgr::prev_view()
411 {
412         setView((0 < current) ? (current - 1) : (views.size() - 1));
413         view_number->fireValueChanged();
414         return views[current];
415 }
416
417 void
418 FGViewMgr::add_view( FGViewer * v )
419 {
420   views.push_back(v);
421   v->init();
422 }
423     
424 double
425 FGViewMgr::getViewHeadingOffset_deg () const
426 {
427   const FGViewer * view = get_current_view();
428   return (view == 0 ? 0 : view->getHeadingOffset_deg());
429 }
430
431 void
432 FGViewMgr::setViewHeadingOffset_deg (double offset)
433 {
434   FGViewer * view = get_current_view();
435   if (view != 0) {
436     view->setGoalHeadingOffset_deg(offset);
437     view->setHeadingOffset_deg(offset);
438   }
439 }
440
441 double
442 FGViewMgr::getViewGoalHeadingOffset_deg () const
443 {
444   const FGViewer * view = get_current_view();
445   return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
446 }
447
448 void
449 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
450 {
451   FGViewer * view = get_current_view();
452   if (view != 0)
453     view->setGoalHeadingOffset_deg(offset);
454 }
455
456 double
457 FGViewMgr::getViewPitchOffset_deg () const
458 {
459   const FGViewer * view = get_current_view();
460   return (view == 0 ? 0 : view->getPitchOffset_deg());
461 }
462
463 void
464 FGViewMgr::setViewPitchOffset_deg (double tilt)
465 {
466   FGViewer * view = get_current_view();
467   if (view != 0) {
468     view->setGoalPitchOffset_deg(tilt);
469     view->setPitchOffset_deg(tilt);
470   }
471 }
472
473 double
474 FGViewMgr::getGoalViewPitchOffset_deg () const
475 {
476   const FGViewer * view = get_current_view();
477   return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
478 }
479
480 void
481 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
482 {
483   FGViewer * view = get_current_view();
484   if (view != 0)
485     view->setGoalPitchOffset_deg(tilt);
486 }
487
488 double
489 FGViewMgr::getViewRollOffset_deg () const
490 {
491   const FGViewer * view = get_current_view();
492   return (view == 0 ? 0 : view->getRollOffset_deg());
493 }
494
495 void
496 FGViewMgr::setViewRollOffset_deg (double tilt)
497 {
498   FGViewer * view = get_current_view();
499   if (view != 0) {
500     view->setGoalRollOffset_deg(tilt);
501     view->setRollOffset_deg(tilt);
502   }
503 }
504
505 double
506 FGViewMgr::getGoalViewRollOffset_deg () const
507 {
508   const FGViewer * view = get_current_view();
509   return (view == 0 ? 0 : view->getGoalRollOffset_deg());
510 }
511
512 void
513 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
514 {
515   FGViewer * view = get_current_view();
516   if (view != 0)
517     view->setGoalRollOffset_deg(tilt);
518 }
519
520 double
521 FGViewMgr::getViewXOffset_m () const
522 {
523   const FGViewer * view = get_current_view();
524   if (view != 0) {
525     return ((FGViewer *)view)->getXOffset_m();
526   } else {
527     return 0;
528   }
529 }
530
531 void
532 FGViewMgr::setViewXOffset_m (double x)
533 {
534   FGViewer * view = get_current_view();
535   if (view != 0) {
536     view->setXOffset_m(x);
537   }
538 }
539
540 double
541 FGViewMgr::getViewYOffset_m () const
542 {
543   const FGViewer * view = get_current_view();
544   if (view != 0) {
545     return ((FGViewer *)view)->getYOffset_m();
546   } else {
547     return 0;
548   }
549 }
550
551 void
552 FGViewMgr::setViewYOffset_m (double y)
553 {
554   FGViewer * view = get_current_view();
555   if (view != 0) {
556     view->setYOffset_m(y);
557   }
558 }
559
560 double
561 FGViewMgr::getViewZOffset_m () const
562 {
563   const FGViewer * view = get_current_view();
564   if (view != 0) {
565     return ((FGViewer *)view)->getZOffset_m();
566   } else {
567     return 0;
568   }
569 }
570
571 void
572 FGViewMgr::setViewZOffset_m (double z)
573 {
574   FGViewer * view = get_current_view();
575   if (view != 0) {
576     view->setZOffset_m(z);
577   }
578 }
579
580 bool
581 FGViewMgr::stationary () const
582 {
583   const FGViewer * view = get_current_view();
584   if (view != 0) {
585     if (((FGViewer *)view)->getXOffset_m() == 0.0 &&
586         ((FGViewer *)view)->getYOffset_m() == 0.0 &&
587         ((FGViewer *)view)->getZOffset_m() == 0.0)
588       return true;
589   }
590
591   return false;
592 }
593
594 double
595 FGViewMgr::getViewTargetXOffset_m () const
596 {
597   const FGViewer * view = get_current_view();
598   if (view != 0) {
599     return ((FGViewer *)view)->getTargetXOffset_m();
600   } else {
601     return 0;
602   }
603 }
604
605 void
606 FGViewMgr::setViewTargetXOffset_m (double x)
607 {
608   FGViewer * view = get_current_view();
609   if (view != 0) {
610     view->setTargetXOffset_m(x);
611   }
612 }
613
614 double
615 FGViewMgr::getViewTargetYOffset_m () const
616 {
617   const FGViewer * view = get_current_view();
618   if (view != 0) {
619     return ((FGViewer *)view)->getTargetYOffset_m();
620   } else {
621     return 0;
622   }
623 }
624
625 void
626 FGViewMgr::setViewTargetYOffset_m (double y)
627 {
628   FGViewer * view = get_current_view();
629   if (view != 0) {
630     view->setTargetYOffset_m(y);
631   }
632 }
633
634 double
635 FGViewMgr::getViewTargetZOffset_m () const
636 {
637   const FGViewer * view = get_current_view();
638   if (view != 0) {
639     return ((FGViewer *)view)->getTargetZOffset_m();
640   } else {
641     return 0;
642   }
643 }
644
645 void
646 FGViewMgr::setViewTargetZOffset_m (double z)
647 {
648   FGViewer * view = get_current_view();
649   if (view != 0) {
650     view->setTargetZOffset_m(z);
651   }
652 }
653
654 int
655 FGViewMgr::getView () const
656 {
657   return ( current );
658 }
659
660 void
661 FGViewMgr::setView (int newview)
662 {
663   // negative numbers -> set view with node index -newview
664   if (newview < 0) {
665     for (int i = 0; i < (int)config_list.size(); i++) {
666       int index = -config_list[i]->getIndex();
667       if (index == newview)
668         newview = i;
669     }
670     if (newview < 0)
671       return;
672   }
673
674   // if newview number too low wrap to last view...
675   if (newview < 0)
676     newview = (int)views.size() - 1;
677
678   // if newview number to high wrap to zero...
679   if (newview >= (int)views.size())
680     newview = 0;
681
682   // set new view
683   set_view(newview);
684   // copy in view data
685   copyToCurrent();
686
687   // Copy the fdm's position into the SGLocation which is shared with
688   // some views ...
689   globals->get_aircraft_model()->update(0);
690   // Do the update ...
691   update(0);
692 }
693
694
695 double
696 FGViewMgr::getFOV_deg () const
697 {
698   const FGViewer * view = get_current_view();
699   return (view == 0 ? 0 : view->get_fov());
700 }
701
702 void
703 FGViewMgr::setFOV_deg (double fov)
704 {
705   FGViewer * view = get_current_view();
706   if (view != 0)
707     view->set_fov(fov);
708 }
709
710 double
711 FGViewMgr::getARM_deg () const
712 {
713   const FGViewer * view = get_current_view();
714   return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
715 }
716
717 void
718 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
719 {
720   FGViewer * view = get_current_view();
721   if (view != 0)
722     view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
723 }
724
725 double
726 FGViewMgr::getNear_m () const
727 {
728   const FGViewer * view = get_current_view();
729   return (view == 0 ? 0.5f : view->getNear_m());
730 }
731
732 void
733 FGViewMgr::setNear_m (double near_m)
734 {
735   FGViewer * view = get_current_view();
736   if (view != 0)
737     view->setNear_m(near_m);
738 }
739
740 void
741 FGViewMgr::setViewAxisLong (double axis)
742 {
743   axis_long = axis;
744 }
745
746 void
747 FGViewMgr::setViewAxisLat (double axis)
748 {
749   axis_lat = axis;
750 }
751
752 void
753 FGViewMgr::do_axes ()
754 {
755                                 // Take no action when hat is centered
756   if ( ( axis_long <  0.01 ) &&
757        ( axis_long > -0.01 ) &&
758        ( axis_lat  <  0.01 ) &&
759        ( axis_lat  > -0.01 )
760      )
761     return;
762
763   double viewDir = 999;
764
765   /* Do all the quick and easy cases */
766   if (axis_long < 0) {          // Longitudinal axis forward
767     if (axis_lat == axis_long)
768       viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
769     else if (axis_lat == - axis_long)
770       viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
771     else if (axis_lat == 0)
772       viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
773   } else if (axis_long > 0) {   // Longitudinal axis backward
774     if (axis_lat == - axis_long)
775       viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
776     else if (axis_lat == axis_long)
777       viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
778     else if (axis_lat == 0)
779       viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
780   } else if (axis_long == 0) {  // Longitudinal axis neutral
781     if (axis_lat < 0)
782       viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
783     else if (axis_lat > 0)
784       viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
785     else return; /* And assertion failure maybe? */
786   }
787
788                                 // Do all the difficult cases
789   if ( viewDir > 900 )
790     viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
791   if ( viewDir < -1 ) viewDir += 360;
792
793   get_current_view()->setGoalHeadingOffset_deg(viewDir);
794 }