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
31 #include <boost/format.hpp>
33 #include <simgear/compiler.h>
34 #include <simgear/sound/soundmgr_openal.hxx>
35 #include <Model/acmodel.hxx>
36 #include <Main/viewer.hxx>
37 #include <Main/fg_props.hxx>
40 FGViewMgr::FGViewMgr( void ) :
43 view_number(fgGetNode("/sim/current-view/view-number", true)),
44 config_list(fgGetNode("/sim", true)->getChildren("view")),
47 smgr = globals->get_soundmgr();
51 FGViewMgr::~FGViewMgr( void ) {
57 double aspect_ratio_multiplier
58 = fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
60 for (unsigned int i = 0; i < config_list.size(); i++) {
61 SGPropertyNode *n = config_list[i];
63 // find out if this is an internal view (e.g. in cockpit, low near plane)
64 bool internal = n->getBoolValue("internal", false);
67 // this is assumed to be an aircraft model...we will need to read
68 // model-from-type as well.
70 // find out if this is a model we are looking from...
71 bool from_model = n->getBoolValue("config/from-model");
72 int from_model_index = n->getIntValue("config/from-model-idx");
74 double x_offset_m = n->getDoubleValue("config/x-offset-m");
75 double y_offset_m = n->getDoubleValue("config/y-offset-m");
76 double z_offset_m = n->getDoubleValue("config/z-offset-m");
78 double heading_offset_deg = n->getDoubleValue("config/heading-offset-deg");
79 n->setDoubleValue("config/heading-offset-deg", heading_offset_deg);
80 double pitch_offset_deg = n->getDoubleValue("config/pitch-offset-deg");
81 n->setDoubleValue("config/pitch-offset-deg", pitch_offset_deg);
82 double roll_offset_deg = n->getDoubleValue("config/roll-offset-deg");
83 n->setDoubleValue("config/roll-offset-deg", roll_offset_deg);
85 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
86 double near_m = n->getDoubleValue("config/ground-level-nearplane-m");
88 // supporting two types "lookat" = 1 and "lookfrom" = 0
89 const char *type = n->getStringValue("type");
90 if (!strcmp(type, "lookat")) {
92 bool at_model = n->getBoolValue("config/at-model");
93 int at_model_index = n->getIntValue("config/at-model-idx");
95 double damp_roll = n->getDoubleValue("config/at-model-roll-damping");
96 double damp_pitch = n->getDoubleValue("config/at-model-pitch-damping");
97 double damp_heading = n->getDoubleValue("config/at-model-heading-damping");
99 double target_x_offset_m = n->getDoubleValue("config/target-x-offset-m");
100 double target_y_offset_m = n->getDoubleValue("config/target-y-offset-m");
101 double target_z_offset_m = n->getDoubleValue("config/target-z-offset-m");
103 add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
104 at_model, at_model_index,
105 damp_roll, damp_pitch, damp_heading,
106 x_offset_m, y_offset_m,z_offset_m,
107 heading_offset_deg, pitch_offset_deg,
108 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
109 target_x_offset_m, target_y_offset_m,
110 target_z_offset_m, near_m, internal ));
112 add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index,
113 false, 0, 0.0, 0.0, 0.0,
114 x_offset_m, y_offset_m, z_offset_m,
115 heading_offset_deg, pitch_offset_deg,
116 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
117 0, 0, 0, near_m, internal ));
127 // reset offsets and fov to configuration defaults
128 for (unsigned int i = 0; i < config_list.size(); i++) {
129 SGPropertyNode *n = config_list[i];
132 fgSetDouble("/sim/current-view/x-offset-m",
133 n->getDoubleValue("config/x-offset-m"));
134 fgSetDouble("/sim/current-view/y-offset-m",
135 n->getDoubleValue("config/y-offset-m"));
136 fgSetDouble("/sim/current-view/z-offset-m",
137 n->getDoubleValue("config/z-offset-m"));
138 fgSetDouble("/sim/current-view/pitch-offset-deg",
139 n->getDoubleValue("config/pitch-offset-deg"));
140 fgSetDouble("/sim/current-view/heading-offset-deg",
141 n->getDoubleValue("config/heading-offset-deg"));
142 fgSetDouble("/sim/current-view/roll-offset-deg",
143 n->getDoubleValue("config/roll-offset-deg"));
145 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
148 fgSetDouble("/sim/current-view/field-of-view", fov_deg);
150 // target offsets for lookat mode only...
151 fgSetDouble("/sim/current-view/target-x-offset-m",
152 n->getDoubleValue("config/target-x-offset-m"));
153 fgSetDouble("/sim/current-view/target-y-offset-m",
154 n->getDoubleValue("config/target-y-offset-m"));
155 fgSetDouble("/sim/current-view/target-z-offset-m",
156 n->getDoubleValue("config/target-z-offset-m"));
161 typedef double (FGViewMgr::*double_getter)() const;
166 // for automatic untying:
167 #define x(str) ((void)tied_props.push_back(str), str)
169 // these are bound to the current view properties
170 fgTie("/sim/current-view/heading-offset-deg", this,
171 &FGViewMgr::getViewHeadingOffset_deg,
172 &FGViewMgr::setViewHeadingOffset_deg);
173 fgSetArchivable("/sim/current-view/heading-offset-deg");
174 fgTie("/sim/current-view/goal-heading-offset-deg", this,
175 &FGViewMgr::getViewGoalHeadingOffset_deg,
176 &FGViewMgr::setViewGoalHeadingOffset_deg);
177 fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
178 fgTie("/sim/current-view/pitch-offset-deg", this,
179 &FGViewMgr::getViewPitchOffset_deg,
180 &FGViewMgr::setViewPitchOffset_deg);
181 fgSetArchivable("/sim/current-view/pitch-offset-deg");
182 fgTie("/sim/current-view/goal-pitch-offset-deg", this,
183 &FGViewMgr::getGoalViewPitchOffset_deg,
184 &FGViewMgr::setGoalViewPitchOffset_deg);
185 fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
186 fgTie("/sim/current-view/roll-offset-deg", this,
187 &FGViewMgr::getViewRollOffset_deg,
188 &FGViewMgr::setViewRollOffset_deg);
189 fgSetArchivable("/sim/current-view/roll-offset-deg");
190 fgTie("/sim/current-view/goal-roll-offset-deg", this,
191 &FGViewMgr::getGoalViewRollOffset_deg,
192 &FGViewMgr::setGoalViewRollOffset_deg);
193 fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
195 fgTie("/sim/current-view/view-number", this,
196 &FGViewMgr::getView, &FGViewMgr::setView);
197 fgSetArchivable("/sim/current-view/view-number", FALSE);
199 fgTie("/sim/current-view/axes/long", this,
200 (double_getter)0, &FGViewMgr::setViewAxisLong);
201 fgSetArchivable("/sim/current-view/axes/long");
203 fgTie("/sim/current-view/axes/lat", this,
204 (double_getter)0, &FGViewMgr::setViewAxisLat);
205 fgSetArchivable("/sim/current-view/axes/lat");
207 fgTie("/sim/current-view/field-of-view", this,
208 &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
209 fgSetArchivable("/sim/current-view/field-of-view");
211 fgTie("/sim/current-view/aspect-ratio-multiplier", this,
212 &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
213 fgSetArchivable("/sim/current-view/field-of-view");
215 fgTie("/sim/current-view/ground-level-nearplane-m", this,
216 &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
217 fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
219 fgTie(x("/sim/current-view/view_orientation"), this,
220 &FGViewMgr::getCurrentViewOrientation);
221 fgTie(x("/sim/current-view/view_or_offset"), this,
222 &FGViewMgr::getCurrentViewOrOffset);
224 fgTie(x("/sim/current-view/view_frame"), this,
225 &FGViewMgr::getCurrentViewFrame);
227 SGPropertyNode *n = fgGetNode("/sim/current-view", true);
228 n->tie("viewer-x-m", SGRawValuePointer<double>(&abs_viewer_position[0]));
229 n->tie("viewer-y-m", SGRawValuePointer<double>(&abs_viewer_position[1]));
230 n->tie("viewer-z-m", SGRawValuePointer<double>(&abs_viewer_position[2]));
239 // need to redo these bindings to the new locations (move to viewer?)
240 fgUntie("/sim/current-view/heading-offset-deg");
241 fgUntie("/sim/current-view/goal-heading-offset-deg");
242 fgUntie("/sim/current-view/pitch-offset-deg");
243 fgUntie("/sim/current-view/goal-pitch-offset-deg");
244 fgUntie("/sim/current-view/field-of-view");
245 fgUntie("/sim/current-view/aspect-ratio-multiplier");
246 fgUntie("/sim/current-view/view-number");
247 fgUntie("/sim/current-view/axes/long");
248 fgUntie("/sim/current-view/axes/lat");
249 fgUntie("/sim/current-view/ground-level-nearplane-m");
250 fgUntie("/sim/current-view/viewer-x-m");
251 fgUntie("/sim/current-view/viewer-y-m");
252 fgUntie("/sim/current-view/viewer-z-m");
254 list<const char*>::const_iterator it;
255 for (it = tied_props.begin(); it != tied_props.end(); it++){
262 FGViewMgr::update (double dt)
265 FGViewer *loop_view = (FGViewer *)get_current_view();
266 if (loop_view == 0) return;
268 SGPropertyNode *n = config_list[current];
269 double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
271 // Set up view location and orientation
273 if (!n->getBoolValue("config/from-model")) {
274 lon_deg = fgGetDouble(n->getStringValue("config/eye-lon-deg-path"));
275 lat_deg = fgGetDouble(n->getStringValue("config/eye-lat-deg-path"));
276 alt_ft = fgGetDouble(n->getStringValue("config/eye-alt-ft-path"));
277 roll_deg = fgGetDouble(n->getStringValue("config/eye-roll-deg-path"));
278 pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path"));
279 heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path"));
281 loop_view->setPosition(lon_deg, lat_deg, alt_ft);
282 loop_view->setOrientation(roll_deg, pitch_deg, heading_deg);
284 // force recalc in viewer
285 loop_view->set_dirty();
288 // if lookat (type 1) then get target data...
289 if (loop_view->getType() == FG_LOOKAT) {
290 if (!n->getBoolValue("config/from-model")) {
291 lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path"));
292 lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path"));
293 alt_ft = fgGetDouble(n->getStringValue("config/target-alt-ft-path"));
294 roll_deg = fgGetDouble(n->getStringValue("config/target-roll-deg-path"));
295 pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path"));
296 heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path"));
298 loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft);
299 loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
301 loop_view->set_dirty();
305 setViewXOffset_m(fgGetDouble("/sim/current-view/x-offset-m"));
306 setViewYOffset_m(fgGetDouble("/sim/current-view/y-offset-m"));
307 setViewZOffset_m(fgGetDouble("/sim/current-view/z-offset-m"));
309 setViewTargetXOffset_m(fgGetDouble("/sim/current-view/target-x-offset-m"));
310 setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m"));
311 setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m"));
313 current_view_orientation = loop_view->getViewOrientation();
314 current_view_or_offset = loop_view->getViewOrientationOffset();
316 // Update the current view
318 loop_view->update(dt);
319 abs_viewer_position = loop_view->getViewPosition();
321 // update audio listener values
322 // set the viewer posotion in Cartesian coordinates in meters
323 smgr->set_position( abs_viewer_position );
324 smgr->set_orientation( current_view_orientation );
326 // get the model velocity
327 SGVec3f velocity = SGVec3f::zeros();
328 if ( !stationary() ) {
329 velocity = globals->get_aircraft_model()->getVelocity();
331 smgr->set_velocity(velocity);
335 FGViewMgr::copyToCurrent()
337 SGPropertyNode *n = config_list[current];
338 fgSetString("/sim/current-view/name", n->getStringValue("name"));
339 fgSetString("/sim/current-view/type", n->getStringValue("type"));
341 // copy certain view config data for default values
342 fgSetDouble("/sim/current-view/config/heading-offset-deg",
343 n->getDoubleValue("config/default-heading-offset-deg"));
344 fgSetDouble("/sim/current-view/config/pitch-offset-deg",
345 n->getDoubleValue("config/pitch-offset-deg"));
346 fgSetDouble("/sim/current-view/config/roll-offset-deg",
347 n->getDoubleValue("config/roll-offset-deg"));
348 fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
349 n->getDoubleValue("config/default-field-of-view-deg"));
350 fgSetBool("/sim/current-view/config/from-model",
351 n->getBoolValue("config/from-model"));
354 fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
355 fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
356 fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
358 fgSetDouble("/sim/current-view/goal-heading-offset-deg",
359 get_current_view()->getGoalHeadingOffset_deg());
360 fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
361 get_current_view()->getGoalPitchOffset_deg());
362 fgSetDouble("/sim/current-view/goal-roll-offset-deg",
363 get_current_view()->getRollOffset_deg());
364 fgSetDouble("/sim/current-view/heading-offset-deg",
365 get_current_view()->getHeadingOffset_deg());
366 fgSetDouble("/sim/current-view/pitch-offset-deg",
367 get_current_view()->getPitchOffset_deg());
368 fgSetDouble("/sim/current-view/roll-offset-deg",
369 get_current_view()->getRollOffset_deg());
370 fgSetDouble("/sim/current-view/target-x-offset-m",
371 get_current_view()->getTargetXOffset_m());
372 fgSetDouble("/sim/current-view/target-y-offset-m",
373 get_current_view()->getTargetYOffset_m());
374 fgSetDouble("/sim/current-view/target-z-offset-m",
375 get_current_view()->getTargetZOffset_m());
376 fgSetBool("/sim/current-view/internal",
377 get_current_view()->getInternal());
380 void FGViewMgr::clear()
386 FGViewMgr::get_current_view()
388 if ( current < (int)views.size() ) {
389 return views[current];
396 FGViewMgr::get_current_view() const
398 if ( current < (int)views.size() ) {
399 return views[current];
407 FGViewMgr::get_view( int i )
409 if ( i < 0 ) { i = 0; }
410 if ( i >= (int)views.size() ) { i = views.size() - 1; }
415 FGViewMgr::get_view( int i ) const
417 if ( i < 0 ) { i = 0; }
418 if ( i >= (int)views.size() ) { i = views.size() - 1; }
423 FGViewMgr::next_view()
425 setView((current+1 < (int)views.size()) ? (current + 1) : 0);
426 view_number->fireValueChanged();
427 return views[current];
431 FGViewMgr::prev_view()
433 setView((0 < current) ? (current - 1) : (views.size() - 1));
434 view_number->fireValueChanged();
435 return views[current];
439 FGViewMgr::add_view( FGViewer * v )
446 FGViewMgr::getViewHeadingOffset_deg () const
448 const FGViewer * view = get_current_view();
449 return (view == 0 ? 0 : view->getHeadingOffset_deg());
453 FGViewMgr::setViewHeadingOffset_deg (double offset)
455 FGViewer * view = get_current_view();
457 view->setGoalHeadingOffset_deg(offset);
458 view->setHeadingOffset_deg(offset);
463 FGViewMgr::getViewGoalHeadingOffset_deg () const
465 const FGViewer * view = get_current_view();
466 return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
470 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
472 FGViewer * view = get_current_view();
474 view->setGoalHeadingOffset_deg(offset);
478 FGViewMgr::getViewPitchOffset_deg () const
480 const FGViewer * view = get_current_view();
481 return (view == 0 ? 0 : view->getPitchOffset_deg());
485 FGViewMgr::setViewPitchOffset_deg (double tilt)
487 FGViewer * view = get_current_view();
489 view->setGoalPitchOffset_deg(tilt);
490 view->setPitchOffset_deg(tilt);
495 FGViewMgr::getGoalViewPitchOffset_deg () const
497 const FGViewer * view = get_current_view();
498 return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
502 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
504 FGViewer * view = get_current_view();
506 view->setGoalPitchOffset_deg(tilt);
510 FGViewMgr::getViewRollOffset_deg () const
512 const FGViewer * view = get_current_view();
513 return (view == 0 ? 0 : view->getRollOffset_deg());
517 FGViewMgr::setViewRollOffset_deg (double tilt)
519 FGViewer * view = get_current_view();
521 view->setGoalRollOffset_deg(tilt);
522 view->setRollOffset_deg(tilt);
527 FGViewMgr::getGoalViewRollOffset_deg () const
529 const FGViewer * view = get_current_view();
530 return (view == 0 ? 0 : view->getGoalRollOffset_deg());
534 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
536 FGViewer * view = get_current_view();
538 view->setGoalRollOffset_deg(tilt);
542 FGViewMgr::getViewXOffset_m () const
544 const FGViewer * view = get_current_view();
546 return ((FGViewer *)view)->getXOffset_m();
553 FGViewMgr::setViewXOffset_m (double x)
555 FGViewer * view = get_current_view();
557 view->setXOffset_m(x);
562 FGViewMgr::getViewYOffset_m () const
564 const FGViewer * view = get_current_view();
566 return ((FGViewer *)view)->getYOffset_m();
573 FGViewMgr::setViewYOffset_m (double y)
575 FGViewer * view = get_current_view();
577 view->setYOffset_m(y);
582 FGViewMgr::getViewZOffset_m () const
584 const FGViewer * view = get_current_view();
586 return ((FGViewer *)view)->getZOffset_m();
593 FGViewMgr::setViewZOffset_m (double z)
595 FGViewer * view = get_current_view();
597 view->setZOffset_m(z);
602 FGViewMgr::stationary () const
604 const FGViewer * view = get_current_view();
606 if (((FGViewer *)view)->getXOffset_m() == 0.0 &&
607 ((FGViewer *)view)->getYOffset_m() == 0.0 &&
608 ((FGViewer *)view)->getZOffset_m() == 0.0)
616 FGViewMgr::getViewTargetXOffset_m () const
618 const FGViewer * view = get_current_view();
620 return ((FGViewer *)view)->getTargetXOffset_m();
627 FGViewMgr::setViewTargetXOffset_m (double x)
629 FGViewer * view = get_current_view();
631 view->setTargetXOffset_m(x);
636 FGViewMgr::getViewTargetYOffset_m () const
638 const FGViewer * view = get_current_view();
640 return ((FGViewer *)view)->getTargetYOffset_m();
647 FGViewMgr::setViewTargetYOffset_m (double y)
649 FGViewer * view = get_current_view();
651 view->setTargetYOffset_m(y);
656 FGViewMgr::getViewTargetZOffset_m () const
658 const FGViewer * view = get_current_view();
660 return ((FGViewer *)view)->getTargetZOffset_m();
667 FGViewMgr::setViewTargetZOffset_m (double z)
669 FGViewer * view = get_current_view();
671 view->setTargetZOffset_m(z);
676 FGViewMgr::getView () const
682 FGViewMgr::setView (int newview)
684 // negative numbers -> set view with node index -newview
686 for (int i = 0; i < (int)config_list.size(); i++) {
687 int index = -config_list[i]->getIndex();
688 if (index == newview)
695 // if newview number too low wrap to last view...
697 newview = (int)views.size() - 1;
699 // if newview number to high wrap to zero...
700 if (newview >= (int)views.size())
708 // Copy the fdm's position into the SGLocation which is shared with
710 globals->get_aircraft_model()->update(0);
717 FGViewMgr::getFOV_deg () const
719 const FGViewer * view = get_current_view();
720 return (view == 0 ? 0 : view->get_fov());
724 FGViewMgr::setFOV_deg (double fov)
726 FGViewer * view = get_current_view();
732 FGViewMgr::getARM_deg () const
734 const FGViewer * view = get_current_view();
735 return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
739 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
741 FGViewer * view = get_current_view();
743 view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
747 FGViewMgr::getNear_m () const
749 const FGViewer * view = get_current_view();
750 return (view == 0 ? 0.5f : view->getNear_m());
754 FGViewMgr::setNear_m (double near_m)
756 FGViewer * view = get_current_view();
758 view->setNear_m(near_m);
762 FGViewMgr::setViewAxisLong (double axis)
768 FGViewMgr::setViewAxisLat (double axis)
773 // Convert a quat to a string.
774 // We assume the quat is being used as a rotor, so we
775 // coerce it to standard rotor form, making the scalar
776 // part non-negative, to eliminate double coverage of
777 // the rotation group.
778 // The format is "w ; x y z" with a semicolon separating
779 // the scalar part from the bivector components.
780 const char* format_rotor(const SGQuatd _quat){
782 if (quat.w() < 0.) quat *= -1.; // remove double coverage
783 return str(boost::format("%6.3f ; %6.3f %6.3f %6.3f")
787 % quat.z() ).c_str();
790 // reference frame orientation.
791 // This is the view orientation you get when you have no
792 // view offset, i.e. the offset operator is the identity.
794 // For example, in the familiar "cockpit lookfrom" view,
795 // the reference frame is equal to the aircraft attitude,
796 // i.e. it is the view looking towards 12:00 straight ahead.
798 // FIXME: Somebody needs to figure out what is the reference
799 // frame view for the other view modes.
801 // Conceptually, this quat represents a rotation relative
802 // to the ECEF reference orientation, as described at
803 // http://www.av8n.com/physics/coords.htm#sec-orientation
805 // See the NOTE concerning reference orientations, below.
807 // The components of this quat are expressed in
808 // the conventional aviation basis set,
809 // i.e. x=forward, y=starboard, z=bottom
810 const char* FGViewMgr::getCurrentViewFrame() const{
811 return format_rotor(current_view_orientation * conj(fsb2sta())
812 * conj(current_view_or_offset) );
816 // This rotation takes you from the aforementioned
817 // reference frame view orientation to whatever
818 // actual current view orientation is.
820 // The components of this quaternion are expressed in
821 // the conventional aviation basis set,
822 // i.e. x=forward, y=starboard, z=bottom
823 const char* FGViewMgr::getCurrentViewOrOffset() const{
824 return format_rotor(current_view_or_offset);
827 // current view orientation.
828 // This is a rotation relative to the earth-centered (ec)
831 // NOTE: Here we remove a factor of fsb2sta so that
832 // the components of this quat are displayed using the
833 // conventional ECEF basis set. This is *not* the way
834 // the view orientation is stored in the views[] array,
835 // but is easier for non-graphics hackers to understand.
836 // If we did not remove this factor of fsb2sta here and
837 // in getCurrentViewFrame, that would be equivalent to
838 // the following peculiar reference orientation:
839 // Suppose you are over the Gulf of Guinea, at (lat,lon) = (0,0).
840 // Then the reference frame orientation can be achieved via:
841 // -- The aircraft X-axis (nose) headed south.
842 // -- The aircraft Y-axis (starboard wingtip) pointing up.
843 // -- The aircraft Z-axis (belly) pointing west.
844 // To say the same thing in other words, and perhaps more to the
845 // point: If we use the OpenGL camera orientation conventions,
846 // i.e. Xprime=starboard, Yprime=top, Zprime=aft, then the
847 // aforementioned peculiar reference orientation at (lat,lon)
848 // = (0,0) can be described as:
849 // -- aircraft Xprime axis (starboard) pointed up
850 // -- aircraft Yprime axis (top) pointed east
851 // -- aircraft Zprime axis (aft) pointed north
852 // meaning the OpenGL axes are aligned with the ECEF axes.
853 const char* FGViewMgr::getCurrentViewOrientation() const{
854 return format_rotor(current_view_orientation * conj(fsb2sta()));
858 FGViewMgr::do_axes ()
860 // Take no action when hat is centered
861 if ( ( axis_long < 0.01 ) &&
862 ( axis_long > -0.01 ) &&
863 ( axis_lat < 0.01 ) &&
868 double viewDir = 999;
870 /* Do all the quick and easy cases */
871 if (axis_long < 0) { // Longitudinal axis forward
872 if (axis_lat == axis_long)
873 viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
874 else if (axis_lat == - axis_long)
875 viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
876 else if (axis_lat == 0)
877 viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
878 } else if (axis_long > 0) { // Longitudinal axis backward
879 if (axis_lat == - axis_long)
880 viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
881 else if (axis_lat == axis_long)
882 viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
883 else if (axis_lat == 0)
884 viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
885 } else if (axis_long == 0) { // Longitudinal axis neutral
887 viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
888 else if (axis_lat > 0)
889 viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
890 else return; /* And assertion failure maybe? */
893 // Do all the difficult cases
895 viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
896 if ( viewDir < -1 ) viewDir += 360;
898 get_current_view()->setGoalHeadingOffset_deg(viewDir);