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