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