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