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