1 // viewmgr.cxx -- class for managing all the views in the flightgear world.
3 // Written by Curtis Olson, started October 2000.
4 // partially rewritten by Jim Wilson March 2002
6 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
28 #include "viewmgr.hxx"
30 #include <string.h> // strcmp
32 #include <simgear/compiler.h>
33 #include <Main/fg_props.hxx>
37 FGViewMgr::FGViewMgr( void ) :
41 view_number(fgGetNode("/sim/current-view/view-number", true)),
42 config_list(fgGetNode("/sim", true)->getChildren("view")),
43 abs_viewer_position(SGVec3d::zeros()),
45 current_view_orientation(SGQuatd::zeros()),
46 current_view_or_offset(SGQuatd::zeros())
48 globals->set_viewmgr(this);
52 FGViewMgr::~FGViewMgr( void )
54 globals->set_viewmgr(NULL);
61 SG_LOG(SG_VIEW, SG_WARN, "duplicate init of view manager");
68 current_x_offs = fgGetNode("/sim/current-view/x-offset-m", true);
69 current_y_offs = fgGetNode("/sim/current-view/y-offset-m", true);
70 current_z_offs = fgGetNode("/sim/current-view/z-offset-m", true);
71 target_x_offs = fgGetNode("/sim/current-view/target-x-offset-m", true);
72 target_y_offs = fgGetNode("/sim/current-view/target-y-offset-m", true);
73 target_z_offs = fgGetNode("/sim/current-view/target-z-offset-m", true);
75 double aspect_ratio_multiplier
76 = fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
78 for (unsigned int i = 0; i < config_list.size(); i++) {
79 SGPropertyNode *n = config_list[i];
80 SGPropertyNode *config = n->getChild("config", 0, true);
82 // find out if this is an internal view (e.g. in cockpit, low near plane)
83 bool internal = n->getBoolValue("internal", false);
86 // this is assumed to be an aircraft model...we will need to read
87 // model-from-type as well.
89 // find out if this is a model we are looking from...
90 bool from_model = config->getBoolValue("from-model");
91 int from_model_index = config->getIntValue("from-model-idx");
93 double x_offset_m = config->getDoubleValue("x-offset-m");
94 double y_offset_m = config->getDoubleValue("y-offset-m");
95 double z_offset_m = config->getDoubleValue("z-offset-m");
97 double heading_offset_deg = config->getDoubleValue("heading-offset-deg");
98 config->setDoubleValue("heading-offset-deg", heading_offset_deg);
99 double pitch_offset_deg = config->getDoubleValue("pitch-offset-deg");
100 config->setDoubleValue("pitch-offset-deg", pitch_offset_deg);
101 double roll_offset_deg = config->getDoubleValue("roll-offset-deg");
102 config->setDoubleValue("roll-offset-deg", roll_offset_deg);
104 double fov_deg = config->getDoubleValue("default-field-of-view-deg");
105 double near_m = config->getDoubleValue("ground-level-nearplane-m");
107 // supporting two types "lookat" = 1 and "lookfrom" = 0
108 const char *type = n->getStringValue("type");
109 if (!strcmp(type, "lookat")) {
111 bool at_model = config->getBoolValue("at-model");
112 int at_model_index = config->getIntValue("at-model-idx");
114 double damp_roll = config->getDoubleValue("at-model-roll-damping");
115 double damp_pitch = config->getDoubleValue("at-model-pitch-damping");
116 double damp_heading = config->getDoubleValue("at-model-heading-damping");
118 double target_x_offset_m = config->getDoubleValue("target-x-offset-m");
119 double target_y_offset_m = config->getDoubleValue("target-y-offset-m");
120 double target_z_offset_m = config->getDoubleValue("target-z-offset-m");
122 add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
123 at_model, at_model_index,
124 damp_roll, damp_pitch, damp_heading,
125 x_offset_m, y_offset_m,z_offset_m,
126 heading_offset_deg, pitch_offset_deg,
127 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
128 target_x_offset_m, target_y_offset_m,
129 target_z_offset_m, near_m, internal ));
131 add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index,
132 false, 0, 0.0, 0.0, 0.0,
133 x_offset_m, y_offset_m, z_offset_m,
134 heading_offset_deg, pitch_offset_deg,
135 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
136 0, 0, 0, near_m, internal ));
147 int current_view_index = current;
149 // reset offsets and fov to configuration defaults
150 for (unsigned int i = 0; i < config_list.size(); i++) {
151 SGPropertyNode *n = config_list[i];
154 fgSetDouble("/sim/current-view/x-offset-m",
155 n->getDoubleValue("config/x-offset-m"));
156 fgSetDouble("/sim/current-view/y-offset-m",
157 n->getDoubleValue("config/y-offset-m"));
158 fgSetDouble("/sim/current-view/z-offset-m",
159 n->getDoubleValue("config/z-offset-m"));
160 fgSetDouble("/sim/current-view/pitch-offset-deg",
161 n->getDoubleValue("config/pitch-offset-deg"));
162 fgSetDouble("/sim/current-view/heading-offset-deg",
163 n->getDoubleValue("config/heading-offset-deg"));
164 fgSetDouble("/sim/current-view/roll-offset-deg",
165 n->getDoubleValue("config/roll-offset-deg"));
167 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
170 fgSetDouble("/sim/current-view/field-of-view", fov_deg);
172 // target offsets for lookat mode only...
173 fgSetDouble("/sim/current-view/target-x-offset-m",
174 n->getDoubleValue("config/target-x-offset-m"));
175 fgSetDouble("/sim/current-view/target-y-offset-m",
176 n->getDoubleValue("config/target-y-offset-m"));
177 fgSetDouble("/sim/current-view/target-z-offset-m",
178 n->getDoubleValue("config/target-z-offset-m"));
180 setView(current_view_index);
183 typedef double (FGViewMgr::*double_getter)() const;
188 // view-manager code was designed to init before bind, so
189 // this is a no-op; init() calls the real bind() impl below
195 // these are bound to the current view properties
196 _tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
197 _tiedProperties.Tie("heading-offset-deg", this,
198 &FGViewMgr::getViewHeadingOffset_deg,
199 &FGViewMgr::setViewHeadingOffset_deg);
200 fgSetArchivable("/sim/current-view/heading-offset-deg");
201 _tiedProperties.Tie("goal-heading-offset-deg", this,
202 &FGViewMgr::getViewGoalHeadingOffset_deg,
203 &FGViewMgr::setViewGoalHeadingOffset_deg);
204 fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
205 _tiedProperties.Tie("pitch-offset-deg", this,
206 &FGViewMgr::getViewPitchOffset_deg,
207 &FGViewMgr::setViewPitchOffset_deg);
208 fgSetArchivable("/sim/current-view/pitch-offset-deg");
209 _tiedProperties.Tie("goal-pitch-offset-deg", this,
210 &FGViewMgr::getGoalViewPitchOffset_deg,
211 &FGViewMgr::setGoalViewPitchOffset_deg);
212 fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
213 _tiedProperties.Tie("roll-offset-deg", this,
214 &FGViewMgr::getViewRollOffset_deg,
215 &FGViewMgr::setViewRollOffset_deg);
216 fgSetArchivable("/sim/current-view/roll-offset-deg");
217 _tiedProperties.Tie("goal-roll-offset-deg", this,
218 &FGViewMgr::getGoalViewRollOffset_deg,
219 &FGViewMgr::setGoalViewRollOffset_deg);
220 fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
222 _tiedProperties.Tie("view-number", this,
223 &FGViewMgr::getView, &FGViewMgr::setView);
224 SGPropertyNode* view_number =
225 _tiedProperties.getRoot()->getNode("view-number");
226 view_number->setAttribute(SGPropertyNode::ARCHIVE, false);
228 // Keep view on reset/reinit
229 view_number->setAttribute(SGPropertyNode::PRESERVE, true);
231 _tiedProperties.Tie("axes/long", this,
232 (double_getter)0, &FGViewMgr::setViewAxisLong);
233 fgSetArchivable("/sim/current-view/axes/long");
235 _tiedProperties.Tie("axes/lat", this,
236 (double_getter)0, &FGViewMgr::setViewAxisLat);
237 fgSetArchivable("/sim/current-view/axes/lat");
239 _tiedProperties.Tie("field-of-view", this,
240 &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
241 fgSetArchivable("/sim/current-view/field-of-view");
243 _tiedProperties.Tie("aspect-ratio-multiplier", this,
244 &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
245 fgSetArchivable("/sim/current-view/field-of-view");
247 _tiedProperties.Tie("ground-level-nearplane-m", this,
248 &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
249 fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
251 SGPropertyNode *n = fgGetNode("/sim/current-view", true);
252 _tiedProperties.Tie(n->getNode("viewer-x-m", true),SGRawValuePointer<double>(&abs_viewer_position[0]));
253 _tiedProperties.Tie(n->getNode("viewer-y-m", true),SGRawValuePointer<double>(&abs_viewer_position[1]));
254 _tiedProperties.Tie(n->getNode("viewer-z-m", true),SGRawValuePointer<double>(&abs_viewer_position[2]));
256 _tiedProperties.Tie("viewer-lon-deg", this, &FGViewMgr::getViewLon_deg);
257 _tiedProperties.Tie("viewer-lat-deg", this, &FGViewMgr::getViewLat_deg);
258 _tiedProperties.Tie("viewer-elev-ft", this, &FGViewMgr::getViewElev_ft);
261 _tiedProperties.Tie("debug/orientation-w", this,
262 &FGViewMgr::getCurrentViewOrientation_w);
263 _tiedProperties.Tie("debug/orientation-x", this,
264 &FGViewMgr::getCurrentViewOrientation_x);
265 _tiedProperties.Tie("debug/orientation-y", this,
266 &FGViewMgr::getCurrentViewOrientation_y);
267 _tiedProperties.Tie("debug/orientation-z", this,
268 &FGViewMgr::getCurrentViewOrientation_z);
270 _tiedProperties.Tie("debug/orientation_offset-w", this,
271 &FGViewMgr::getCurrentViewOrOffset_w);
272 _tiedProperties.Tie("debug/orientation_offset-x", this,
273 &FGViewMgr::getCurrentViewOrOffset_x);
274 _tiedProperties.Tie("debug/orientation_offset-y", this,
275 &FGViewMgr::getCurrentViewOrOffset_y);
276 _tiedProperties.Tie("debug/orientation_offset-z", this,
277 &FGViewMgr::getCurrentViewOrOffset_z);
279 _tiedProperties.Tie("debug/frame-w", this,
280 &FGViewMgr::getCurrentViewFrame_w);
281 _tiedProperties.Tie("debug/frame-x", this,
282 &FGViewMgr::getCurrentViewFrame_x);
283 _tiedProperties.Tie("debug/frame-y", this,
284 &FGViewMgr::getCurrentViewFrame_y);
285 _tiedProperties.Tie("debug/frame-z", this,
286 &FGViewMgr::getCurrentViewFrame_z);
292 _tiedProperties.Untie();
296 FGViewMgr::update (double dt)
298 FGViewer* currentView = (FGViewer *)get_current_view();
299 if (!currentView) return;
301 SGPropertyNode *n = config_list[current];
302 SGPropertyNode *config = n->getChild("config", 0, true);
303 double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
305 // Set up view location and orientation
307 if (!config->getBoolValue("from-model")) {
308 lon_deg = fgGetDouble(config->getStringValue("eye-lon-deg-path"));
309 lat_deg = fgGetDouble(config->getStringValue("eye-lat-deg-path"));
310 alt_ft = fgGetDouble(config->getStringValue("eye-alt-ft-path"));
311 roll_deg = fgGetDouble(config->getStringValue("eye-roll-deg-path"));
312 pitch_deg = fgGetDouble(config->getStringValue("eye-pitch-deg-path"));
313 heading_deg = fgGetDouble(config->getStringValue("eye-heading-deg-path"));
315 currentView->setPosition(lon_deg, lat_deg, alt_ft);
316 currentView->setOrientation(roll_deg, pitch_deg, heading_deg);
318 // force recalc in viewer
319 currentView->set_dirty();
322 // if lookat (type 1) then get target data...
323 if (currentView->getType() == FG_LOOKAT) {
324 if (!config->getBoolValue("from-model")) {
325 lon_deg = fgGetDouble(config->getStringValue("target-lon-deg-path"));
326 lat_deg = fgGetDouble(config->getStringValue("target-lat-deg-path"));
327 alt_ft = fgGetDouble(config->getStringValue("target-alt-ft-path"));
328 roll_deg = fgGetDouble(config->getStringValue("target-roll-deg-path"));
329 pitch_deg = fgGetDouble(config->getStringValue("target-pitch-deg-path"));
330 heading_deg = fgGetDouble(config->getStringValue("target-heading-deg-path"));
332 currentView->setTargetPosition(lon_deg, lat_deg, alt_ft);
333 currentView->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
335 currentView->set_dirty();
339 setViewXOffset_m(current_x_offs->getDoubleValue());
340 setViewYOffset_m(current_y_offs->getDoubleValue());
341 setViewZOffset_m(current_z_offs->getDoubleValue());
343 setViewTargetXOffset_m(target_x_offs->getDoubleValue());
344 setViewTargetYOffset_m(target_y_offs->getDoubleValue());
345 setViewTargetZOffset_m(target_z_offs->getDoubleValue());
347 current_view_orientation = currentView->getViewOrientation();
348 current_view_or_offset = currentView->getViewOrientationOffset();
350 // Update the current view
352 currentView->update(dt);
353 abs_viewer_position = currentView->getViewPosition();
355 // expose the raw (OpenGL) orientation to the property tree,
356 // for the sound-manager
357 for (int i=0; i<4; ++i) {
358 _tiedProperties.getRoot()->getChild("raw-orientation", i, true)->setDoubleValue(current_view_orientation[i]);
363 FGViewMgr::copyToCurrent()
369 SGPropertyNode *n = config_list[current];
370 fgSetString("/sim/current-view/name", n->getStringValue("name"));
371 fgSetString("/sim/current-view/type", n->getStringValue("type"));
373 // copy certain view config data for default values
374 fgSetDouble("/sim/current-view/config/heading-offset-deg",
375 n->getDoubleValue("config/default-heading-offset-deg"));
376 fgSetDouble("/sim/current-view/config/pitch-offset-deg",
377 n->getDoubleValue("config/pitch-offset-deg"));
378 fgSetDouble("/sim/current-view/config/roll-offset-deg",
379 n->getDoubleValue("config/roll-offset-deg"));
380 fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
381 n->getDoubleValue("config/default-field-of-view-deg"));
382 fgSetBool("/sim/current-view/config/from-model",
383 n->getBoolValue("config/from-model"));
386 fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
387 fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
388 fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
390 fgSetDouble("/sim/current-view/goal-heading-offset-deg",
391 get_current_view()->getGoalHeadingOffset_deg());
392 fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
393 get_current_view()->getGoalPitchOffset_deg());
394 fgSetDouble("/sim/current-view/goal-roll-offset-deg",
395 get_current_view()->getRollOffset_deg());
396 fgSetDouble("/sim/current-view/heading-offset-deg",
397 get_current_view()->getHeadingOffset_deg());
398 fgSetDouble("/sim/current-view/pitch-offset-deg",
399 get_current_view()->getPitchOffset_deg());
400 fgSetDouble("/sim/current-view/roll-offset-deg",
401 get_current_view()->getRollOffset_deg());
402 fgSetDouble("/sim/current-view/target-x-offset-m",
403 get_current_view()->getTargetXOffset_m());
404 fgSetDouble("/sim/current-view/target-y-offset-m",
405 get_current_view()->getTargetYOffset_m());
406 fgSetDouble("/sim/current-view/target-z-offset-m",
407 get_current_view()->getTargetZOffset_m());
408 fgSetBool("/sim/current-view/internal",
409 get_current_view()->getInternal());
412 void FGViewMgr::clear()
418 FGViewMgr::get_current_view()
420 if ( current < (int)views.size() ) {
421 return views[current];
428 FGViewMgr::get_current_view() const
430 if ( current < (int)views.size() ) {
431 return views[current];
439 FGViewMgr::get_view( int i )
441 if ( i < 0 ) { i = 0; }
442 if ( i >= (int)views.size() ) { i = views.size() - 1; }
447 FGViewMgr::get_view( int i ) const
449 if ( i < 0 ) { i = 0; }
450 if ( i >= (int)views.size() ) { i = views.size() - 1; }
455 FGViewMgr::next_view()
457 setView((current+1 < (int)views.size()) ? (current + 1) : 0);
458 view_number->fireValueChanged();
459 return views[current];
463 FGViewMgr::prev_view()
465 setView((0 < current) ? (current - 1) : (views.size() - 1));
466 view_number->fireValueChanged();
467 return views[current];
471 FGViewMgr::add_view( FGViewer * v )
478 FGViewMgr::getViewHeadingOffset_deg () const
480 const FGViewer * view = get_current_view();
481 return (view == 0 ? 0 : view->getHeadingOffset_deg());
485 FGViewMgr::setViewHeadingOffset_deg (double offset)
487 FGViewer * view = get_current_view();
489 view->setGoalHeadingOffset_deg(offset);
490 view->setHeadingOffset_deg(offset);
495 FGViewMgr::getViewGoalHeadingOffset_deg () const
497 const FGViewer * view = get_current_view();
498 return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
502 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
504 FGViewer * view = get_current_view();
506 view->setGoalHeadingOffset_deg(offset);
510 FGViewMgr::getViewPitchOffset_deg () const
512 const FGViewer * view = get_current_view();
513 return (view == 0 ? 0 : view->getPitchOffset_deg());
517 FGViewMgr::setViewPitchOffset_deg (double tilt)
519 FGViewer * view = get_current_view();
521 view->setGoalPitchOffset_deg(tilt);
522 view->setPitchOffset_deg(tilt);
527 FGViewMgr::getGoalViewPitchOffset_deg () const
529 const FGViewer * view = get_current_view();
530 return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
534 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
536 FGViewer * view = get_current_view();
538 view->setGoalPitchOffset_deg(tilt);
542 FGViewMgr::getViewRollOffset_deg () const
544 const FGViewer * view = get_current_view();
545 return (view == 0 ? 0 : view->getRollOffset_deg());
549 FGViewMgr::setViewRollOffset_deg (double tilt)
551 FGViewer * view = get_current_view();
553 view->setGoalRollOffset_deg(tilt);
554 view->setRollOffset_deg(tilt);
559 FGViewMgr::getGoalViewRollOffset_deg () const
561 const FGViewer * view = get_current_view();
562 return (view == 0 ? 0 : view->getGoalRollOffset_deg());
566 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
568 FGViewer * view = get_current_view();
570 view->setGoalRollOffset_deg(tilt);
574 FGViewMgr::getViewXOffset_m () const
576 const FGViewer * view = get_current_view();
578 return ((FGViewer *)view)->getXOffset_m();
585 FGViewMgr::setViewXOffset_m (double x)
587 FGViewer * view = get_current_view();
589 view->setXOffset_m(x);
594 FGViewMgr::getViewYOffset_m () const
596 const FGViewer * view = get_current_view();
598 return ((FGViewer *)view)->getYOffset_m();
605 FGViewMgr::setViewYOffset_m (double y)
607 FGViewer * view = get_current_view();
609 view->setYOffset_m(y);
614 FGViewMgr::getViewZOffset_m () const
616 const FGViewer * view = get_current_view();
618 return ((FGViewer *)view)->getZOffset_m();
625 FGViewMgr::setViewZOffset_m (double z)
627 FGViewer * view = get_current_view();
629 view->setZOffset_m(z);
634 FGViewMgr::getViewTargetXOffset_m () const
636 const FGViewer * view = get_current_view();
638 return ((FGViewer *)view)->getTargetXOffset_m();
645 FGViewMgr::setViewTargetXOffset_m (double x)
647 FGViewer * view = get_current_view();
649 view->setTargetXOffset_m(x);
654 FGViewMgr::getViewTargetYOffset_m () const
656 const FGViewer * view = get_current_view();
658 return ((FGViewer *)view)->getTargetYOffset_m();
665 FGViewMgr::setViewTargetYOffset_m (double y)
667 FGViewer * view = get_current_view();
669 view->setTargetYOffset_m(y);
674 FGViewMgr::getViewTargetZOffset_m () const
676 const FGViewer * view = get_current_view();
678 return ((FGViewer *)view)->getTargetZOffset_m();
685 FGViewMgr::setViewTargetZOffset_m (double z)
687 FGViewer * view = get_current_view();
689 view->setTargetZOffset_m(z);
694 FGViewMgr::getView () const
700 FGViewMgr::setView (int newview)
702 // negative numbers -> set view with node index -newview
704 for (int i = 0; i < (int)config_list.size(); i++) {
705 int index = -config_list[i]->getIndex();
706 if (index == newview)
713 // if newview number too low wrap to last view...
715 newview = (int)views.size() - 1;
717 // if newview number to high wrap to zero...
718 if (newview >= (int)views.size())
729 FGViewMgr::getFOV_deg () const
731 const FGViewer * view = get_current_view();
732 return (view == 0 ? 0 : view->get_fov());
736 FGViewMgr::setFOV_deg (double fov)
738 FGViewer * view = get_current_view();
744 FGViewMgr::getARM_deg () const
746 const FGViewer * view = get_current_view();
747 return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
751 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
753 FGViewer * view = get_current_view();
755 view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
759 FGViewMgr::getNear_m () const
761 const FGViewer * view = get_current_view();
762 return (view == 0 ? 0.5f : view->getNear_m());
766 FGViewMgr::setNear_m (double near_m)
768 FGViewer * view = get_current_view();
770 view->setNear_m(near_m);
774 FGViewMgr::setViewAxisLong (double axis)
780 FGViewMgr::setViewAxisLat (double axis)
786 FGViewMgr::getViewLon_deg() const
788 const FGViewer* view = get_current_view();
789 return (view != NULL) ? view->getPosition().getLongitudeDeg() : 0.0;
793 FGViewMgr::getViewLat_deg() const
795 const FGViewer* view = get_current_view();
796 return (view != NULL) ? view->getPosition().getLatitudeDeg() : 0.0;
800 FGViewMgr::getViewElev_ft() const
802 const FGViewer* view = get_current_view();
803 return (view != NULL) ? view->getPosition().getElevationFt() : 0.0;
807 // reference frame orientation.
808 // This is the view orientation you get when you have no
809 // view offset, i.e. the offset operator is the identity.
811 // For example, in the familiar "cockpit lookfrom" view,
812 // the reference frame is equal to the aircraft attitude,
813 // i.e. it is the view looking towards 12:00 straight ahead.
815 // FIXME: Somebody needs to figure out what is the reference
816 // frame view for the other view modes.
818 // Conceptually, this quat represents a rotation relative
819 // to the ECEF reference orientation, as described at
820 // http://www.av8n.com/physics/coords.htm#sec-orientation
822 // See the NOTE concerning reference orientations, below.
824 // The components of this quat are expressed in
825 // the conventional aviation basis set,
826 // i.e. x=forward, y=starboard, z=bottom
827 double FGViewMgr::getCurrentViewFrame_w() const{
828 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).w();
830 double FGViewMgr::getCurrentViewFrame_x() const{
831 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).x();
833 double FGViewMgr::getCurrentViewFrame_y() const{
834 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).y();
836 double FGViewMgr::getCurrentViewFrame_z() const{
837 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).z();
842 // This rotation takes you from the aforementioned
843 // reference frame view orientation to whatever
844 // actual current view orientation is.
846 // The components of this quaternion are expressed in
847 // the conventional aviation basis set,
848 // i.e. x=forward, y=starboard, z=bottom
849 double FGViewMgr::getCurrentViewOrOffset_w() const{
850 return current_view_or_offset.w();
852 double FGViewMgr::getCurrentViewOrOffset_x() const{
853 return current_view_or_offset.x();
855 double FGViewMgr::getCurrentViewOrOffset_y() const{
856 return current_view_or_offset.y();
858 double FGViewMgr::getCurrentViewOrOffset_z() const{
859 return current_view_or_offset.z();
863 // current view orientation.
864 // This is a rotation relative to the earth-centered (ec)
867 // NOTE: Here we remove a factor of fsb2sta so that
868 // the components of this quat are displayed using the
869 // conventional ECEF basis set. This is *not* the way
870 // the view orientation is stored in the views[] array,
871 // but is easier for non-graphics hackers to understand.
872 // If we did not remove this factor of fsb2sta here and
873 // in getCurrentViewFrame, that would be equivalent to
874 // the following peculiar reference orientation:
875 // Suppose you are over the Gulf of Guinea, at (lat,lon) = (0,0).
876 // Then the reference frame orientation can be achieved via:
877 // -- The aircraft X-axis (nose) headed south.
878 // -- The aircraft Y-axis (starboard wingtip) pointing up.
879 // -- The aircraft Z-axis (belly) pointing west.
880 // To say the same thing in other words, and perhaps more to the
881 // point: If we use the OpenGL camera orientation conventions,
882 // i.e. Xprime=starboard, Yprime=top, Zprime=aft, then the
883 // aforementioned peculiar reference orientation at (lat,lon)
884 // = (0,0) can be described as:
885 // -- aircraft Xprime axis (starboard) pointed up
886 // -- aircraft Yprime axis (top) pointed east
887 // -- aircraft Zprime axis (aft) pointed north
888 // meaning the OpenGL axes are aligned with the ECEF axes.
889 double FGViewMgr::getCurrentViewOrientation_w() const{
890 return (current_view_orientation * conj(fsb2sta())).w();
892 double FGViewMgr::getCurrentViewOrientation_x() const{
893 return (current_view_orientation * conj(fsb2sta())).x();
895 double FGViewMgr::getCurrentViewOrientation_y() const{
896 return (current_view_orientation * conj(fsb2sta())).y();
898 double FGViewMgr::getCurrentViewOrientation_z() const{
899 return (current_view_orientation * conj(fsb2sta())).z();
903 FGViewMgr::do_axes ()
905 // Take no action when hat is centered
906 if ( ( axis_long < 0.01 ) &&
907 ( axis_long > -0.01 ) &&
908 ( axis_lat < 0.01 ) &&
913 double viewDir = 999;
915 /* Do all the quick and easy cases */
916 if (axis_long < 0) { // Longitudinal axis forward
917 if (axis_lat == axis_long)
918 viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
919 else if (axis_lat == - axis_long)
920 viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
921 else if (axis_lat == 0)
922 viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
923 } else if (axis_long > 0) { // Longitudinal axis backward
924 if (axis_lat == - axis_long)
925 viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
926 else if (axis_lat == axis_long)
927 viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
928 else if (axis_lat == 0)
929 viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
930 } else if (axis_long == 0) { // Longitudinal axis neutral
932 viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
933 else if (axis_lat > 0)
934 viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
935 else return; /* And assertion failure maybe? */
938 // Do all the difficult cases
940 viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
941 if ( viewDir < -1 ) viewDir += 360;
943 get_current_view()->setGoalHeadingOffset_deg(viewDir);