]> git.mxchange.org Git - flightgear.git/blob - src/Main/viewmgr.cxx
header cleanups
[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 <string.h>             // strcmp
29
30 #include <plib/sg.h>
31
32 #include <simgear/compiler.h>
33
34 #include <Model/acmodel.hxx>
35
36 #include "viewmgr.hxx"
37
38
39 // Constructor
40 FGViewMgr::FGViewMgr( void ) :
41   axis_long(0),
42   axis_lat(0),
43   view_number(fgGetNode("/sim/current-view/view-number", true)),
44   config_list(fgGetNode("/sim", true)->getChildren("view")),
45   current(0)
46 {
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-deg",
151         n->getDoubleValue("config/target-x-offset-m"));
152     fgSetDouble("/sim/current-view/target-y-offset-deg",
153         n->getDoubleValue("config/target-y-offset-m"));
154     fgSetDouble("/sim/current-view/target-z-offset-deg",
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 }
216
217 void
218 FGViewMgr::unbind ()
219 {
220   // FIXME:
221   // need to redo these bindings to the new locations (move to viewer?)
222   fgUntie("/sim/current-view/heading-offset-deg");
223   fgUntie("/sim/current-view/goal-heading-offset-deg");
224   fgUntie("/sim/current-view/pitch-offset-deg");
225   fgUntie("/sim/current-view/goal-pitch-offset-deg");
226   fgUntie("/sim/current-view/field-of-view");
227   fgUntie("/sim/current-view/aspect-ratio-multiplier");
228   fgUntie("/sim/current-view/view-number");
229   fgUntie("/sim/current-view/axes/long");
230   fgUntie("/sim/current-view/axes/lat");
231   fgUntie("/sim/current-view/ground-level-nearplane-m");
232 }
233
234 void
235 FGViewMgr::update (double dt)
236 {
237   FGViewer * view = get_current_view();
238   if (view == 0)
239     return;
240
241   FGViewer *loop_view = (FGViewer *)get_view(current);
242   SGPropertyNode *n = config_list[current];
243   double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
244
245   // Set up view location and orientation
246
247   if (!n->getBoolValue("config/from-model")) {
248     lon_deg = fgGetDouble(n->getStringValue("config/eye-lon-deg-path"));
249     lat_deg = fgGetDouble(n->getStringValue("config/eye-lat-deg-path"));
250     alt_ft = fgGetDouble(n->getStringValue("config/eye-alt-ft-path"));
251     roll_deg = fgGetDouble(n->getStringValue("config/eye-roll-deg-path"));
252     pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path"));
253     heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path"));
254
255     loop_view->setPosition(lon_deg, lat_deg, alt_ft);
256     loop_view->setOrientation(roll_deg, pitch_deg, heading_deg);
257   } else {
258     // force recalc in viewer
259     loop_view->set_dirty();
260   }
261
262   // if lookat (type 1) then get target data...
263   if (loop_view->getType() == FG_LOOKAT) {
264     if (!n->getBoolValue("config/from-model")) {
265       lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path"));
266       lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path"));
267       alt_ft = fgGetDouble(n->getStringValue("config/target-alt-ft-path"));
268       roll_deg = fgGetDouble(n->getStringValue("config/target-roll-deg-path"));
269       pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path"));
270       heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path"));
271
272       loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft);
273       loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
274     } else {
275       loop_view->set_dirty();
276     }
277   }
278
279   setViewXOffset_m(fgGetDouble("/sim/current-view/x-offset-m"));
280   setViewYOffset_m(fgGetDouble("/sim/current-view/y-offset-m"));
281   setViewZOffset_m(fgGetDouble("/sim/current-view/z-offset-m"));
282
283   setViewTargetXOffset_m(fgGetDouble("/sim/current-view/target-x-offset-m"));
284   setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m"));
285   setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m"));
286
287   // Update the current view
288   do_axes();
289   view->update(dt);
290 }
291
292 void
293 FGViewMgr::copyToCurrent()
294 {
295     SGPropertyNode *n = config_list[current];
296     fgSetString("/sim/current-view/name", n->getStringValue("name"));
297     fgSetString("/sim/current-view/type", n->getStringValue("type"));
298
299     // copy certain view config data for default values
300     fgSetDouble("/sim/current-view/config/heading-offset-deg",
301                 n->getDoubleValue("config/default-heading-offset-deg"));
302     fgSetDouble("/sim/current-view/config/pitch-offset-deg",
303                 n->getDoubleValue("config/pitch-offset-deg"));
304     fgSetDouble("/sim/current-view/config/roll-offset-deg",
305                 n->getDoubleValue("config/roll-offset-deg"));
306     fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
307                 n->getDoubleValue("config/default-field-of-view-deg"));
308     fgSetBool("/sim/current-view/config/from-model",
309                 n->getBoolValue("config/from-model"));
310
311     // copy view data
312     fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
313     fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
314     fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
315
316     fgSetDouble("/sim/current-view/goal-heading-offset-deg",
317                 get_current_view()->getGoalHeadingOffset_deg());
318     fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
319                 get_current_view()->getGoalPitchOffset_deg());
320     fgSetDouble("/sim/current-view/goal-roll-offset-deg",
321                 get_current_view()->getRollOffset_deg());
322     fgSetDouble("/sim/current-view/heading-offset-deg",
323                 get_current_view()->getHeadingOffset_deg());
324     fgSetDouble("/sim/current-view/pitch-offset-deg",
325                 get_current_view()->getPitchOffset_deg());
326     fgSetDouble("/sim/current-view/roll-offset-deg",
327                 get_current_view()->getRollOffset_deg());
328     fgSetDouble("/sim/current-view/target-x-offset-m",
329                 get_current_view()->getTargetXOffset_m());
330     fgSetDouble("/sim/current-view/target-y-offset-m",
331                 get_current_view()->getTargetYOffset_m());
332     fgSetDouble("/sim/current-view/target-z-offset-m",
333                 get_current_view()->getTargetZOffset_m());
334     fgSetBool("/sim/current-view/internal",
335                 get_current_view()->getInternal());
336 }
337
338
339 double
340 FGViewMgr::getViewHeadingOffset_deg () const
341 {
342   const FGViewer * view = get_current_view();
343   return (view == 0 ? 0 : view->getHeadingOffset_deg());
344 }
345
346 void
347 FGViewMgr::setViewHeadingOffset_deg (double offset)
348 {
349   FGViewer * view = get_current_view();
350   if (view != 0) {
351     view->setGoalHeadingOffset_deg(offset);
352     view->setHeadingOffset_deg(offset);
353   }
354 }
355
356 double
357 FGViewMgr::getViewGoalHeadingOffset_deg () const
358 {
359   const FGViewer * view = get_current_view();
360   return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
361 }
362
363 void
364 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
365 {
366   FGViewer * view = get_current_view();
367   if (view != 0)
368     view->setGoalHeadingOffset_deg(offset);
369 }
370
371 double
372 FGViewMgr::getViewPitchOffset_deg () const
373 {
374   const FGViewer * view = get_current_view();
375   return (view == 0 ? 0 : view->getPitchOffset_deg());
376 }
377
378 void
379 FGViewMgr::setViewPitchOffset_deg (double tilt)
380 {
381   FGViewer * view = get_current_view();
382   if (view != 0) {
383     view->setGoalPitchOffset_deg(tilt);
384     view->setPitchOffset_deg(tilt);
385   }
386 }
387
388 double
389 FGViewMgr::getGoalViewPitchOffset_deg () const
390 {
391   const FGViewer * view = get_current_view();
392   return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
393 }
394
395 void
396 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
397 {
398   FGViewer * view = get_current_view();
399   if (view != 0)
400     view->setGoalPitchOffset_deg(tilt);
401 }
402
403 double
404 FGViewMgr::getViewRollOffset_deg () const
405 {
406   const FGViewer * view = get_current_view();
407   return (view == 0 ? 0 : view->getRollOffset_deg());
408 }
409
410 void
411 FGViewMgr::setViewRollOffset_deg (double tilt)
412 {
413   FGViewer * view = get_current_view();
414   if (view != 0) {
415     view->setGoalRollOffset_deg(tilt);
416     view->setRollOffset_deg(tilt);
417   }
418 }
419
420 double
421 FGViewMgr::getGoalViewRollOffset_deg () const
422 {
423   const FGViewer * view = get_current_view();
424   return (view == 0 ? 0 : view->getGoalRollOffset_deg());
425 }
426
427 void
428 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
429 {
430   FGViewer * view = get_current_view();
431   if (view != 0)
432     view->setGoalRollOffset_deg(tilt);
433 }
434
435 double
436 FGViewMgr::getViewXOffset_m () const
437 {
438   const FGViewer * view = get_current_view();
439   if (view != 0) {
440     return ((FGViewer *)view)->getXOffset_m();
441   } else {
442     return 0;
443   }
444 }
445
446 void
447 FGViewMgr::setViewXOffset_m (double x)
448 {
449   FGViewer * view = get_current_view();
450   if (view != 0) {
451     view->setXOffset_m(x);
452   }
453 }
454
455 double
456 FGViewMgr::getViewYOffset_m () const
457 {
458   const FGViewer * view = get_current_view();
459   if (view != 0) {
460     return ((FGViewer *)view)->getYOffset_m();
461   } else {
462     return 0;
463   }
464 }
465
466 void
467 FGViewMgr::setViewYOffset_m (double y)
468 {
469   FGViewer * view = get_current_view();
470   if (view != 0) {
471     view->setYOffset_m(y);
472   }
473 }
474
475 double
476 FGViewMgr::getViewZOffset_m () const
477 {
478   const FGViewer * view = get_current_view();
479   if (view != 0) {
480     return ((FGViewer *)view)->getZOffset_m();
481   } else {
482     return 0;
483   }
484 }
485
486 void
487 FGViewMgr::setViewZOffset_m (double z)
488 {
489   FGViewer * view = get_current_view();
490   if (view != 0) {
491     view->setZOffset_m(z);
492   }
493 }
494
495 double
496 FGViewMgr::getViewTargetXOffset_m () const
497 {
498   const FGViewer * view = get_current_view();
499   if (view != 0) {
500     return ((FGViewer *)view)->getTargetXOffset_m();
501   } else {
502     return 0;
503   }
504 }
505
506 void
507 FGViewMgr::setViewTargetXOffset_m (double x)
508 {
509   FGViewer * view = get_current_view();
510   if (view != 0) {
511     view->setTargetXOffset_m(x);
512   }
513 }
514
515 double
516 FGViewMgr::getViewTargetYOffset_m () const
517 {
518   const FGViewer * view = get_current_view();
519   if (view != 0) {
520     return ((FGViewer *)view)->getTargetYOffset_m();
521   } else {
522     return 0;
523   }
524 }
525
526 void
527 FGViewMgr::setViewTargetYOffset_m (double y)
528 {
529   FGViewer * view = get_current_view();
530   if (view != 0) {
531     view->setTargetYOffset_m(y);
532   }
533 }
534
535 double
536 FGViewMgr::getViewTargetZOffset_m () const
537 {
538   const FGViewer * view = get_current_view();
539   if (view != 0) {
540     return ((FGViewer *)view)->getTargetZOffset_m();
541   } else {
542     return 0;
543   }
544 }
545
546 void
547 FGViewMgr::setViewTargetZOffset_m (double z)
548 {
549   FGViewer * view = get_current_view();
550   if (view != 0) {
551     view->setTargetZOffset_m(z);
552   }
553 }
554
555 int
556 FGViewMgr::getView () const
557 {
558   return ( current );
559 }
560
561 void
562 FGViewMgr::setView (int newview)
563 {
564   // negative numbers -> set view with node index -newview
565   if (newview < 0) {
566     for (int i = 0; i < (int)config_list.size(); i++) {
567       int index = -config_list[i]->getIndex();
568       if (index == newview)
569         newview = i;
570     }
571     if (newview < 0)
572       return;
573   }
574
575   // if newview number too low wrap to last view...
576   if (newview < 0)
577     newview = (int)views.size() - 1;
578
579   // if newview number to high wrap to zero...
580   if (newview >= (int)views.size())
581     newview = 0;
582
583   // set new view
584   set_view(newview);
585   // copy in view data
586   copyToCurrent();
587
588   // Copy the fdm's position into the SGLocation which is shared with
589   // some views ...
590   globals->get_aircraft_model()->update(0);
591   // Do the update ...
592   update(0);
593 }
594
595
596 double
597 FGViewMgr::getFOV_deg () const
598 {
599   const FGViewer * view = get_current_view();
600   return (view == 0 ? 0 : view->get_fov());
601 }
602
603 void
604 FGViewMgr::setFOV_deg (double fov)
605 {
606   FGViewer * view = get_current_view();
607   if (view != 0)
608     view->set_fov(fov);
609 }
610
611 double
612 FGViewMgr::getARM_deg () const
613 {
614   const FGViewer * view = get_current_view();
615   return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
616 }
617
618 void
619 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
620 {
621   FGViewer * view = get_current_view();
622   if (view != 0)
623     view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
624 }
625
626 double
627 FGViewMgr::getNear_m () const
628 {
629   const FGViewer * view = get_current_view();
630   return (view == 0 ? 0.5f : view->getNear_m());
631 }
632
633 void
634 FGViewMgr::setNear_m (double near_m)
635 {
636   FGViewer * view = get_current_view();
637   if (view != 0)
638     view->setNear_m(near_m);
639 }
640
641 void
642 FGViewMgr::setViewAxisLong (double axis)
643 {
644   axis_long = axis;
645 }
646
647 void
648 FGViewMgr::setViewAxisLat (double axis)
649 {
650   axis_lat = axis;
651 }
652
653 void
654 FGViewMgr::do_axes ()
655 {
656                                 // Take no action when hat is centered
657   if ( ( axis_long <  0.01 ) &&
658        ( axis_long > -0.01 ) &&
659        ( axis_lat  <  0.01 ) &&
660        ( axis_lat  > -0.01 )
661      )
662     return;
663
664   double viewDir = 999;
665
666   /* Do all the quick and easy cases */
667   if (axis_long < 0) {          // Longitudinal axis forward
668     if (axis_lat == axis_long)
669       viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
670     else if (axis_lat == - axis_long)
671       viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
672     else if (axis_lat == 0)
673       viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
674   } else if (axis_long > 0) {   // Longitudinal axis backward
675     if (axis_lat == - axis_long)
676       viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
677     else if (axis_lat == axis_long)
678       viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
679     else if (axis_lat == 0)
680       viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
681   } else if (axis_long == 0) {  // Longitudinal axis neutral
682     if (axis_lat < 0)
683       viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
684     else if (axis_lat > 0)
685       viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
686     else return; /* And assertion failure maybe? */
687   }
688
689                                 // Do all the difficult cases
690   if ( viewDir > 900 )
691     viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
692   if ( viewDir < -1 ) viewDir += 360;
693
694   get_current_view()->setGoalHeadingOffset_deg(viewDir);
695 }