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