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/sound/soundmgr_openal.hxx>
34 #include <Main/fg_props.hxx>
38 FGViewMgr::FGViewMgr( void ) :
42 view_number(fgGetNode("/sim/current-view/view-number", true)),
43 config_list(fgGetNode("/sim", true)->getChildren("view")),
44 abs_viewer_position(SGVec3d::zeros()),
46 current_view_orientation(SGQuatd::zeros()),
47 current_view_or_offset(SGQuatd::zeros()),
48 smgr(globals->get_soundmgr())
53 FGViewMgr::~FGViewMgr( void ) {
60 SG_LOG(SG_VIEW, SG_WARN, "duplicate init of view manager");
66 double aspect_ratio_multiplier
67 = fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
69 for (unsigned int i = 0; i < config_list.size(); i++) {
70 SGPropertyNode *n = config_list[i];
72 // find out if this is an internal view (e.g. in cockpit, low near plane)
73 bool internal = n->getBoolValue("internal", false);
76 // this is assumed to be an aircraft model...we will need to read
77 // model-from-type as well.
79 // find out if this is a model we are looking from...
80 bool from_model = n->getBoolValue("config/from-model");
81 int from_model_index = n->getIntValue("config/from-model-idx");
83 double x_offset_m = n->getDoubleValue("config/x-offset-m");
84 double y_offset_m = n->getDoubleValue("config/y-offset-m");
85 double z_offset_m = n->getDoubleValue("config/z-offset-m");
87 double heading_offset_deg = n->getDoubleValue("config/heading-offset-deg");
88 n->setDoubleValue("config/heading-offset-deg", heading_offset_deg);
89 double pitch_offset_deg = n->getDoubleValue("config/pitch-offset-deg");
90 n->setDoubleValue("config/pitch-offset-deg", pitch_offset_deg);
91 double roll_offset_deg = n->getDoubleValue("config/roll-offset-deg");
92 n->setDoubleValue("config/roll-offset-deg", roll_offset_deg);
94 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
95 double near_m = n->getDoubleValue("config/ground-level-nearplane-m");
97 // supporting two types "lookat" = 1 and "lookfrom" = 0
98 const char *type = n->getStringValue("type");
99 if (!strcmp(type, "lookat")) {
101 bool at_model = n->getBoolValue("config/at-model");
102 int at_model_index = n->getIntValue("config/at-model-idx");
104 double damp_roll = n->getDoubleValue("config/at-model-roll-damping");
105 double damp_pitch = n->getDoubleValue("config/at-model-pitch-damping");
106 double damp_heading = n->getDoubleValue("config/at-model-heading-damping");
108 double target_x_offset_m = n->getDoubleValue("config/target-x-offset-m");
109 double target_y_offset_m = n->getDoubleValue("config/target-y-offset-m");
110 double target_z_offset_m = n->getDoubleValue("config/target-z-offset-m");
112 add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
113 at_model, at_model_index,
114 damp_roll, damp_pitch, damp_heading,
115 x_offset_m, y_offset_m,z_offset_m,
116 heading_offset_deg, pitch_offset_deg,
117 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
118 target_x_offset_m, target_y_offset_m,
119 target_z_offset_m, near_m, internal ));
121 add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index,
122 false, 0, 0.0, 0.0, 0.0,
123 x_offset_m, y_offset_m, z_offset_m,
124 heading_offset_deg, pitch_offset_deg,
125 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
126 0, 0, 0, near_m, internal ));
137 // reset offsets and fov to configuration defaults
138 for (unsigned int i = 0; i < config_list.size(); i++) {
139 SGPropertyNode *n = config_list[i];
142 fgSetDouble("/sim/current-view/x-offset-m",
143 n->getDoubleValue("config/x-offset-m"));
144 fgSetDouble("/sim/current-view/y-offset-m",
145 n->getDoubleValue("config/y-offset-m"));
146 fgSetDouble("/sim/current-view/z-offset-m",
147 n->getDoubleValue("config/z-offset-m"));
148 fgSetDouble("/sim/current-view/pitch-offset-deg",
149 n->getDoubleValue("config/pitch-offset-deg"));
150 fgSetDouble("/sim/current-view/heading-offset-deg",
151 n->getDoubleValue("config/heading-offset-deg"));
152 fgSetDouble("/sim/current-view/roll-offset-deg",
153 n->getDoubleValue("config/roll-offset-deg"));
155 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
158 fgSetDouble("/sim/current-view/field-of-view", fov_deg);
160 // target offsets for lookat mode only...
161 fgSetDouble("/sim/current-view/target-x-offset-m",
162 n->getDoubleValue("config/target-x-offset-m"));
163 fgSetDouble("/sim/current-view/target-y-offset-m",
164 n->getDoubleValue("config/target-y-offset-m"));
165 fgSetDouble("/sim/current-view/target-z-offset-m",
166 n->getDoubleValue("config/target-z-offset-m"));
171 typedef double (FGViewMgr::*double_getter)() const;
176 // view-manager code was designed to init before bind, so
177 // this is a no-op; init() calls the real bind() impl below
183 velocityNorthFPS = fgGetNode("velocities/speed-north-fps", true);
184 velocityEastFPS = fgGetNode("velocities/speed-east-fps", true);
185 velocityDownFPS = fgGetNode("velocities/speed-down-fps", true);
187 // these are bound to the current view properties
188 _tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
189 _tiedProperties.Tie("heading-offset-deg", this,
190 &FGViewMgr::getViewHeadingOffset_deg,
191 &FGViewMgr::setViewHeadingOffset_deg);
192 fgSetArchivable("/sim/current-view/heading-offset-deg");
193 _tiedProperties.Tie("goal-heading-offset-deg", this,
194 &FGViewMgr::getViewGoalHeadingOffset_deg,
195 &FGViewMgr::setViewGoalHeadingOffset_deg);
196 fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
197 _tiedProperties.Tie("pitch-offset-deg", this,
198 &FGViewMgr::getViewPitchOffset_deg,
199 &FGViewMgr::setViewPitchOffset_deg);
200 fgSetArchivable("/sim/current-view/pitch-offset-deg");
201 _tiedProperties.Tie("goal-pitch-offset-deg", this,
202 &FGViewMgr::getGoalViewPitchOffset_deg,
203 &FGViewMgr::setGoalViewPitchOffset_deg);
204 fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
205 _tiedProperties.Tie("roll-offset-deg", this,
206 &FGViewMgr::getViewRollOffset_deg,
207 &FGViewMgr::setViewRollOffset_deg);
208 fgSetArchivable("/sim/current-view/roll-offset-deg");
209 _tiedProperties.Tie("goal-roll-offset-deg", this,
210 &FGViewMgr::getGoalViewRollOffset_deg,
211 &FGViewMgr::setGoalViewRollOffset_deg);
212 fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
214 _tiedProperties.Tie("view-number", this,
215 &FGViewMgr::getView, &FGViewMgr::setView);
216 fgSetArchivable("/sim/current-view/view-number", false);
218 _tiedProperties.Tie("axes/long", this,
219 (double_getter)0, &FGViewMgr::setViewAxisLong);
220 fgSetArchivable("/sim/current-view/axes/long");
222 _tiedProperties.Tie("axes/lat", this,
223 (double_getter)0, &FGViewMgr::setViewAxisLat);
224 fgSetArchivable("/sim/current-view/axes/lat");
226 _tiedProperties.Tie("field-of-view", this,
227 &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
228 fgSetArchivable("/sim/current-view/field-of-view");
230 _tiedProperties.Tie("aspect-ratio-multiplier", this,
231 &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
232 fgSetArchivable("/sim/current-view/field-of-view");
234 _tiedProperties.Tie("ground-level-nearplane-m", this,
235 &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
236 fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
238 SGPropertyNode *n = fgGetNode("/sim/current-view", true);
239 _tiedProperties.Tie(n->getNode("viewer-x-m", true),SGRawValuePointer<double>(&abs_viewer_position[0]));
240 _tiedProperties.Tie(n->getNode("viewer-y-m", true),SGRawValuePointer<double>(&abs_viewer_position[1]));
241 _tiedProperties.Tie(n->getNode("viewer-z-m", true),SGRawValuePointer<double>(&abs_viewer_position[2]));
243 _tiedProperties.Tie("debug/orientation-w", this,
244 &FGViewMgr::getCurrentViewOrientation_w);
245 _tiedProperties.Tie("debug/orientation-x", this,
246 &FGViewMgr::getCurrentViewOrientation_x);
247 _tiedProperties.Tie("debug/orientation-y", this,
248 &FGViewMgr::getCurrentViewOrientation_y);
249 _tiedProperties.Tie("debug/orientation-z", this,
250 &FGViewMgr::getCurrentViewOrientation_z);
252 _tiedProperties.Tie("debug/orientation_offset-w", this,
253 &FGViewMgr::getCurrentViewOrOffset_w);
254 _tiedProperties.Tie("debug/orientation_offset-x", this,
255 &FGViewMgr::getCurrentViewOrOffset_x);
256 _tiedProperties.Tie("debug/orientation_offset-y", this,
257 &FGViewMgr::getCurrentViewOrOffset_y);
258 _tiedProperties.Tie("debug/orientation_offset-z", this,
259 &FGViewMgr::getCurrentViewOrOffset_z);
261 _tiedProperties.Tie("debug/frame-w", this,
262 &FGViewMgr::getCurrentViewFrame_w);
263 _tiedProperties.Tie("debug/frame-x", this,
264 &FGViewMgr::getCurrentViewFrame_x);
265 _tiedProperties.Tie("debug/frame-y", this,
266 &FGViewMgr::getCurrentViewFrame_y);
267 _tiedProperties.Tie("debug/frame-z", this,
268 &FGViewMgr::getCurrentViewFrame_z);
274 _tiedProperties.Untie();
278 FGViewMgr::update (double dt)
280 FGViewer *loop_view = (FGViewer *)get_current_view();
281 if (loop_view == 0) return;
283 SGPropertyNode *n = config_list[current];
284 double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
286 // Set up view location and orientation
288 if (!n->getBoolValue("config/from-model")) {
289 lon_deg = fgGetDouble(n->getStringValue("config/eye-lon-deg-path"));
290 lat_deg = fgGetDouble(n->getStringValue("config/eye-lat-deg-path"));
291 alt_ft = fgGetDouble(n->getStringValue("config/eye-alt-ft-path"));
292 roll_deg = fgGetDouble(n->getStringValue("config/eye-roll-deg-path"));
293 pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path"));
294 heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path"));
296 loop_view->setPosition(lon_deg, lat_deg, alt_ft);
297 loop_view->setOrientation(roll_deg, pitch_deg, heading_deg);
299 // force recalc in viewer
300 loop_view->set_dirty();
303 // if lookat (type 1) then get target data...
304 if (loop_view->getType() == FG_LOOKAT) {
305 if (!n->getBoolValue("config/from-model")) {
306 lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path"));
307 lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path"));
308 alt_ft = fgGetDouble(n->getStringValue("config/target-alt-ft-path"));
309 roll_deg = fgGetDouble(n->getStringValue("config/target-roll-deg-path"));
310 pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path"));
311 heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path"));
313 loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft);
314 loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
316 loop_view->set_dirty();
320 setViewXOffset_m(fgGetDouble("/sim/current-view/x-offset-m"));
321 setViewYOffset_m(fgGetDouble("/sim/current-view/y-offset-m"));
322 setViewZOffset_m(fgGetDouble("/sim/current-view/z-offset-m"));
324 setViewTargetXOffset_m(fgGetDouble("/sim/current-view/target-x-offset-m"));
325 setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m"));
326 setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m"));
328 current_view_orientation = loop_view->getViewOrientation();
329 current_view_or_offset = loop_view->getViewOrientationOffset();
331 // Update the current view
333 loop_view->update(dt);
334 abs_viewer_position = loop_view->getViewPosition();
336 // update audio listener values
337 // set the viewer position in Cartesian coordinates in meters
338 smgr->set_position( abs_viewer_position, loop_view->getPosition() );
339 smgr->set_orientation( current_view_orientation );
341 // get the model velocity
342 SGVec3d velocity = SGVec3d::zeros();
343 if ( !stationary() ) {
344 velocity = SGVec3d( velocityNorthFPS->getDoubleValue(),
345 velocityEastFPS->getDoubleValue(),
346 velocityDownFPS->getDoubleValue() );
348 smgr->set_velocity( velocity );
352 FGViewMgr::copyToCurrent()
358 SGPropertyNode *n = config_list[current];
359 fgSetString("/sim/current-view/name", n->getStringValue("name"));
360 fgSetString("/sim/current-view/type", n->getStringValue("type"));
362 // copy certain view config data for default values
363 fgSetDouble("/sim/current-view/config/heading-offset-deg",
364 n->getDoubleValue("config/default-heading-offset-deg"));
365 fgSetDouble("/sim/current-view/config/pitch-offset-deg",
366 n->getDoubleValue("config/pitch-offset-deg"));
367 fgSetDouble("/sim/current-view/config/roll-offset-deg",
368 n->getDoubleValue("config/roll-offset-deg"));
369 fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
370 n->getDoubleValue("config/default-field-of-view-deg"));
371 fgSetBool("/sim/current-view/config/from-model",
372 n->getBoolValue("config/from-model"));
375 fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
376 fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
377 fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
379 fgSetDouble("/sim/current-view/goal-heading-offset-deg",
380 get_current_view()->getGoalHeadingOffset_deg());
381 fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
382 get_current_view()->getGoalPitchOffset_deg());
383 fgSetDouble("/sim/current-view/goal-roll-offset-deg",
384 get_current_view()->getRollOffset_deg());
385 fgSetDouble("/sim/current-view/heading-offset-deg",
386 get_current_view()->getHeadingOffset_deg());
387 fgSetDouble("/sim/current-view/pitch-offset-deg",
388 get_current_view()->getPitchOffset_deg());
389 fgSetDouble("/sim/current-view/roll-offset-deg",
390 get_current_view()->getRollOffset_deg());
391 fgSetDouble("/sim/current-view/target-x-offset-m",
392 get_current_view()->getTargetXOffset_m());
393 fgSetDouble("/sim/current-view/target-y-offset-m",
394 get_current_view()->getTargetYOffset_m());
395 fgSetDouble("/sim/current-view/target-z-offset-m",
396 get_current_view()->getTargetZOffset_m());
397 fgSetBool("/sim/current-view/internal",
398 get_current_view()->getInternal());
401 void FGViewMgr::clear()
407 FGViewMgr::get_current_view()
409 if ( current < (int)views.size() ) {
410 return views[current];
417 FGViewMgr::get_current_view() const
419 if ( current < (int)views.size() ) {
420 return views[current];
428 FGViewMgr::get_view( int i )
430 if ( i < 0 ) { i = 0; }
431 if ( i >= (int)views.size() ) { i = views.size() - 1; }
436 FGViewMgr::get_view( int i ) const
438 if ( i < 0 ) { i = 0; }
439 if ( i >= (int)views.size() ) { i = views.size() - 1; }
444 FGViewMgr::next_view()
446 setView((current+1 < (int)views.size()) ? (current + 1) : 0);
447 view_number->fireValueChanged();
448 return views[current];
452 FGViewMgr::prev_view()
454 setView((0 < current) ? (current - 1) : (views.size() - 1));
455 view_number->fireValueChanged();
456 return views[current];
460 FGViewMgr::add_view( FGViewer * v )
467 FGViewMgr::getViewHeadingOffset_deg () const
469 const FGViewer * view = get_current_view();
470 return (view == 0 ? 0 : view->getHeadingOffset_deg());
474 FGViewMgr::setViewHeadingOffset_deg (double offset)
476 FGViewer * view = get_current_view();
478 view->setGoalHeadingOffset_deg(offset);
479 view->setHeadingOffset_deg(offset);
484 FGViewMgr::getViewGoalHeadingOffset_deg () const
486 const FGViewer * view = get_current_view();
487 return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
491 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
493 FGViewer * view = get_current_view();
495 view->setGoalHeadingOffset_deg(offset);
499 FGViewMgr::getViewPitchOffset_deg () const
501 const FGViewer * view = get_current_view();
502 return (view == 0 ? 0 : view->getPitchOffset_deg());
506 FGViewMgr::setViewPitchOffset_deg (double tilt)
508 FGViewer * view = get_current_view();
510 view->setGoalPitchOffset_deg(tilt);
511 view->setPitchOffset_deg(tilt);
516 FGViewMgr::getGoalViewPitchOffset_deg () const
518 const FGViewer * view = get_current_view();
519 return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
523 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
525 FGViewer * view = get_current_view();
527 view->setGoalPitchOffset_deg(tilt);
531 FGViewMgr::getViewRollOffset_deg () const
533 const FGViewer * view = get_current_view();
534 return (view == 0 ? 0 : view->getRollOffset_deg());
538 FGViewMgr::setViewRollOffset_deg (double tilt)
540 FGViewer * view = get_current_view();
542 view->setGoalRollOffset_deg(tilt);
543 view->setRollOffset_deg(tilt);
548 FGViewMgr::getGoalViewRollOffset_deg () const
550 const FGViewer * view = get_current_view();
551 return (view == 0 ? 0 : view->getGoalRollOffset_deg());
555 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
557 FGViewer * view = get_current_view();
559 view->setGoalRollOffset_deg(tilt);
563 FGViewMgr::getViewXOffset_m () const
565 const FGViewer * view = get_current_view();
567 return ((FGViewer *)view)->getXOffset_m();
574 FGViewMgr::setViewXOffset_m (double x)
576 FGViewer * view = get_current_view();
578 view->setXOffset_m(x);
583 FGViewMgr::getViewYOffset_m () const
585 const FGViewer * view = get_current_view();
587 return ((FGViewer *)view)->getYOffset_m();
594 FGViewMgr::setViewYOffset_m (double y)
596 FGViewer * view = get_current_view();
598 view->setYOffset_m(y);
603 FGViewMgr::getViewZOffset_m () const
605 const FGViewer * view = get_current_view();
607 return ((FGViewer *)view)->getZOffset_m();
614 FGViewMgr::setViewZOffset_m (double z)
616 FGViewer * view = get_current_view();
618 view->setZOffset_m(z);
623 FGViewMgr::stationary () const
625 const FGViewer * view = get_current_view();
627 if (((FGViewer *)view)->getXOffset_m() == 0.0 &&
628 ((FGViewer *)view)->getYOffset_m() == 0.0 &&
629 ((FGViewer *)view)->getZOffset_m() == 0.0)
637 FGViewMgr::getViewTargetXOffset_m () const
639 const FGViewer * view = get_current_view();
641 return ((FGViewer *)view)->getTargetXOffset_m();
648 FGViewMgr::setViewTargetXOffset_m (double x)
650 FGViewer * view = get_current_view();
652 view->setTargetXOffset_m(x);
657 FGViewMgr::getViewTargetYOffset_m () const
659 const FGViewer * view = get_current_view();
661 return ((FGViewer *)view)->getTargetYOffset_m();
668 FGViewMgr::setViewTargetYOffset_m (double y)
670 FGViewer * view = get_current_view();
672 view->setTargetYOffset_m(y);
677 FGViewMgr::getViewTargetZOffset_m () const
679 const FGViewer * view = get_current_view();
681 return ((FGViewer *)view)->getTargetZOffset_m();
688 FGViewMgr::setViewTargetZOffset_m (double z)
690 FGViewer * view = get_current_view();
692 view->setTargetZOffset_m(z);
697 FGViewMgr::getView () const
703 FGViewMgr::setView (int newview)
705 // negative numbers -> set view with node index -newview
707 for (int i = 0; i < (int)config_list.size(); i++) {
708 int index = -config_list[i]->getIndex();
709 if (index == newview)
716 // if newview number too low wrap to last view...
718 newview = (int)views.size() - 1;
720 // if newview number to high wrap to zero...
721 if (newview >= (int)views.size())
732 FGViewMgr::getFOV_deg () const
734 const FGViewer * view = get_current_view();
735 return (view == 0 ? 0 : view->get_fov());
739 FGViewMgr::setFOV_deg (double fov)
741 FGViewer * view = get_current_view();
747 FGViewMgr::getARM_deg () const
749 const FGViewer * view = get_current_view();
750 return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
754 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
756 FGViewer * view = get_current_view();
758 view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
762 FGViewMgr::getNear_m () const
764 const FGViewer * view = get_current_view();
765 return (view == 0 ? 0.5f : view->getNear_m());
769 FGViewMgr::setNear_m (double near_m)
771 FGViewer * view = get_current_view();
773 view->setNear_m(near_m);
777 FGViewMgr::setViewAxisLong (double axis)
783 FGViewMgr::setViewAxisLat (double axis)
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);