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 <simgear/scene/util/OsgMath.hxx>
35 #include <Main/fg_props.hxx>
38 #include "CameraGroup.hxx"
41 FGViewMgr::FGViewMgr( void ) :
45 view_number(fgGetNode("/sim/current-view/view-number", true)),
46 config_list(fgGetNode("/sim", true)->getChildren("view")),
47 abs_viewer_position(SGVec3d::zeros()),
49 current_view_orientation(SGQuatd::zeros()),
50 current_view_or_offset(SGQuatd::zeros())
55 FGViewMgr::~FGViewMgr( void )
63 SG_LOG(SG_VIEW, SG_WARN, "duplicate init of view manager");
70 current_x_offs = fgGetNode("/sim/current-view/x-offset-m", true);
71 current_y_offs = fgGetNode("/sim/current-view/y-offset-m", true);
72 current_z_offs = fgGetNode("/sim/current-view/z-offset-m", true);
73 target_x_offs = fgGetNode("/sim/current-view/target-x-offset-m", true);
74 target_y_offs = fgGetNode("/sim/current-view/target-y-offset-m", true);
75 target_z_offs = fgGetNode("/sim/current-view/target-z-offset-m", true);
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 flightgear::View* v = flightgear::View::createFromProperties(config);
95 // force update now so many properties of the current view are valid,
96 // eg view position and orientation (as exposed via globals)
101 FGViewMgr::shutdown()
113 int current_view_index = current;
115 // reset offsets and fov to configuration defaults
116 for (unsigned int i = 0; i < config_list.size(); i++) {
117 SGPropertyNode *n = config_list[i];
120 fgSetDouble("/sim/current-view/x-offset-m",
121 n->getDoubleValue("config/x-offset-m"));
122 fgSetDouble("/sim/current-view/y-offset-m",
123 n->getDoubleValue("config/y-offset-m"));
124 fgSetDouble("/sim/current-view/z-offset-m",
125 n->getDoubleValue("config/z-offset-m"));
126 fgSetDouble("/sim/current-view/pitch-offset-deg",
127 n->getDoubleValue("config/pitch-offset-deg"));
128 fgSetDouble("/sim/current-view/heading-offset-deg",
129 n->getDoubleValue("config/heading-offset-deg"));
130 fgSetDouble("/sim/current-view/roll-offset-deg",
131 n->getDoubleValue("config/roll-offset-deg"));
133 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
136 fgSetDouble("/sim/current-view/field-of-view", fov_deg);
138 // target offsets for lookat mode only...
139 fgSetDouble("/sim/current-view/target-x-offset-m",
140 n->getDoubleValue("config/target-x-offset-m"));
141 fgSetDouble("/sim/current-view/target-y-offset-m",
142 n->getDoubleValue("config/target-y-offset-m"));
143 fgSetDouble("/sim/current-view/target-z-offset-m",
144 n->getDoubleValue("config/target-z-offset-m"));
146 setView(current_view_index);
149 typedef double (FGViewMgr::*double_getter)() const;
154 // view-manager code was designed to init before bind, so
155 // this is a no-op; init() calls the real bind() impl below
161 // these are bound to the current view properties
162 _tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
163 _tiedProperties.Tie("heading-offset-deg", this,
164 &FGViewMgr::getViewHeadingOffset_deg,
165 &FGViewMgr::setViewHeadingOffset_deg);
166 fgSetArchivable("/sim/current-view/heading-offset-deg");
167 _tiedProperties.Tie("goal-heading-offset-deg", this,
168 &FGViewMgr::getViewGoalHeadingOffset_deg,
169 &FGViewMgr::setViewGoalHeadingOffset_deg);
170 fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
171 _tiedProperties.Tie("pitch-offset-deg", this,
172 &FGViewMgr::getViewPitchOffset_deg,
173 &FGViewMgr::setViewPitchOffset_deg);
174 fgSetArchivable("/sim/current-view/pitch-offset-deg");
175 _tiedProperties.Tie("goal-pitch-offset-deg", this,
176 &FGViewMgr::getGoalViewPitchOffset_deg,
177 &FGViewMgr::setGoalViewPitchOffset_deg);
178 fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
179 _tiedProperties.Tie("roll-offset-deg", this,
180 &FGViewMgr::getViewRollOffset_deg,
181 &FGViewMgr::setViewRollOffset_deg);
182 fgSetArchivable("/sim/current-view/roll-offset-deg");
183 _tiedProperties.Tie("goal-roll-offset-deg", this,
184 &FGViewMgr::getGoalViewRollOffset_deg,
185 &FGViewMgr::setGoalViewRollOffset_deg);
186 fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
188 _tiedProperties.Tie("view-number", this,
189 &FGViewMgr::getView, &FGViewMgr::setView);
190 SGPropertyNode* view_number =
191 _tiedProperties.getRoot()->getNode("view-number");
192 view_number->setAttribute(SGPropertyNode::ARCHIVE, false);
194 // Keep view on reset/reinit
195 view_number->setAttribute(SGPropertyNode::PRESERVE, true);
197 _tiedProperties.Tie("axes/long", this,
198 (double_getter)0, &FGViewMgr::setViewAxisLong);
199 fgSetArchivable("/sim/current-view/axes/long");
201 _tiedProperties.Tie("axes/lat", this,
202 (double_getter)0, &FGViewMgr::setViewAxisLat);
203 fgSetArchivable("/sim/current-view/axes/lat");
205 _tiedProperties.Tie("field-of-view", this,
206 &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
207 fgSetArchivable("/sim/current-view/field-of-view");
209 _tiedProperties.Tie("aspect-ratio-multiplier", this,
210 &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
211 fgSetArchivable("/sim/current-view/field-of-view");
213 _tiedProperties.Tie("ground-level-nearplane-m", this,
214 &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
215 fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
217 SGPropertyNode *n = fgGetNode("/sim/current-view", true);
218 _tiedProperties.Tie(n->getNode("viewer-x-m", true),SGRawValuePointer<double>(&abs_viewer_position[0]));
219 _tiedProperties.Tie(n->getNode("viewer-y-m", true),SGRawValuePointer<double>(&abs_viewer_position[1]));
220 _tiedProperties.Tie(n->getNode("viewer-z-m", true),SGRawValuePointer<double>(&abs_viewer_position[2]));
222 _tiedProperties.Tie("viewer-lon-deg", this, &FGViewMgr::getViewLon_deg);
223 _tiedProperties.Tie("viewer-lat-deg", this, &FGViewMgr::getViewLat_deg);
224 _tiedProperties.Tie("viewer-elev-ft", this, &FGViewMgr::getViewElev_ft);
227 _tiedProperties.Tie("debug/orientation-w", this,
228 &FGViewMgr::getCurrentViewOrientation_w);
229 _tiedProperties.Tie("debug/orientation-x", this,
230 &FGViewMgr::getCurrentViewOrientation_x);
231 _tiedProperties.Tie("debug/orientation-y", this,
232 &FGViewMgr::getCurrentViewOrientation_y);
233 _tiedProperties.Tie("debug/orientation-z", this,
234 &FGViewMgr::getCurrentViewOrientation_z);
236 _tiedProperties.Tie("debug/orientation_offset-w", this,
237 &FGViewMgr::getCurrentViewOrOffset_w);
238 _tiedProperties.Tie("debug/orientation_offset-x", this,
239 &FGViewMgr::getCurrentViewOrOffset_x);
240 _tiedProperties.Tie("debug/orientation_offset-y", this,
241 &FGViewMgr::getCurrentViewOrOffset_y);
242 _tiedProperties.Tie("debug/orientation_offset-z", this,
243 &FGViewMgr::getCurrentViewOrOffset_z);
245 _tiedProperties.Tie("debug/frame-w", this,
246 &FGViewMgr::getCurrentViewFrame_w);
247 _tiedProperties.Tie("debug/frame-x", this,
248 &FGViewMgr::getCurrentViewFrame_x);
249 _tiedProperties.Tie("debug/frame-y", this,
250 &FGViewMgr::getCurrentViewFrame_y);
251 _tiedProperties.Tie("debug/frame-z", this,
252 &FGViewMgr::getCurrentViewFrame_z);
258 _tiedProperties.Untie();
264 FGViewMgr::update (double dt)
266 flightgear::View* currentView = get_current_view();
267 if (!currentView) return;
269 SGPropertyNode *n = config_list[current];
270 SGPropertyNode *config = n->getChild("config", 0, true);
271 double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
273 // Set up view location and orientation
275 if (!config->getBoolValue("from-model")) {
276 lon_deg = fgGetDouble(config->getStringValue("eye-lon-deg-path"));
277 lat_deg = fgGetDouble(config->getStringValue("eye-lat-deg-path"));
278 alt_ft = fgGetDouble(config->getStringValue("eye-alt-ft-path"));
279 roll_deg = fgGetDouble(config->getStringValue("eye-roll-deg-path"));
280 pitch_deg = fgGetDouble(config->getStringValue("eye-pitch-deg-path"));
281 heading_deg = fgGetDouble(config->getStringValue("eye-heading-deg-path"));
283 currentView->setPosition(lon_deg, lat_deg, alt_ft);
284 currentView->setOrientation(roll_deg, pitch_deg, heading_deg);
286 // force recalc in viewer
287 currentView->set_dirty();
290 // if lookat (type 1) then get target data...
291 if (currentView->getType() == flightgear::View::FG_LOOKAT) {
292 if (!config->getBoolValue("from-model")) {
293 lon_deg = fgGetDouble(config->getStringValue("target-lon-deg-path"));
294 lat_deg = fgGetDouble(config->getStringValue("target-lat-deg-path"));
295 alt_ft = fgGetDouble(config->getStringValue("target-alt-ft-path"));
296 roll_deg = fgGetDouble(config->getStringValue("target-roll-deg-path"));
297 pitch_deg = fgGetDouble(config->getStringValue("target-pitch-deg-path"));
298 heading_deg = fgGetDouble(config->getStringValue("target-heading-deg-path"));
300 currentView->setTargetPosition(lon_deg, lat_deg, alt_ft);
301 currentView->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
303 currentView->set_dirty();
307 setViewXOffset_m(current_x_offs->getDoubleValue());
308 setViewYOffset_m(current_y_offs->getDoubleValue());
309 setViewZOffset_m(current_z_offs->getDoubleValue());
311 setViewTargetXOffset_m(target_x_offs->getDoubleValue());
312 setViewTargetYOffset_m(target_y_offs->getDoubleValue());
313 setViewTargetZOffset_m(target_z_offs->getDoubleValue());
315 current_view_orientation = currentView->getViewOrientation();
316 current_view_or_offset = currentView->getViewOrientationOffset();
318 // Update the current view
320 currentView->update(dt);
321 abs_viewer_position = currentView->getViewPosition();
324 // update the camera now
325 osg::ref_ptr<flightgear::CameraGroup> cameraGroup = flightgear::CameraGroup::getDefault();
326 cameraGroup->update(toOsg(abs_viewer_position),
327 toOsg(currentView->getViewOrientation()));
328 cameraGroup->setCameraParameters(currentView->get_v_fov(),
329 cameraGroup->getMasterAspectRatio());
331 // expose the raw (OpenGL) orientation to the property tree,
332 // for the sound-manager
333 for (int i=0; i<4; ++i) {
334 _tiedProperties.getRoot()->getChild("raw-orientation", i, true)->setDoubleValue(current_view_orientation[i]);
339 FGViewMgr::copyToCurrent()
345 SGPropertyNode *n = config_list[current];
346 fgSetString("/sim/current-view/name", n->getStringValue("name"));
347 fgSetString("/sim/current-view/type", n->getStringValue("type"));
349 // copy certain view config data for default values
350 fgSetDouble("/sim/current-view/config/heading-offset-deg",
351 n->getDoubleValue("config/default-heading-offset-deg"));
352 fgSetDouble("/sim/current-view/config/pitch-offset-deg",
353 n->getDoubleValue("config/pitch-offset-deg"));
354 fgSetDouble("/sim/current-view/config/roll-offset-deg",
355 n->getDoubleValue("config/roll-offset-deg"));
356 fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
357 n->getDoubleValue("config/default-field-of-view-deg"));
358 fgSetBool("/sim/current-view/config/from-model",
359 n->getBoolValue("config/from-model"));
362 fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
363 fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
364 fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
366 fgSetDouble("/sim/current-view/goal-heading-offset-deg",
367 get_current_view()->getGoalHeadingOffset_deg());
368 fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
369 get_current_view()->getGoalPitchOffset_deg());
370 fgSetDouble("/sim/current-view/goal-roll-offset-deg",
371 get_current_view()->getRollOffset_deg());
372 fgSetDouble("/sim/current-view/heading-offset-deg",
373 get_current_view()->getHeadingOffset_deg());
374 fgSetDouble("/sim/current-view/pitch-offset-deg",
375 get_current_view()->getPitchOffset_deg());
376 fgSetDouble("/sim/current-view/roll-offset-deg",
377 get_current_view()->getRollOffset_deg());
378 fgSetDouble("/sim/current-view/target-x-offset-m",
379 get_current_view()->getTargetXOffset_m());
380 fgSetDouble("/sim/current-view/target-y-offset-m",
381 get_current_view()->getTargetYOffset_m());
382 fgSetDouble("/sim/current-view/target-z-offset-m",
383 get_current_view()->getTargetZOffset_m());
384 fgSetBool("/sim/current-view/internal",
385 get_current_view()->getInternal());
388 void FGViewMgr::clear()
394 FGViewMgr::get_current_view()
396 if ( current < (int)views.size() ) {
397 return views[current];
403 const flightgear::View*
404 FGViewMgr::get_current_view() const
406 if ( current < (int)views.size() ) {
407 return views[current];
415 FGViewMgr::get_view( int i )
417 if ( i < 0 ) { i = 0; }
418 if ( i >= (int)views.size() ) { i = views.size() - 1; }
422 const flightgear::View*
423 FGViewMgr::get_view( int i ) const
425 if ( i < 0 ) { i = 0; }
426 if ( i >= (int)views.size() ) { i = views.size() - 1; }
431 FGViewMgr::next_view()
433 setView((current+1 < (int)views.size()) ? (current + 1) : 0);
434 view_number->fireValueChanged();
435 return views[current];
439 FGViewMgr::prev_view()
441 setView((0 < current) ? (current - 1) : (views.size() - 1));
442 view_number->fireValueChanged();
443 return views[current];
447 FGViewMgr::add_view( flightgear::View * v )
454 FGViewMgr::getViewHeadingOffset_deg () const
456 const flightgear::View * view = get_current_view();
457 return (view == 0 ? 0 : view->getHeadingOffset_deg());
461 FGViewMgr::setViewHeadingOffset_deg (double offset)
463 flightgear::View * view = get_current_view();
465 view->setGoalHeadingOffset_deg(offset);
466 view->setHeadingOffset_deg(offset);
471 FGViewMgr::getViewGoalHeadingOffset_deg () const
473 const flightgear::View * view = get_current_view();
474 return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
478 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
480 flightgear::View * view = get_current_view();
482 view->setGoalHeadingOffset_deg(offset);
486 FGViewMgr::getViewPitchOffset_deg () const
488 const flightgear::View * view = get_current_view();
489 return (view == 0 ? 0 : view->getPitchOffset_deg());
493 FGViewMgr::setViewPitchOffset_deg (double tilt)
495 flightgear::View * view = get_current_view();
497 view->setGoalPitchOffset_deg(tilt);
498 view->setPitchOffset_deg(tilt);
503 FGViewMgr::getGoalViewPitchOffset_deg () const
505 const flightgear::View * view = get_current_view();
506 return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
510 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
512 flightgear::View * view = get_current_view();
514 view->setGoalPitchOffset_deg(tilt);
518 FGViewMgr::getViewRollOffset_deg () const
520 const flightgear::View * view = get_current_view();
521 return (view == 0 ? 0 : view->getRollOffset_deg());
525 FGViewMgr::setViewRollOffset_deg (double tilt)
527 flightgear::View * view = get_current_view();
529 view->setGoalRollOffset_deg(tilt);
530 view->setRollOffset_deg(tilt);
535 FGViewMgr::getGoalViewRollOffset_deg () const
537 const flightgear::View * view = get_current_view();
538 return (view == 0 ? 0 : view->getGoalRollOffset_deg());
542 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
544 flightgear::View * view = get_current_view();
546 view->setGoalRollOffset_deg(tilt);
550 FGViewMgr::getViewXOffset_m () const
552 const flightgear::View * view = get_current_view();
554 return ((flightgear::View *)view)->getXOffset_m();
561 FGViewMgr::setViewXOffset_m (double x)
563 flightgear::View * view = get_current_view();
565 view->setXOffset_m(x);
570 FGViewMgr::getViewYOffset_m () const
572 const flightgear::View * view = get_current_view();
574 return ((flightgear::View *)view)->getYOffset_m();
581 FGViewMgr::setViewYOffset_m (double y)
583 flightgear::View * view = get_current_view();
585 view->setYOffset_m(y);
590 FGViewMgr::getViewZOffset_m () const
592 const flightgear::View * view = get_current_view();
594 return ((flightgear::View *)view)->getZOffset_m();
601 FGViewMgr::setViewZOffset_m (double z)
603 flightgear::View * view = get_current_view();
605 view->setZOffset_m(z);
610 FGViewMgr::getViewTargetXOffset_m () const
612 const flightgear::View * view = get_current_view();
614 return ((flightgear::View *)view)->getTargetXOffset_m();
621 FGViewMgr::setViewTargetXOffset_m (double x)
623 flightgear::View * view = get_current_view();
625 view->setTargetXOffset_m(x);
630 FGViewMgr::getViewTargetYOffset_m () const
632 const flightgear::View * view = get_current_view();
634 return ((flightgear::View *)view)->getTargetYOffset_m();
641 FGViewMgr::setViewTargetYOffset_m (double y)
643 flightgear::View * view = get_current_view();
645 view->setTargetYOffset_m(y);
650 FGViewMgr::getViewTargetZOffset_m () const
652 const flightgear::View * view = get_current_view();
654 return ((flightgear::View *)view)->getTargetZOffset_m();
661 FGViewMgr::setViewTargetZOffset_m (double z)
663 flightgear::View * view = get_current_view();
665 view->setTargetZOffset_m(z);
670 FGViewMgr::getView () const
676 FGViewMgr::setView (int newview)
678 // negative numbers -> set view with node index -newview
680 for (int i = 0; i < (int)config_list.size(); i++) {
681 int index = -config_list[i]->getIndex();
682 if (index == newview)
689 // if newview number too low wrap to last view...
691 newview = (int)views.size() - 1;
693 // if newview number to high wrap to zero...
694 if (newview >= (int)views.size())
702 // force an update now, to avoid returning bogus data.
703 // real fix would to be make all the accessors use the dirty mechanism
704 // on FGViewer, so update() is a no-op.
710 FGViewMgr::getFOV_deg () const
712 const flightgear::View * view = get_current_view();
713 return (view == 0 ? 0 : view->get_fov());
717 FGViewMgr::setFOV_deg (double fov)
719 flightgear::View * view = get_current_view();
725 FGViewMgr::getARM_deg () const
727 const flightgear::View * view = get_current_view();
728 return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
732 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
734 flightgear::View * view = get_current_view();
736 view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
740 FGViewMgr::getNear_m () const
742 const flightgear::View * view = get_current_view();
743 return (view == 0 ? 0.5f : view->getNear_m());
747 FGViewMgr::setNear_m (double near_m)
749 flightgear::View * view = get_current_view();
751 view->setNear_m(near_m);
755 FGViewMgr::setViewAxisLong (double axis)
761 FGViewMgr::setViewAxisLat (double axis)
767 FGViewMgr::getViewLon_deg() const
769 const flightgear::View* view = get_current_view();
770 return (view != NULL) ? view->getPosition().getLongitudeDeg() : 0.0;
774 FGViewMgr::getViewLat_deg() const
776 const flightgear::View* view = get_current_view();
777 return (view != NULL) ? view->getPosition().getLatitudeDeg() : 0.0;
781 FGViewMgr::getViewElev_ft() const
783 const flightgear::View* view = get_current_view();
784 return (view != NULL) ? view->getPosition().getElevationFt() : 0.0;
788 // reference frame orientation.
789 // This is the view orientation you get when you have no
790 // view offset, i.e. the offset operator is the identity.
792 // For example, in the familiar "cockpit lookfrom" view,
793 // the reference frame is equal to the aircraft attitude,
794 // i.e. it is the view looking towards 12:00 straight ahead.
796 // FIXME: Somebody needs to figure out what is the reference
797 // frame view for the other view modes.
799 // Conceptually, this quat represents a rotation relative
800 // to the ECEF reference orientation, as described at
801 // http://www.av8n.com/physics/coords.htm#sec-orientation
803 // See the NOTE concerning reference orientations, below.
805 // The components of this quat are expressed in
806 // the conventional aviation basis set,
807 // i.e. x=forward, y=starboard, z=bottom
808 double FGViewMgr::getCurrentViewFrame_w() const{
809 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).w();
811 double FGViewMgr::getCurrentViewFrame_x() const{
812 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).x();
814 double FGViewMgr::getCurrentViewFrame_y() const{
815 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).y();
817 double FGViewMgr::getCurrentViewFrame_z() const{
818 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).z();
823 // This rotation takes you from the aforementioned
824 // reference frame view orientation to whatever
825 // actual current view orientation is.
827 // The components of this quaternion are expressed in
828 // the conventional aviation basis set,
829 // i.e. x=forward, y=starboard, z=bottom
830 double FGViewMgr::getCurrentViewOrOffset_w() const{
831 return current_view_or_offset.w();
833 double FGViewMgr::getCurrentViewOrOffset_x() const{
834 return current_view_or_offset.x();
836 double FGViewMgr::getCurrentViewOrOffset_y() const{
837 return current_view_or_offset.y();
839 double FGViewMgr::getCurrentViewOrOffset_z() const{
840 return current_view_or_offset.z();
844 // current view orientation.
845 // This is a rotation relative to the earth-centered (ec)
848 // NOTE: Here we remove a factor of fsb2sta so that
849 // the components of this quat are displayed using the
850 // conventional ECEF basis set. This is *not* the way
851 // the view orientation is stored in the views[] array,
852 // but is easier for non-graphics hackers to understand.
853 // If we did not remove this factor of fsb2sta here and
854 // in getCurrentViewFrame, that would be equivalent to
855 // the following peculiar reference orientation:
856 // Suppose you are over the Gulf of Guinea, at (lat,lon) = (0,0).
857 // Then the reference frame orientation can be achieved via:
858 // -- The aircraft X-axis (nose) headed south.
859 // -- The aircraft Y-axis (starboard wingtip) pointing up.
860 // -- The aircraft Z-axis (belly) pointing west.
861 // To say the same thing in other words, and perhaps more to the
862 // point: If we use the OpenGL camera orientation conventions,
863 // i.e. Xprime=starboard, Yprime=top, Zprime=aft, then the
864 // aforementioned peculiar reference orientation at (lat,lon)
865 // = (0,0) can be described as:
866 // -- aircraft Xprime axis (starboard) pointed up
867 // -- aircraft Yprime axis (top) pointed east
868 // -- aircraft Zprime axis (aft) pointed north
869 // meaning the OpenGL axes are aligned with the ECEF axes.
870 double FGViewMgr::getCurrentViewOrientation_w() const{
871 return (current_view_orientation * conj(fsb2sta())).w();
873 double FGViewMgr::getCurrentViewOrientation_x() const{
874 return (current_view_orientation * conj(fsb2sta())).x();
876 double FGViewMgr::getCurrentViewOrientation_y() const{
877 return (current_view_orientation * conj(fsb2sta())).y();
879 double FGViewMgr::getCurrentViewOrientation_z() const{
880 return (current_view_orientation * conj(fsb2sta())).z();
884 FGViewMgr::do_axes ()
886 // Take no action when hat is centered
887 if ( ( axis_long < 0.01 ) &&
888 ( axis_long > -0.01 ) &&
889 ( axis_lat < 0.01 ) &&
894 double viewDir = 999;
896 /* Do all the quick and easy cases */
897 if (axis_long < 0) { // Longitudinal axis forward
898 if (axis_lat == axis_long)
899 viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
900 else if (axis_lat == - axis_long)
901 viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
902 else if (axis_lat == 0)
903 viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
904 } else if (axis_long > 0) { // Longitudinal axis backward
905 if (axis_lat == - axis_long)
906 viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
907 else if (axis_lat == axis_long)
908 viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
909 else if (axis_lat == 0)
910 viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
911 } else if (axis_long == 0) { // Longitudinal axis neutral
913 viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
914 else if (axis_lat > 0)
915 viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
916 else return; /* And assertion failure maybe? */
919 // Do all the difficult cases
921 viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
922 if ( viewDir < -1 ) viewDir += 360;
924 get_current_view()->setGoalHeadingOffset_deg(viewDir);