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 <Model/acmodel.hxx>
35 #include <Main/fg_props.hxx>
39 FGViewMgr::FGViewMgr( void ) :
43 view_number(fgGetNode("/sim/current-view/view-number", true)),
44 config_list(fgGetNode("/sim", true)->getChildren("view")),
45 abs_viewer_position(SGVec3d::zeros()),
47 current_view_orientation(SGQuatd::zeros()),
48 current_view_or_offset(SGQuatd::zeros()),
49 smgr(globals->get_soundmgr())
54 FGViewMgr::~FGViewMgr( void ) {
61 SG_LOG(SG_VIEW, SG_WARN, "duplicate init of view manager");
67 double aspect_ratio_multiplier
68 = fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
70 for (unsigned int i = 0; i < config_list.size(); i++) {
71 SGPropertyNode *n = config_list[i];
73 // find out if this is an internal view (e.g. in cockpit, low near plane)
74 bool internal = n->getBoolValue("internal", false);
77 // this is assumed to be an aircraft model...we will need to read
78 // model-from-type as well.
80 // find out if this is a model we are looking from...
81 bool from_model = n->getBoolValue("config/from-model");
82 int from_model_index = n->getIntValue("config/from-model-idx");
84 double x_offset_m = n->getDoubleValue("config/x-offset-m");
85 double y_offset_m = n->getDoubleValue("config/y-offset-m");
86 double z_offset_m = n->getDoubleValue("config/z-offset-m");
88 double heading_offset_deg = n->getDoubleValue("config/heading-offset-deg");
89 n->setDoubleValue("config/heading-offset-deg", heading_offset_deg);
90 double pitch_offset_deg = n->getDoubleValue("config/pitch-offset-deg");
91 n->setDoubleValue("config/pitch-offset-deg", pitch_offset_deg);
92 double roll_offset_deg = n->getDoubleValue("config/roll-offset-deg");
93 n->setDoubleValue("config/roll-offset-deg", roll_offset_deg);
95 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
96 double near_m = n->getDoubleValue("config/ground-level-nearplane-m");
98 // supporting two types "lookat" = 1 and "lookfrom" = 0
99 const char *type = n->getStringValue("type");
100 if (!strcmp(type, "lookat")) {
102 bool at_model = n->getBoolValue("config/at-model");
103 int at_model_index = n->getIntValue("config/at-model-idx");
105 double damp_roll = n->getDoubleValue("config/at-model-roll-damping");
106 double damp_pitch = n->getDoubleValue("config/at-model-pitch-damping");
107 double damp_heading = n->getDoubleValue("config/at-model-heading-damping");
109 double target_x_offset_m = n->getDoubleValue("config/target-x-offset-m");
110 double target_y_offset_m = n->getDoubleValue("config/target-y-offset-m");
111 double target_z_offset_m = n->getDoubleValue("config/target-z-offset-m");
113 add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
114 at_model, at_model_index,
115 damp_roll, damp_pitch, damp_heading,
116 x_offset_m, y_offset_m,z_offset_m,
117 heading_offset_deg, pitch_offset_deg,
118 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
119 target_x_offset_m, target_y_offset_m,
120 target_z_offset_m, near_m, internal ));
122 add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index,
123 false, 0, 0.0, 0.0, 0.0,
124 x_offset_m, y_offset_m, z_offset_m,
125 heading_offset_deg, pitch_offset_deg,
126 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
127 0, 0, 0, near_m, internal ));
138 // reset offsets and fov to configuration defaults
139 for (unsigned int i = 0; i < config_list.size(); i++) {
140 SGPropertyNode *n = config_list[i];
143 fgSetDouble("/sim/current-view/x-offset-m",
144 n->getDoubleValue("config/x-offset-m"));
145 fgSetDouble("/sim/current-view/y-offset-m",
146 n->getDoubleValue("config/y-offset-m"));
147 fgSetDouble("/sim/current-view/z-offset-m",
148 n->getDoubleValue("config/z-offset-m"));
149 fgSetDouble("/sim/current-view/pitch-offset-deg",
150 n->getDoubleValue("config/pitch-offset-deg"));
151 fgSetDouble("/sim/current-view/heading-offset-deg",
152 n->getDoubleValue("config/heading-offset-deg"));
153 fgSetDouble("/sim/current-view/roll-offset-deg",
154 n->getDoubleValue("config/roll-offset-deg"));
156 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
159 fgSetDouble("/sim/current-view/field-of-view", fov_deg);
161 // target offsets for lookat mode only...
162 fgSetDouble("/sim/current-view/target-x-offset-m",
163 n->getDoubleValue("config/target-x-offset-m"));
164 fgSetDouble("/sim/current-view/target-y-offset-m",
165 n->getDoubleValue("config/target-y-offset-m"));
166 fgSetDouble("/sim/current-view/target-z-offset-m",
167 n->getDoubleValue("config/target-z-offset-m"));
172 typedef double (FGViewMgr::*double_getter)() const;
177 // view-manager code was designed to init before bind, so
178 // this is a no-op; init() calls the real bind() impl below
184 // these are bound to the current view properties
185 _tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
186 _tiedProperties.Tie("heading-offset-deg", this,
187 &FGViewMgr::getViewHeadingOffset_deg,
188 &FGViewMgr::setViewHeadingOffset_deg);
189 fgSetArchivable("/sim/current-view/heading-offset-deg");
190 _tiedProperties.Tie("goal-heading-offset-deg", this,
191 &FGViewMgr::getViewGoalHeadingOffset_deg,
192 &FGViewMgr::setViewGoalHeadingOffset_deg);
193 fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
194 _tiedProperties.Tie("pitch-offset-deg", this,
195 &FGViewMgr::getViewPitchOffset_deg,
196 &FGViewMgr::setViewPitchOffset_deg);
197 fgSetArchivable("/sim/current-view/pitch-offset-deg");
198 _tiedProperties.Tie("goal-pitch-offset-deg", this,
199 &FGViewMgr::getGoalViewPitchOffset_deg,
200 &FGViewMgr::setGoalViewPitchOffset_deg);
201 fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
202 _tiedProperties.Tie("roll-offset-deg", this,
203 &FGViewMgr::getViewRollOffset_deg,
204 &FGViewMgr::setViewRollOffset_deg);
205 fgSetArchivable("/sim/current-view/roll-offset-deg");
206 _tiedProperties.Tie("goal-roll-offset-deg", this,
207 &FGViewMgr::getGoalViewRollOffset_deg,
208 &FGViewMgr::setGoalViewRollOffset_deg);
209 fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
211 _tiedProperties.Tie("view-number", this,
212 &FGViewMgr::getView, &FGViewMgr::setView);
213 fgSetArchivable("/sim/current-view/view-number", false);
215 _tiedProperties.Tie("axes/long", this,
216 (double_getter)0, &FGViewMgr::setViewAxisLong);
217 fgSetArchivable("/sim/current-view/axes/long");
219 _tiedProperties.Tie("axes/lat", this,
220 (double_getter)0, &FGViewMgr::setViewAxisLat);
221 fgSetArchivable("/sim/current-view/axes/lat");
223 _tiedProperties.Tie("field-of-view", this,
224 &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
225 fgSetArchivable("/sim/current-view/field-of-view");
227 _tiedProperties.Tie("aspect-ratio-multiplier", this,
228 &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
229 fgSetArchivable("/sim/current-view/field-of-view");
231 _tiedProperties.Tie("ground-level-nearplane-m", this,
232 &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
233 fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
235 SGPropertyNode *n = fgGetNode("/sim/current-view", true);
236 _tiedProperties.Tie(n->getNode("viewer-x-m", true),SGRawValuePointer<double>(&abs_viewer_position[0]));
237 _tiedProperties.Tie(n->getNode("viewer-y-m", true),SGRawValuePointer<double>(&abs_viewer_position[1]));
238 _tiedProperties.Tie(n->getNode("viewer-z-m", true),SGRawValuePointer<double>(&abs_viewer_position[2]));
240 _tiedProperties.Tie("debug/orientation-w", this,
241 &FGViewMgr::getCurrentViewOrientation_w);
242 _tiedProperties.Tie("debug/orientation-x", this,
243 &FGViewMgr::getCurrentViewOrientation_x);
244 _tiedProperties.Tie("debug/orientation-y", this,
245 &FGViewMgr::getCurrentViewOrientation_y);
246 _tiedProperties.Tie("debug/orientation-z", this,
247 &FGViewMgr::getCurrentViewOrientation_z);
249 _tiedProperties.Tie("debug/orientation_offset-w", this,
250 &FGViewMgr::getCurrentViewOrOffset_w);
251 _tiedProperties.Tie("debug/orientation_offset-x", this,
252 &FGViewMgr::getCurrentViewOrOffset_x);
253 _tiedProperties.Tie("debug/orientation_offset-y", this,
254 &FGViewMgr::getCurrentViewOrOffset_y);
255 _tiedProperties.Tie("debug/orientation_offset-z", this,
256 &FGViewMgr::getCurrentViewOrOffset_z);
258 _tiedProperties.Tie("debug/frame-w", this,
259 &FGViewMgr::getCurrentViewFrame_w);
260 _tiedProperties.Tie("debug/frame-x", this,
261 &FGViewMgr::getCurrentViewFrame_x);
262 _tiedProperties.Tie("debug/frame-y", this,
263 &FGViewMgr::getCurrentViewFrame_y);
264 _tiedProperties.Tie("debug/frame-z", this,
265 &FGViewMgr::getCurrentViewFrame_z);
271 _tiedProperties.Untie();
275 FGViewMgr::update (double dt)
277 FGViewer *loop_view = (FGViewer *)get_current_view();
278 if (loop_view == 0) return;
280 SGPropertyNode *n = config_list[current];
281 double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
283 // Set up view location and orientation
285 if (!n->getBoolValue("config/from-model")) {
286 lon_deg = fgGetDouble(n->getStringValue("config/eye-lon-deg-path"));
287 lat_deg = fgGetDouble(n->getStringValue("config/eye-lat-deg-path"));
288 alt_ft = fgGetDouble(n->getStringValue("config/eye-alt-ft-path"));
289 roll_deg = fgGetDouble(n->getStringValue("config/eye-roll-deg-path"));
290 pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path"));
291 heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path"));
293 loop_view->setPosition(lon_deg, lat_deg, alt_ft);
294 loop_view->setOrientation(roll_deg, pitch_deg, heading_deg);
296 // force recalc in viewer
297 loop_view->set_dirty();
300 // if lookat (type 1) then get target data...
301 if (loop_view->getType() == FG_LOOKAT) {
302 if (!n->getBoolValue("config/from-model")) {
303 lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path"));
304 lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path"));
305 alt_ft = fgGetDouble(n->getStringValue("config/target-alt-ft-path"));
306 roll_deg = fgGetDouble(n->getStringValue("config/target-roll-deg-path"));
307 pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path"));
308 heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path"));
310 loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft);
311 loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
313 loop_view->set_dirty();
317 setViewXOffset_m(fgGetDouble("/sim/current-view/x-offset-m"));
318 setViewYOffset_m(fgGetDouble("/sim/current-view/y-offset-m"));
319 setViewZOffset_m(fgGetDouble("/sim/current-view/z-offset-m"));
321 setViewTargetXOffset_m(fgGetDouble("/sim/current-view/target-x-offset-m"));
322 setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m"));
323 setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m"));
325 current_view_orientation = loop_view->getViewOrientation();
326 current_view_or_offset = loop_view->getViewOrientationOffset();
328 // Update the current view
330 loop_view->update(dt);
331 abs_viewer_position = loop_view->getViewPosition();
333 // update audio listener values
334 // set the viewer position in Cartesian coordinates in meters
335 smgr->set_position( abs_viewer_position, loop_view->getPosition() );
336 smgr->set_orientation( current_view_orientation );
338 // get the model velocity
339 SGVec3d velocity = SGVec3d::zeros();
340 if ( !stationary() ) {
341 velocity = globals->get_aircraft_model()->getVelocity();
343 smgr->set_velocity( velocity );
347 FGViewMgr::copyToCurrent()
353 SGPropertyNode *n = config_list[current];
354 fgSetString("/sim/current-view/name", n->getStringValue("name"));
355 fgSetString("/sim/current-view/type", n->getStringValue("type"));
357 // copy certain view config data for default values
358 fgSetDouble("/sim/current-view/config/heading-offset-deg",
359 n->getDoubleValue("config/default-heading-offset-deg"));
360 fgSetDouble("/sim/current-view/config/pitch-offset-deg",
361 n->getDoubleValue("config/pitch-offset-deg"));
362 fgSetDouble("/sim/current-view/config/roll-offset-deg",
363 n->getDoubleValue("config/roll-offset-deg"));
364 fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
365 n->getDoubleValue("config/default-field-of-view-deg"));
366 fgSetBool("/sim/current-view/config/from-model",
367 n->getBoolValue("config/from-model"));
370 fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
371 fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
372 fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
374 fgSetDouble("/sim/current-view/goal-heading-offset-deg",
375 get_current_view()->getGoalHeadingOffset_deg());
376 fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
377 get_current_view()->getGoalPitchOffset_deg());
378 fgSetDouble("/sim/current-view/goal-roll-offset-deg",
379 get_current_view()->getRollOffset_deg());
380 fgSetDouble("/sim/current-view/heading-offset-deg",
381 get_current_view()->getHeadingOffset_deg());
382 fgSetDouble("/sim/current-view/pitch-offset-deg",
383 get_current_view()->getPitchOffset_deg());
384 fgSetDouble("/sim/current-view/roll-offset-deg",
385 get_current_view()->getRollOffset_deg());
386 fgSetDouble("/sim/current-view/target-x-offset-m",
387 get_current_view()->getTargetXOffset_m());
388 fgSetDouble("/sim/current-view/target-y-offset-m",
389 get_current_view()->getTargetYOffset_m());
390 fgSetDouble("/sim/current-view/target-z-offset-m",
391 get_current_view()->getTargetZOffset_m());
392 fgSetBool("/sim/current-view/internal",
393 get_current_view()->getInternal());
396 void FGViewMgr::clear()
402 FGViewMgr::get_current_view()
404 if ( current < (int)views.size() ) {
405 return views[current];
412 FGViewMgr::get_current_view() const
414 if ( current < (int)views.size() ) {
415 return views[current];
423 FGViewMgr::get_view( int i )
425 if ( i < 0 ) { i = 0; }
426 if ( i >= (int)views.size() ) { i = views.size() - 1; }
431 FGViewMgr::get_view( int i ) const
433 if ( i < 0 ) { i = 0; }
434 if ( i >= (int)views.size() ) { i = views.size() - 1; }
439 FGViewMgr::next_view()
441 setView((current+1 < (int)views.size()) ? (current + 1) : 0);
442 view_number->fireValueChanged();
443 return views[current];
447 FGViewMgr::prev_view()
449 setView((0 < current) ? (current - 1) : (views.size() - 1));
450 view_number->fireValueChanged();
451 return views[current];
455 FGViewMgr::add_view( FGViewer * v )
462 FGViewMgr::getViewHeadingOffset_deg () const
464 const FGViewer * view = get_current_view();
465 return (view == 0 ? 0 : view->getHeadingOffset_deg());
469 FGViewMgr::setViewHeadingOffset_deg (double offset)
471 FGViewer * view = get_current_view();
473 view->setGoalHeadingOffset_deg(offset);
474 view->setHeadingOffset_deg(offset);
479 FGViewMgr::getViewGoalHeadingOffset_deg () const
481 const FGViewer * view = get_current_view();
482 return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
486 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
488 FGViewer * view = get_current_view();
490 view->setGoalHeadingOffset_deg(offset);
494 FGViewMgr::getViewPitchOffset_deg () const
496 const FGViewer * view = get_current_view();
497 return (view == 0 ? 0 : view->getPitchOffset_deg());
501 FGViewMgr::setViewPitchOffset_deg (double tilt)
503 FGViewer * view = get_current_view();
505 view->setGoalPitchOffset_deg(tilt);
506 view->setPitchOffset_deg(tilt);
511 FGViewMgr::getGoalViewPitchOffset_deg () const
513 const FGViewer * view = get_current_view();
514 return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
518 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
520 FGViewer * view = get_current_view();
522 view->setGoalPitchOffset_deg(tilt);
526 FGViewMgr::getViewRollOffset_deg () const
528 const FGViewer * view = get_current_view();
529 return (view == 0 ? 0 : view->getRollOffset_deg());
533 FGViewMgr::setViewRollOffset_deg (double tilt)
535 FGViewer * view = get_current_view();
537 view->setGoalRollOffset_deg(tilt);
538 view->setRollOffset_deg(tilt);
543 FGViewMgr::getGoalViewRollOffset_deg () const
545 const FGViewer * view = get_current_view();
546 return (view == 0 ? 0 : view->getGoalRollOffset_deg());
550 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
552 FGViewer * view = get_current_view();
554 view->setGoalRollOffset_deg(tilt);
558 FGViewMgr::getViewXOffset_m () const
560 const FGViewer * view = get_current_view();
562 return ((FGViewer *)view)->getXOffset_m();
569 FGViewMgr::setViewXOffset_m (double x)
571 FGViewer * view = get_current_view();
573 view->setXOffset_m(x);
578 FGViewMgr::getViewYOffset_m () const
580 const FGViewer * view = get_current_view();
582 return ((FGViewer *)view)->getYOffset_m();
589 FGViewMgr::setViewYOffset_m (double y)
591 FGViewer * view = get_current_view();
593 view->setYOffset_m(y);
598 FGViewMgr::getViewZOffset_m () const
600 const FGViewer * view = get_current_view();
602 return ((FGViewer *)view)->getZOffset_m();
609 FGViewMgr::setViewZOffset_m (double z)
611 FGViewer * view = get_current_view();
613 view->setZOffset_m(z);
618 FGViewMgr::stationary () const
620 const FGViewer * view = get_current_view();
622 if (((FGViewer *)view)->getXOffset_m() == 0.0 &&
623 ((FGViewer *)view)->getYOffset_m() == 0.0 &&
624 ((FGViewer *)view)->getZOffset_m() == 0.0)
632 FGViewMgr::getViewTargetXOffset_m () const
634 const FGViewer * view = get_current_view();
636 return ((FGViewer *)view)->getTargetXOffset_m();
643 FGViewMgr::setViewTargetXOffset_m (double x)
645 FGViewer * view = get_current_view();
647 view->setTargetXOffset_m(x);
652 FGViewMgr::getViewTargetYOffset_m () const
654 const FGViewer * view = get_current_view();
656 return ((FGViewer *)view)->getTargetYOffset_m();
663 FGViewMgr::setViewTargetYOffset_m (double y)
665 FGViewer * view = get_current_view();
667 view->setTargetYOffset_m(y);
672 FGViewMgr::getViewTargetZOffset_m () const
674 const FGViewer * view = get_current_view();
676 return ((FGViewer *)view)->getTargetZOffset_m();
683 FGViewMgr::setViewTargetZOffset_m (double z)
685 FGViewer * view = get_current_view();
687 view->setTargetZOffset_m(z);
692 FGViewMgr::getView () const
698 FGViewMgr::setView (int newview)
700 // negative numbers -> set view with node index -newview
702 for (int i = 0; i < (int)config_list.size(); i++) {
703 int index = -config_list[i]->getIndex();
704 if (index == newview)
711 // if newview number too low wrap to last view...
713 newview = (int)views.size() - 1;
715 // if newview number to high wrap to zero...
716 if (newview >= (int)views.size())
727 FGViewMgr::getFOV_deg () const
729 const FGViewer * view = get_current_view();
730 return (view == 0 ? 0 : view->get_fov());
734 FGViewMgr::setFOV_deg (double fov)
736 FGViewer * view = get_current_view();
742 FGViewMgr::getARM_deg () const
744 const FGViewer * view = get_current_view();
745 return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
749 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
751 FGViewer * view = get_current_view();
753 view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
757 FGViewMgr::getNear_m () const
759 const FGViewer * view = get_current_view();
760 return (view == 0 ? 0.5f : view->getNear_m());
764 FGViewMgr::setNear_m (double near_m)
766 FGViewer * view = get_current_view();
768 view->setNear_m(near_m);
772 FGViewMgr::setViewAxisLong (double axis)
778 FGViewMgr::setViewAxisLat (double axis)
783 // reference frame orientation.
784 // This is the view orientation you get when you have no
785 // view offset, i.e. the offset operator is the identity.
787 // For example, in the familiar "cockpit lookfrom" view,
788 // the reference frame is equal to the aircraft attitude,
789 // i.e. it is the view looking towards 12:00 straight ahead.
791 // FIXME: Somebody needs to figure out what is the reference
792 // frame view for the other view modes.
794 // Conceptually, this quat represents a rotation relative
795 // to the ECEF reference orientation, as described at
796 // http://www.av8n.com/physics/coords.htm#sec-orientation
798 // See the NOTE concerning reference orientations, below.
800 // The components of this quat are expressed in
801 // the conventional aviation basis set,
802 // i.e. x=forward, y=starboard, z=bottom
803 double FGViewMgr::getCurrentViewFrame_w() const{
804 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).w();
806 double FGViewMgr::getCurrentViewFrame_x() const{
807 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).x();
809 double FGViewMgr::getCurrentViewFrame_y() const{
810 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).y();
812 double FGViewMgr::getCurrentViewFrame_z() const{
813 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).z();
818 // This rotation takes you from the aforementioned
819 // reference frame view orientation to whatever
820 // actual current view orientation is.
822 // The components of this quaternion are expressed in
823 // the conventional aviation basis set,
824 // i.e. x=forward, y=starboard, z=bottom
825 double FGViewMgr::getCurrentViewOrOffset_w() const{
826 return current_view_or_offset.w();
828 double FGViewMgr::getCurrentViewOrOffset_x() const{
829 return current_view_or_offset.x();
831 double FGViewMgr::getCurrentViewOrOffset_y() const{
832 return current_view_or_offset.y();
834 double FGViewMgr::getCurrentViewOrOffset_z() const{
835 return current_view_or_offset.z();
839 // current view orientation.
840 // This is a rotation relative to the earth-centered (ec)
843 // NOTE: Here we remove a factor of fsb2sta so that
844 // the components of this quat are displayed using the
845 // conventional ECEF basis set. This is *not* the way
846 // the view orientation is stored in the views[] array,
847 // but is easier for non-graphics hackers to understand.
848 // If we did not remove this factor of fsb2sta here and
849 // in getCurrentViewFrame, that would be equivalent to
850 // the following peculiar reference orientation:
851 // Suppose you are over the Gulf of Guinea, at (lat,lon) = (0,0).
852 // Then the reference frame orientation can be achieved via:
853 // -- The aircraft X-axis (nose) headed south.
854 // -- The aircraft Y-axis (starboard wingtip) pointing up.
855 // -- The aircraft Z-axis (belly) pointing west.
856 // To say the same thing in other words, and perhaps more to the
857 // point: If we use the OpenGL camera orientation conventions,
858 // i.e. Xprime=starboard, Yprime=top, Zprime=aft, then the
859 // aforementioned peculiar reference orientation at (lat,lon)
860 // = (0,0) can be described as:
861 // -- aircraft Xprime axis (starboard) pointed up
862 // -- aircraft Yprime axis (top) pointed east
863 // -- aircraft Zprime axis (aft) pointed north
864 // meaning the OpenGL axes are aligned with the ECEF axes.
865 double FGViewMgr::getCurrentViewOrientation_w() const{
866 return (current_view_orientation * conj(fsb2sta())).w();
868 double FGViewMgr::getCurrentViewOrientation_x() const{
869 return (current_view_orientation * conj(fsb2sta())).x();
871 double FGViewMgr::getCurrentViewOrientation_y() const{
872 return (current_view_orientation * conj(fsb2sta())).y();
874 double FGViewMgr::getCurrentViewOrientation_z() const{
875 return (current_view_orientation * conj(fsb2sta())).z();
879 FGViewMgr::do_axes ()
881 // Take no action when hat is centered
882 if ( ( axis_long < 0.01 ) &&
883 ( axis_long > -0.01 ) &&
884 ( axis_lat < 0.01 ) &&
889 double viewDir = 999;
891 /* Do all the quick and easy cases */
892 if (axis_long < 0) { // Longitudinal axis forward
893 if (axis_lat == axis_long)
894 viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
895 else if (axis_lat == - axis_long)
896 viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
897 else if (axis_lat == 0)
898 viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
899 } else if (axis_long > 0) { // Longitudinal axis backward
900 if (axis_lat == - axis_long)
901 viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
902 else if (axis_lat == axis_long)
903 viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
904 else if (axis_lat == 0)
905 viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
906 } else if (axis_long == 0) { // Longitudinal axis neutral
908 viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
909 else if (axis_lat > 0)
910 viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
911 else return; /* And assertion failure maybe? */
914 // Do all the difficult cases
916 viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
917 if ( viewDir < -1 ) viewDir += 360;
919 get_current_view()->setGoalHeadingOffset_deg(viewDir);