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