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