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/viewer.hxx>
36 #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")),
47 smgr = globals->get_soundmgr();
51 FGViewMgr::~FGViewMgr( void ) {
58 SG_LOG(SG_GENERAL, SG_WARN, "duplicate init of view manager");
64 double aspect_ratio_multiplier
65 = fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
67 for (unsigned int i = 0; i < config_list.size(); i++) {
68 SGPropertyNode *n = config_list[i];
70 // find out if this is an internal view (e.g. in cockpit, low near plane)
71 bool internal = n->getBoolValue("internal", false);
74 // this is assumed to be an aircraft model...we will need to read
75 // model-from-type as well.
77 // find out if this is a model we are looking from...
78 bool from_model = n->getBoolValue("config/from-model");
79 int from_model_index = n->getIntValue("config/from-model-idx");
81 double x_offset_m = n->getDoubleValue("config/x-offset-m");
82 double y_offset_m = n->getDoubleValue("config/y-offset-m");
83 double z_offset_m = n->getDoubleValue("config/z-offset-m");
85 double heading_offset_deg = n->getDoubleValue("config/heading-offset-deg");
86 n->setDoubleValue("config/heading-offset-deg", heading_offset_deg);
87 double pitch_offset_deg = n->getDoubleValue("config/pitch-offset-deg");
88 n->setDoubleValue("config/pitch-offset-deg", pitch_offset_deg);
89 double roll_offset_deg = n->getDoubleValue("config/roll-offset-deg");
90 n->setDoubleValue("config/roll-offset-deg", roll_offset_deg);
92 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
93 double near_m = n->getDoubleValue("config/ground-level-nearplane-m");
95 // supporting two types "lookat" = 1 and "lookfrom" = 0
96 const char *type = n->getStringValue("type");
97 if (!strcmp(type, "lookat")) {
99 bool at_model = n->getBoolValue("config/at-model");
100 int at_model_index = n->getIntValue("config/at-model-idx");
102 double damp_roll = n->getDoubleValue("config/at-model-roll-damping");
103 double damp_pitch = n->getDoubleValue("config/at-model-pitch-damping");
104 double damp_heading = n->getDoubleValue("config/at-model-heading-damping");
106 double target_x_offset_m = n->getDoubleValue("config/target-x-offset-m");
107 double target_y_offset_m = n->getDoubleValue("config/target-y-offset-m");
108 double target_z_offset_m = n->getDoubleValue("config/target-z-offset-m");
110 add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
111 at_model, at_model_index,
112 damp_roll, damp_pitch, damp_heading,
113 x_offset_m, y_offset_m,z_offset_m,
114 heading_offset_deg, pitch_offset_deg,
115 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
116 target_x_offset_m, target_y_offset_m,
117 target_z_offset_m, near_m, internal ));
119 add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index,
120 false, 0, 0.0, 0.0, 0.0,
121 x_offset_m, y_offset_m, z_offset_m,
122 heading_offset_deg, pitch_offset_deg,
123 roll_offset_deg, fov_deg, aspect_ratio_multiplier,
124 0, 0, 0, near_m, internal ));
135 // reset offsets and fov to configuration defaults
136 for (unsigned int i = 0; i < config_list.size(); i++) {
137 SGPropertyNode *n = config_list[i];
140 fgSetDouble("/sim/current-view/x-offset-m",
141 n->getDoubleValue("config/x-offset-m"));
142 fgSetDouble("/sim/current-view/y-offset-m",
143 n->getDoubleValue("config/y-offset-m"));
144 fgSetDouble("/sim/current-view/z-offset-m",
145 n->getDoubleValue("config/z-offset-m"));
146 fgSetDouble("/sim/current-view/pitch-offset-deg",
147 n->getDoubleValue("config/pitch-offset-deg"));
148 fgSetDouble("/sim/current-view/heading-offset-deg",
149 n->getDoubleValue("config/heading-offset-deg"));
150 fgSetDouble("/sim/current-view/roll-offset-deg",
151 n->getDoubleValue("config/roll-offset-deg"));
153 double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
156 fgSetDouble("/sim/current-view/field-of-view", fov_deg);
158 // target offsets for lookat mode only...
159 fgSetDouble("/sim/current-view/target-x-offset-m",
160 n->getDoubleValue("config/target-x-offset-m"));
161 fgSetDouble("/sim/current-view/target-y-offset-m",
162 n->getDoubleValue("config/target-y-offset-m"));
163 fgSetDouble("/sim/current-view/target-z-offset-m",
164 n->getDoubleValue("config/target-z-offset-m"));
169 typedef double (FGViewMgr::*double_getter)() const;
174 // view-manager code was designed to init before bind, so
175 // this is a no-op; init() calls the real bind() impl below
181 // these are bound to the current view properties
182 fgTie("/sim/current-view/heading-offset-deg", this,
183 &FGViewMgr::getViewHeadingOffset_deg,
184 &FGViewMgr::setViewHeadingOffset_deg);
185 fgSetArchivable("/sim/current-view/heading-offset-deg");
186 fgTie("/sim/current-view/goal-heading-offset-deg", this,
187 &FGViewMgr::getViewGoalHeadingOffset_deg,
188 &FGViewMgr::setViewGoalHeadingOffset_deg);
189 fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
190 fgTie("/sim/current-view/pitch-offset-deg", this,
191 &FGViewMgr::getViewPitchOffset_deg,
192 &FGViewMgr::setViewPitchOffset_deg);
193 fgSetArchivable("/sim/current-view/pitch-offset-deg");
194 fgTie("/sim/current-view/goal-pitch-offset-deg", this,
195 &FGViewMgr::getGoalViewPitchOffset_deg,
196 &FGViewMgr::setGoalViewPitchOffset_deg);
197 fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
198 fgTie("/sim/current-view/roll-offset-deg", this,
199 &FGViewMgr::getViewRollOffset_deg,
200 &FGViewMgr::setViewRollOffset_deg);
201 fgSetArchivable("/sim/current-view/roll-offset-deg");
202 fgTie("/sim/current-view/goal-roll-offset-deg", this,
203 &FGViewMgr::getGoalViewRollOffset_deg,
204 &FGViewMgr::setGoalViewRollOffset_deg);
205 fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
207 fgTie("/sim/current-view/view-number", this,
208 &FGViewMgr::getView, &FGViewMgr::setView);
209 fgSetArchivable("/sim/current-view/view-number", false);
211 fgTie("/sim/current-view/axes/long", this,
212 (double_getter)0, &FGViewMgr::setViewAxisLong);
213 fgSetArchivable("/sim/current-view/axes/long");
215 fgTie("/sim/current-view/axes/lat", this,
216 (double_getter)0, &FGViewMgr::setViewAxisLat);
217 fgSetArchivable("/sim/current-view/axes/lat");
219 fgTie("/sim/current-view/field-of-view", this,
220 &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
221 fgSetArchivable("/sim/current-view/field-of-view");
223 fgTie("/sim/current-view/aspect-ratio-multiplier", this,
224 &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
225 fgSetArchivable("/sim/current-view/field-of-view");
227 fgTie("/sim/current-view/ground-level-nearplane-m", this,
228 &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
229 fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
231 SGPropertyNode *n = fgGetNode("/sim/current-view", true);
232 n->tie("viewer-x-m", SGRawValuePointer<double>(&abs_viewer_position[0]));
233 n->tie("viewer-y-m", SGRawValuePointer<double>(&abs_viewer_position[1]));
234 n->tie("viewer-z-m", SGRawValuePointer<double>(&abs_viewer_position[2]));
236 // for automatic untying:
237 #define x(str) ((void)tied_props.push_back(str), str)
239 fgTie(x("/sim/current-view/debug/orientation-w"), this,
240 &FGViewMgr::getCurrentViewOrientation_w);
241 fgTie(x("/sim/current-view/debug/orientation-x"), this,
242 &FGViewMgr::getCurrentViewOrientation_x);
243 fgTie(x("/sim/current-view/debug/orientation-y"), this,
244 &FGViewMgr::getCurrentViewOrientation_y);
245 fgTie(x("/sim/current-view/debug/orientation-z"), this,
246 &FGViewMgr::getCurrentViewOrientation_z);
248 fgTie(x("/sim/current-view/debug/orientation_offset-w"), this,
249 &FGViewMgr::getCurrentViewOrOffset_w);
250 fgTie(x("/sim/current-view/debug/orientation_offset-x"), this,
251 &FGViewMgr::getCurrentViewOrOffset_x);
252 fgTie(x("/sim/current-view/debug/orientation_offset-y"), this,
253 &FGViewMgr::getCurrentViewOrOffset_y);
254 fgTie(x("/sim/current-view/debug/orientation_offset-z"), this,
255 &FGViewMgr::getCurrentViewOrOffset_z);
257 fgTie(x("/sim/current-view/debug/frame-w"), this,
258 &FGViewMgr::getCurrentViewFrame_w);
259 fgTie(x("/sim/current-view/debug/frame-x"), this,
260 &FGViewMgr::getCurrentViewFrame_x);
261 fgTie(x("/sim/current-view/debug/frame-y"), this,
262 &FGViewMgr::getCurrentViewFrame_y);
263 fgTie(x("/sim/current-view/debug/frame-z"), this,
264 &FGViewMgr::getCurrentViewFrame_z);
273 // need to redo these bindings to the new locations (move to viewer?)
274 fgUntie("/sim/current-view/heading-offset-deg");
275 fgUntie("/sim/current-view/goal-heading-offset-deg");
276 fgUntie("/sim/current-view/pitch-offset-deg");
277 fgUntie("/sim/current-view/goal-pitch-offset-deg");
278 fgUntie("/sim/current-view/field-of-view");
279 fgUntie("/sim/current-view/aspect-ratio-multiplier");
280 fgUntie("/sim/current-view/view-number");
281 fgUntie("/sim/current-view/axes/long");
282 fgUntie("/sim/current-view/axes/lat");
283 fgUntie("/sim/current-view/ground-level-nearplane-m");
284 fgUntie("/sim/current-view/viewer-x-m");
285 fgUntie("/sim/current-view/viewer-y-m");
286 fgUntie("/sim/current-view/viewer-z-m");
288 list<const char*>::const_iterator it;
289 for (it = tied_props.begin(); it != tied_props.end(); it++){
296 FGViewMgr::update (double dt)
299 FGViewer *loop_view = (FGViewer *)get_current_view();
300 if (loop_view == 0) return;
302 SGPropertyNode *n = config_list[current];
303 double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
305 // Set up view location and orientation
307 if (!n->getBoolValue("config/from-model")) {
308 lon_deg = fgGetDouble(n->getStringValue("config/eye-lon-deg-path"));
309 lat_deg = fgGetDouble(n->getStringValue("config/eye-lat-deg-path"));
310 alt_ft = fgGetDouble(n->getStringValue("config/eye-alt-ft-path"));
311 roll_deg = fgGetDouble(n->getStringValue("config/eye-roll-deg-path"));
312 pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path"));
313 heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path"));
315 loop_view->setPosition(lon_deg, lat_deg, alt_ft);
316 loop_view->setOrientation(roll_deg, pitch_deg, heading_deg);
318 // force recalc in viewer
319 loop_view->set_dirty();
322 // if lookat (type 1) then get target data...
323 if (loop_view->getType() == FG_LOOKAT) {
324 if (!n->getBoolValue("config/from-model")) {
325 lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path"));
326 lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path"));
327 alt_ft = fgGetDouble(n->getStringValue("config/target-alt-ft-path"));
328 roll_deg = fgGetDouble(n->getStringValue("config/target-roll-deg-path"));
329 pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path"));
330 heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path"));
332 loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft);
333 loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
335 loop_view->set_dirty();
339 setViewXOffset_m(fgGetDouble("/sim/current-view/x-offset-m"));
340 setViewYOffset_m(fgGetDouble("/sim/current-view/y-offset-m"));
341 setViewZOffset_m(fgGetDouble("/sim/current-view/z-offset-m"));
343 setViewTargetXOffset_m(fgGetDouble("/sim/current-view/target-x-offset-m"));
344 setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m"));
345 setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m"));
347 current_view_orientation = loop_view->getViewOrientation();
348 current_view_or_offset = loop_view->getViewOrientationOffset();
350 // Update the current view
352 loop_view->update(dt);
353 abs_viewer_position = loop_view->getViewPosition();
355 // update audio listener values
356 // set the viewer posotion in Cartesian coordinates in meters
357 smgr->set_position( abs_viewer_position, loop_view->getPosition() );
358 smgr->set_orientation( current_view_orientation );
360 // get the model velocity
361 SGVec3d velocity = SGVec3d::zeros();
362 if ( !stationary() ) {
363 velocity = globals->get_aircraft_model()->getVelocity();
365 smgr->set_velocity( velocity );
369 FGViewMgr::copyToCurrent()
375 SGPropertyNode *n = config_list[current];
376 fgSetString("/sim/current-view/name", n->getStringValue("name"));
377 fgSetString("/sim/current-view/type", n->getStringValue("type"));
379 // copy certain view config data for default values
380 fgSetDouble("/sim/current-view/config/heading-offset-deg",
381 n->getDoubleValue("config/default-heading-offset-deg"));
382 fgSetDouble("/sim/current-view/config/pitch-offset-deg",
383 n->getDoubleValue("config/pitch-offset-deg"));
384 fgSetDouble("/sim/current-view/config/roll-offset-deg",
385 n->getDoubleValue("config/roll-offset-deg"));
386 fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
387 n->getDoubleValue("config/default-field-of-view-deg"));
388 fgSetBool("/sim/current-view/config/from-model",
389 n->getBoolValue("config/from-model"));
392 fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
393 fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
394 fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
396 fgSetDouble("/sim/current-view/goal-heading-offset-deg",
397 get_current_view()->getGoalHeadingOffset_deg());
398 fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
399 get_current_view()->getGoalPitchOffset_deg());
400 fgSetDouble("/sim/current-view/goal-roll-offset-deg",
401 get_current_view()->getRollOffset_deg());
402 fgSetDouble("/sim/current-view/heading-offset-deg",
403 get_current_view()->getHeadingOffset_deg());
404 fgSetDouble("/sim/current-view/pitch-offset-deg",
405 get_current_view()->getPitchOffset_deg());
406 fgSetDouble("/sim/current-view/roll-offset-deg",
407 get_current_view()->getRollOffset_deg());
408 fgSetDouble("/sim/current-view/target-x-offset-m",
409 get_current_view()->getTargetXOffset_m());
410 fgSetDouble("/sim/current-view/target-y-offset-m",
411 get_current_view()->getTargetYOffset_m());
412 fgSetDouble("/sim/current-view/target-z-offset-m",
413 get_current_view()->getTargetZOffset_m());
414 fgSetBool("/sim/current-view/internal",
415 get_current_view()->getInternal());
418 void FGViewMgr::clear()
424 FGViewMgr::get_current_view()
426 if ( current < (int)views.size() ) {
427 return views[current];
434 FGViewMgr::get_current_view() const
436 if ( current < (int)views.size() ) {
437 return views[current];
445 FGViewMgr::get_view( int i )
447 if ( i < 0 ) { i = 0; }
448 if ( i >= (int)views.size() ) { i = views.size() - 1; }
453 FGViewMgr::get_view( int i ) const
455 if ( i < 0 ) { i = 0; }
456 if ( i >= (int)views.size() ) { i = views.size() - 1; }
461 FGViewMgr::next_view()
463 setView((current+1 < (int)views.size()) ? (current + 1) : 0);
464 view_number->fireValueChanged();
465 return views[current];
469 FGViewMgr::prev_view()
471 setView((0 < current) ? (current - 1) : (views.size() - 1));
472 view_number->fireValueChanged();
473 return views[current];
477 FGViewMgr::add_view( FGViewer * v )
484 FGViewMgr::getViewHeadingOffset_deg () const
486 const FGViewer * view = get_current_view();
487 return (view == 0 ? 0 : view->getHeadingOffset_deg());
491 FGViewMgr::setViewHeadingOffset_deg (double offset)
493 FGViewer * view = get_current_view();
495 view->setGoalHeadingOffset_deg(offset);
496 view->setHeadingOffset_deg(offset);
501 FGViewMgr::getViewGoalHeadingOffset_deg () const
503 const FGViewer * view = get_current_view();
504 return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
508 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
510 FGViewer * view = get_current_view();
512 view->setGoalHeadingOffset_deg(offset);
516 FGViewMgr::getViewPitchOffset_deg () const
518 const FGViewer * view = get_current_view();
519 return (view == 0 ? 0 : view->getPitchOffset_deg());
523 FGViewMgr::setViewPitchOffset_deg (double tilt)
525 FGViewer * view = get_current_view();
527 view->setGoalPitchOffset_deg(tilt);
528 view->setPitchOffset_deg(tilt);
533 FGViewMgr::getGoalViewPitchOffset_deg () const
535 const FGViewer * view = get_current_view();
536 return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
540 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
542 FGViewer * view = get_current_view();
544 view->setGoalPitchOffset_deg(tilt);
548 FGViewMgr::getViewRollOffset_deg () const
550 const FGViewer * view = get_current_view();
551 return (view == 0 ? 0 : view->getRollOffset_deg());
555 FGViewMgr::setViewRollOffset_deg (double tilt)
557 FGViewer * view = get_current_view();
559 view->setGoalRollOffset_deg(tilt);
560 view->setRollOffset_deg(tilt);
565 FGViewMgr::getGoalViewRollOffset_deg () const
567 const FGViewer * view = get_current_view();
568 return (view == 0 ? 0 : view->getGoalRollOffset_deg());
572 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
574 FGViewer * view = get_current_view();
576 view->setGoalRollOffset_deg(tilt);
580 FGViewMgr::getViewXOffset_m () const
582 const FGViewer * view = get_current_view();
584 return ((FGViewer *)view)->getXOffset_m();
591 FGViewMgr::setViewXOffset_m (double x)
593 FGViewer * view = get_current_view();
595 view->setXOffset_m(x);
600 FGViewMgr::getViewYOffset_m () const
602 const FGViewer * view = get_current_view();
604 return ((FGViewer *)view)->getYOffset_m();
611 FGViewMgr::setViewYOffset_m (double y)
613 FGViewer * view = get_current_view();
615 view->setYOffset_m(y);
620 FGViewMgr::getViewZOffset_m () const
622 const FGViewer * view = get_current_view();
624 return ((FGViewer *)view)->getZOffset_m();
631 FGViewMgr::setViewZOffset_m (double z)
633 FGViewer * view = get_current_view();
635 view->setZOffset_m(z);
640 FGViewMgr::stationary () const
642 const FGViewer * view = get_current_view();
644 if (((FGViewer *)view)->getXOffset_m() == 0.0 &&
645 ((FGViewer *)view)->getYOffset_m() == 0.0 &&
646 ((FGViewer *)view)->getZOffset_m() == 0.0)
654 FGViewMgr::getViewTargetXOffset_m () const
656 const FGViewer * view = get_current_view();
658 return ((FGViewer *)view)->getTargetXOffset_m();
665 FGViewMgr::setViewTargetXOffset_m (double x)
667 FGViewer * view = get_current_view();
669 view->setTargetXOffset_m(x);
674 FGViewMgr::getViewTargetYOffset_m () const
676 const FGViewer * view = get_current_view();
678 return ((FGViewer *)view)->getTargetYOffset_m();
685 FGViewMgr::setViewTargetYOffset_m (double y)
687 FGViewer * view = get_current_view();
689 view->setTargetYOffset_m(y);
694 FGViewMgr::getViewTargetZOffset_m () const
696 const FGViewer * view = get_current_view();
698 return ((FGViewer *)view)->getTargetZOffset_m();
705 FGViewMgr::setViewTargetZOffset_m (double z)
707 FGViewer * view = get_current_view();
709 view->setTargetZOffset_m(z);
714 FGViewMgr::getView () const
720 FGViewMgr::setView (int newview)
722 // negative numbers -> set view with node index -newview
724 for (int i = 0; i < (int)config_list.size(); i++) {
725 int index = -config_list[i]->getIndex();
726 if (index == newview)
733 // if newview number too low wrap to last view...
735 newview = (int)views.size() - 1;
737 // if newview number to high wrap to zero...
738 if (newview >= (int)views.size())
749 FGViewMgr::getFOV_deg () const
751 const FGViewer * view = get_current_view();
752 return (view == 0 ? 0 : view->get_fov());
756 FGViewMgr::setFOV_deg (double fov)
758 FGViewer * view = get_current_view();
764 FGViewMgr::getARM_deg () const
766 const FGViewer * view = get_current_view();
767 return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
771 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
773 FGViewer * view = get_current_view();
775 view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
779 FGViewMgr::getNear_m () const
781 const FGViewer * view = get_current_view();
782 return (view == 0 ? 0.5f : view->getNear_m());
786 FGViewMgr::setNear_m (double near_m)
788 FGViewer * view = get_current_view();
790 view->setNear_m(near_m);
794 FGViewMgr::setViewAxisLong (double axis)
800 FGViewMgr::setViewAxisLat (double axis)
805 // reference frame orientation.
806 // This is the view orientation you get when you have no
807 // view offset, i.e. the offset operator is the identity.
809 // For example, in the familiar "cockpit lookfrom" view,
810 // the reference frame is equal to the aircraft attitude,
811 // i.e. it is the view looking towards 12:00 straight ahead.
813 // FIXME: Somebody needs to figure out what is the reference
814 // frame view for the other view modes.
816 // Conceptually, this quat represents a rotation relative
817 // to the ECEF reference orientation, as described at
818 // http://www.av8n.com/physics/coords.htm#sec-orientation
820 // See the NOTE concerning reference orientations, below.
822 // The components of this quat are expressed in
823 // the conventional aviation basis set,
824 // i.e. x=forward, y=starboard, z=bottom
825 double FGViewMgr::getCurrentViewFrame_w() const{
826 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).w();
828 double FGViewMgr::getCurrentViewFrame_x() const{
829 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).x();
831 double FGViewMgr::getCurrentViewFrame_y() const{
832 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).y();
834 double FGViewMgr::getCurrentViewFrame_z() const{
835 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).z();
840 // This rotation takes you from the aforementioned
841 // reference frame view orientation to whatever
842 // actual current view orientation is.
844 // The components of this quaternion are expressed in
845 // the conventional aviation basis set,
846 // i.e. x=forward, y=starboard, z=bottom
847 double FGViewMgr::getCurrentViewOrOffset_w() const{
848 return current_view_or_offset.w();
850 double FGViewMgr::getCurrentViewOrOffset_x() const{
851 return current_view_or_offset.x();
853 double FGViewMgr::getCurrentViewOrOffset_y() const{
854 return current_view_or_offset.y();
856 double FGViewMgr::getCurrentViewOrOffset_z() const{
857 return current_view_or_offset.z();
861 // current view orientation.
862 // This is a rotation relative to the earth-centered (ec)
865 // NOTE: Here we remove a factor of fsb2sta so that
866 // the components of this quat are displayed using the
867 // conventional ECEF basis set. This is *not* the way
868 // the view orientation is stored in the views[] array,
869 // but is easier for non-graphics hackers to understand.
870 // If we did not remove this factor of fsb2sta here and
871 // in getCurrentViewFrame, that would be equivalent to
872 // the following peculiar reference orientation:
873 // Suppose you are over the Gulf of Guinea, at (lat,lon) = (0,0).
874 // Then the reference frame orientation can be achieved via:
875 // -- The aircraft X-axis (nose) headed south.
876 // -- The aircraft Y-axis (starboard wingtip) pointing up.
877 // -- The aircraft Z-axis (belly) pointing west.
878 // To say the same thing in other words, and perhaps more to the
879 // point: If we use the OpenGL camera orientation conventions,
880 // i.e. Xprime=starboard, Yprime=top, Zprime=aft, then the
881 // aforementioned peculiar reference orientation at (lat,lon)
882 // = (0,0) can be described as:
883 // -- aircraft Xprime axis (starboard) pointed up
884 // -- aircraft Yprime axis (top) pointed east
885 // -- aircraft Zprime axis (aft) pointed north
886 // meaning the OpenGL axes are aligned with the ECEF axes.
887 double FGViewMgr::getCurrentViewOrientation_w() const{
888 return (current_view_orientation * conj(fsb2sta())).w();
890 double FGViewMgr::getCurrentViewOrientation_x() const{
891 return (current_view_orientation * conj(fsb2sta())).x();
893 double FGViewMgr::getCurrentViewOrientation_y() const{
894 return (current_view_orientation * conj(fsb2sta())).y();
896 double FGViewMgr::getCurrentViewOrientation_z() const{
897 return (current_view_orientation * conj(fsb2sta())).z();
901 FGViewMgr::do_axes ()
903 // Take no action when hat is centered
904 if ( ( axis_long < 0.01 ) &&
905 ( axis_long > -0.01 ) &&
906 ( axis_lat < 0.01 ) &&
911 double viewDir = 999;
913 /* Do all the quick and easy cases */
914 if (axis_long < 0) { // Longitudinal axis forward
915 if (axis_lat == axis_long)
916 viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
917 else if (axis_lat == - axis_long)
918 viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
919 else if (axis_lat == 0)
920 viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
921 } else if (axis_long > 0) { // Longitudinal axis backward
922 if (axis_lat == - axis_long)
923 viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
924 else if (axis_lat == axis_long)
925 viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
926 else if (axis_lat == 0)
927 viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
928 } else if (axis_long == 0) { // Longitudinal axis neutral
930 viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
931 else if (axis_lat > 0)
932 viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
933 else return; /* And assertion failure maybe? */
936 // Do all the difficult cases
938 viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
939 if ( viewDir < -1 ) viewDir += 360;
941 get_current_view()->setGoalHeadingOffset_deg(viewDir);