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")),
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_GENERAL, 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 fgTie("/sim/current-view/heading-offset-deg", this,
186 &FGViewMgr::getViewHeadingOffset_deg,
187 &FGViewMgr::setViewHeadingOffset_deg);
188 fgSetArchivable("/sim/current-view/heading-offset-deg");
189 fgTie("/sim/current-view/goal-heading-offset-deg", this,
190 &FGViewMgr::getViewGoalHeadingOffset_deg,
191 &FGViewMgr::setViewGoalHeadingOffset_deg);
192 fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
193 fgTie("/sim/current-view/pitch-offset-deg", this,
194 &FGViewMgr::getViewPitchOffset_deg,
195 &FGViewMgr::setViewPitchOffset_deg);
196 fgSetArchivable("/sim/current-view/pitch-offset-deg");
197 fgTie("/sim/current-view/goal-pitch-offset-deg", this,
198 &FGViewMgr::getGoalViewPitchOffset_deg,
199 &FGViewMgr::setGoalViewPitchOffset_deg);
200 fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
201 fgTie("/sim/current-view/roll-offset-deg", this,
202 &FGViewMgr::getViewRollOffset_deg,
203 &FGViewMgr::setViewRollOffset_deg);
204 fgSetArchivable("/sim/current-view/roll-offset-deg");
205 fgTie("/sim/current-view/goal-roll-offset-deg", this,
206 &FGViewMgr::getGoalViewRollOffset_deg,
207 &FGViewMgr::setGoalViewRollOffset_deg);
208 fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
210 fgTie("/sim/current-view/view-number", this,
211 &FGViewMgr::getView, &FGViewMgr::setView);
212 fgSetArchivable("/sim/current-view/view-number", false);
214 fgTie("/sim/current-view/axes/long", this,
215 (double_getter)0, &FGViewMgr::setViewAxisLong);
216 fgSetArchivable("/sim/current-view/axes/long");
218 fgTie("/sim/current-view/axes/lat", this,
219 (double_getter)0, &FGViewMgr::setViewAxisLat);
220 fgSetArchivable("/sim/current-view/axes/lat");
222 fgTie("/sim/current-view/field-of-view", this,
223 &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
224 fgSetArchivable("/sim/current-view/field-of-view");
226 fgTie("/sim/current-view/aspect-ratio-multiplier", this,
227 &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
228 fgSetArchivable("/sim/current-view/field-of-view");
230 fgTie("/sim/current-view/ground-level-nearplane-m", this,
231 &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
232 fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
234 SGPropertyNode *n = fgGetNode("/sim/current-view", true);
235 n->tie("viewer-x-m", SGRawValuePointer<double>(&abs_viewer_position[0]));
236 n->tie("viewer-y-m", SGRawValuePointer<double>(&abs_viewer_position[1]));
237 n->tie("viewer-z-m", SGRawValuePointer<double>(&abs_viewer_position[2]));
239 // for automatic untying:
240 #define x(str) ((void)tied_props.push_back(str), str)
242 fgTie(x("/sim/current-view/debug/orientation-w"), this,
243 &FGViewMgr::getCurrentViewOrientation_w);
244 fgTie(x("/sim/current-view/debug/orientation-x"), this,
245 &FGViewMgr::getCurrentViewOrientation_x);
246 fgTie(x("/sim/current-view/debug/orientation-y"), this,
247 &FGViewMgr::getCurrentViewOrientation_y);
248 fgTie(x("/sim/current-view/debug/orientation-z"), this,
249 &FGViewMgr::getCurrentViewOrientation_z);
251 fgTie(x("/sim/current-view/debug/orientation_offset-w"), this,
252 &FGViewMgr::getCurrentViewOrOffset_w);
253 fgTie(x("/sim/current-view/debug/orientation_offset-x"), this,
254 &FGViewMgr::getCurrentViewOrOffset_x);
255 fgTie(x("/sim/current-view/debug/orientation_offset-y"), this,
256 &FGViewMgr::getCurrentViewOrOffset_y);
257 fgTie(x("/sim/current-view/debug/orientation_offset-z"), this,
258 &FGViewMgr::getCurrentViewOrOffset_z);
260 fgTie(x("/sim/current-view/debug/frame-w"), this,
261 &FGViewMgr::getCurrentViewFrame_w);
262 fgTie(x("/sim/current-view/debug/frame-x"), this,
263 &FGViewMgr::getCurrentViewFrame_x);
264 fgTie(x("/sim/current-view/debug/frame-y"), this,
265 &FGViewMgr::getCurrentViewFrame_y);
266 fgTie(x("/sim/current-view/debug/frame-z"), this,
267 &FGViewMgr::getCurrentViewFrame_z);
276 // need to redo these bindings to the new locations (move to viewer?)
277 fgUntie("/sim/current-view/heading-offset-deg");
278 fgUntie("/sim/current-view/goal-heading-offset-deg");
279 fgUntie("/sim/current-view/pitch-offset-deg");
280 fgUntie("/sim/current-view/goal-pitch-offset-deg");
281 fgUntie("/sim/current-view/field-of-view");
282 fgUntie("/sim/current-view/aspect-ratio-multiplier");
283 fgUntie("/sim/current-view/view-number");
284 fgUntie("/sim/current-view/axes/long");
285 fgUntie("/sim/current-view/axes/lat");
286 fgUntie("/sim/current-view/ground-level-nearplane-m");
287 fgUntie("/sim/current-view/viewer-x-m");
288 fgUntie("/sim/current-view/viewer-y-m");
289 fgUntie("/sim/current-view/viewer-z-m");
291 list<const char*>::const_iterator it;
292 for (it = tied_props.begin(); it != tied_props.end(); it++){
299 FGViewMgr::update (double dt)
302 FGViewer *loop_view = (FGViewer *)get_current_view();
303 if (loop_view == 0) return;
305 SGPropertyNode *n = config_list[current];
306 double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
308 // Set up view location and orientation
310 if (!n->getBoolValue("config/from-model")) {
311 lon_deg = fgGetDouble(n->getStringValue("config/eye-lon-deg-path"));
312 lat_deg = fgGetDouble(n->getStringValue("config/eye-lat-deg-path"));
313 alt_ft = fgGetDouble(n->getStringValue("config/eye-alt-ft-path"));
314 roll_deg = fgGetDouble(n->getStringValue("config/eye-roll-deg-path"));
315 pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path"));
316 heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path"));
318 loop_view->setPosition(lon_deg, lat_deg, alt_ft);
319 loop_view->setOrientation(roll_deg, pitch_deg, heading_deg);
321 // force recalc in viewer
322 loop_view->set_dirty();
325 // if lookat (type 1) then get target data...
326 if (loop_view->getType() == FG_LOOKAT) {
327 if (!n->getBoolValue("config/from-model")) {
328 lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path"));
329 lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path"));
330 alt_ft = fgGetDouble(n->getStringValue("config/target-alt-ft-path"));
331 roll_deg = fgGetDouble(n->getStringValue("config/target-roll-deg-path"));
332 pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path"));
333 heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path"));
335 loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft);
336 loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
338 loop_view->set_dirty();
342 setViewXOffset_m(fgGetDouble("/sim/current-view/x-offset-m"));
343 setViewYOffset_m(fgGetDouble("/sim/current-view/y-offset-m"));
344 setViewZOffset_m(fgGetDouble("/sim/current-view/z-offset-m"));
346 setViewTargetXOffset_m(fgGetDouble("/sim/current-view/target-x-offset-m"));
347 setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m"));
348 setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m"));
350 current_view_orientation = loop_view->getViewOrientation();
351 current_view_or_offset = loop_view->getViewOrientationOffset();
353 // Update the current view
355 loop_view->update(dt);
356 abs_viewer_position = loop_view->getViewPosition();
358 // update audio listener values
359 // set the viewer position in Cartesian coordinates in meters
360 smgr->set_position( abs_viewer_position, loop_view->getPosition() );
361 smgr->set_orientation( current_view_orientation );
363 // get the model velocity
364 SGVec3d velocity = SGVec3d::zeros();
365 if ( !stationary() ) {
366 velocity = globals->get_aircraft_model()->getVelocity();
368 smgr->set_velocity( velocity );
372 FGViewMgr::copyToCurrent()
378 SGPropertyNode *n = config_list[current];
379 fgSetString("/sim/current-view/name", n->getStringValue("name"));
380 fgSetString("/sim/current-view/type", n->getStringValue("type"));
382 // copy certain view config data for default values
383 fgSetDouble("/sim/current-view/config/heading-offset-deg",
384 n->getDoubleValue("config/default-heading-offset-deg"));
385 fgSetDouble("/sim/current-view/config/pitch-offset-deg",
386 n->getDoubleValue("config/pitch-offset-deg"));
387 fgSetDouble("/sim/current-view/config/roll-offset-deg",
388 n->getDoubleValue("config/roll-offset-deg"));
389 fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
390 n->getDoubleValue("config/default-field-of-view-deg"));
391 fgSetBool("/sim/current-view/config/from-model",
392 n->getBoolValue("config/from-model"));
395 fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
396 fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
397 fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
399 fgSetDouble("/sim/current-view/goal-heading-offset-deg",
400 get_current_view()->getGoalHeadingOffset_deg());
401 fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
402 get_current_view()->getGoalPitchOffset_deg());
403 fgSetDouble("/sim/current-view/goal-roll-offset-deg",
404 get_current_view()->getRollOffset_deg());
405 fgSetDouble("/sim/current-view/heading-offset-deg",
406 get_current_view()->getHeadingOffset_deg());
407 fgSetDouble("/sim/current-view/pitch-offset-deg",
408 get_current_view()->getPitchOffset_deg());
409 fgSetDouble("/sim/current-view/roll-offset-deg",
410 get_current_view()->getRollOffset_deg());
411 fgSetDouble("/sim/current-view/target-x-offset-m",
412 get_current_view()->getTargetXOffset_m());
413 fgSetDouble("/sim/current-view/target-y-offset-m",
414 get_current_view()->getTargetYOffset_m());
415 fgSetDouble("/sim/current-view/target-z-offset-m",
416 get_current_view()->getTargetZOffset_m());
417 fgSetBool("/sim/current-view/internal",
418 get_current_view()->getInternal());
421 void FGViewMgr::clear()
427 FGViewMgr::get_current_view()
429 if ( current < (int)views.size() ) {
430 return views[current];
437 FGViewMgr::get_current_view() const
439 if ( current < (int)views.size() ) {
440 return views[current];
448 FGViewMgr::get_view( int i )
450 if ( i < 0 ) { i = 0; }
451 if ( i >= (int)views.size() ) { i = views.size() - 1; }
456 FGViewMgr::get_view( int i ) const
458 if ( i < 0 ) { i = 0; }
459 if ( i >= (int)views.size() ) { i = views.size() - 1; }
464 FGViewMgr::next_view()
466 setView((current+1 < (int)views.size()) ? (current + 1) : 0);
467 view_number->fireValueChanged();
468 return views[current];
472 FGViewMgr::prev_view()
474 setView((0 < current) ? (current - 1) : (views.size() - 1));
475 view_number->fireValueChanged();
476 return views[current];
480 FGViewMgr::add_view( FGViewer * v )
487 FGViewMgr::getViewHeadingOffset_deg () const
489 const FGViewer * view = get_current_view();
490 return (view == 0 ? 0 : view->getHeadingOffset_deg());
494 FGViewMgr::setViewHeadingOffset_deg (double offset)
496 FGViewer * view = get_current_view();
498 view->setGoalHeadingOffset_deg(offset);
499 view->setHeadingOffset_deg(offset);
504 FGViewMgr::getViewGoalHeadingOffset_deg () const
506 const FGViewer * view = get_current_view();
507 return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
511 FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
513 FGViewer * view = get_current_view();
515 view->setGoalHeadingOffset_deg(offset);
519 FGViewMgr::getViewPitchOffset_deg () const
521 const FGViewer * view = get_current_view();
522 return (view == 0 ? 0 : view->getPitchOffset_deg());
526 FGViewMgr::setViewPitchOffset_deg (double tilt)
528 FGViewer * view = get_current_view();
530 view->setGoalPitchOffset_deg(tilt);
531 view->setPitchOffset_deg(tilt);
536 FGViewMgr::getGoalViewPitchOffset_deg () const
538 const FGViewer * view = get_current_view();
539 return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
543 FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
545 FGViewer * view = get_current_view();
547 view->setGoalPitchOffset_deg(tilt);
551 FGViewMgr::getViewRollOffset_deg () const
553 const FGViewer * view = get_current_view();
554 return (view == 0 ? 0 : view->getRollOffset_deg());
558 FGViewMgr::setViewRollOffset_deg (double tilt)
560 FGViewer * view = get_current_view();
562 view->setGoalRollOffset_deg(tilt);
563 view->setRollOffset_deg(tilt);
568 FGViewMgr::getGoalViewRollOffset_deg () const
570 const FGViewer * view = get_current_view();
571 return (view == 0 ? 0 : view->getGoalRollOffset_deg());
575 FGViewMgr::setGoalViewRollOffset_deg (double tilt)
577 FGViewer * view = get_current_view();
579 view->setGoalRollOffset_deg(tilt);
583 FGViewMgr::getViewXOffset_m () const
585 const FGViewer * view = get_current_view();
587 return ((FGViewer *)view)->getXOffset_m();
594 FGViewMgr::setViewXOffset_m (double x)
596 FGViewer * view = get_current_view();
598 view->setXOffset_m(x);
603 FGViewMgr::getViewYOffset_m () const
605 const FGViewer * view = get_current_view();
607 return ((FGViewer *)view)->getYOffset_m();
614 FGViewMgr::setViewYOffset_m (double y)
616 FGViewer * view = get_current_view();
618 view->setYOffset_m(y);
623 FGViewMgr::getViewZOffset_m () const
625 const FGViewer * view = get_current_view();
627 return ((FGViewer *)view)->getZOffset_m();
634 FGViewMgr::setViewZOffset_m (double z)
636 FGViewer * view = get_current_view();
638 view->setZOffset_m(z);
643 FGViewMgr::stationary () const
645 const FGViewer * view = get_current_view();
647 if (((FGViewer *)view)->getXOffset_m() == 0.0 &&
648 ((FGViewer *)view)->getYOffset_m() == 0.0 &&
649 ((FGViewer *)view)->getZOffset_m() == 0.0)
657 FGViewMgr::getViewTargetXOffset_m () const
659 const FGViewer * view = get_current_view();
661 return ((FGViewer *)view)->getTargetXOffset_m();
668 FGViewMgr::setViewTargetXOffset_m (double x)
670 FGViewer * view = get_current_view();
672 view->setTargetXOffset_m(x);
677 FGViewMgr::getViewTargetYOffset_m () const
679 const FGViewer * view = get_current_view();
681 return ((FGViewer *)view)->getTargetYOffset_m();
688 FGViewMgr::setViewTargetYOffset_m (double y)
690 FGViewer * view = get_current_view();
692 view->setTargetYOffset_m(y);
697 FGViewMgr::getViewTargetZOffset_m () const
699 const FGViewer * view = get_current_view();
701 return ((FGViewer *)view)->getTargetZOffset_m();
708 FGViewMgr::setViewTargetZOffset_m (double z)
710 FGViewer * view = get_current_view();
712 view->setTargetZOffset_m(z);
717 FGViewMgr::getView () const
723 FGViewMgr::setView (int newview)
725 // negative numbers -> set view with node index -newview
727 for (int i = 0; i < (int)config_list.size(); i++) {
728 int index = -config_list[i]->getIndex();
729 if (index == newview)
736 // if newview number too low wrap to last view...
738 newview = (int)views.size() - 1;
740 // if newview number to high wrap to zero...
741 if (newview >= (int)views.size())
752 FGViewMgr::getFOV_deg () const
754 const FGViewer * view = get_current_view();
755 return (view == 0 ? 0 : view->get_fov());
759 FGViewMgr::setFOV_deg (double fov)
761 FGViewer * view = get_current_view();
767 FGViewMgr::getARM_deg () const
769 const FGViewer * view = get_current_view();
770 return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
774 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
776 FGViewer * view = get_current_view();
778 view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
782 FGViewMgr::getNear_m () const
784 const FGViewer * view = get_current_view();
785 return (view == 0 ? 0.5f : view->getNear_m());
789 FGViewMgr::setNear_m (double near_m)
791 FGViewer * view = get_current_view();
793 view->setNear_m(near_m);
797 FGViewMgr::setViewAxisLong (double axis)
803 FGViewMgr::setViewAxisLat (double axis)
808 // reference frame orientation.
809 // This is the view orientation you get when you have no
810 // view offset, i.e. the offset operator is the identity.
812 // For example, in the familiar "cockpit lookfrom" view,
813 // the reference frame is equal to the aircraft attitude,
814 // i.e. it is the view looking towards 12:00 straight ahead.
816 // FIXME: Somebody needs to figure out what is the reference
817 // frame view for the other view modes.
819 // Conceptually, this quat represents a rotation relative
820 // to the ECEF reference orientation, as described at
821 // http://www.av8n.com/physics/coords.htm#sec-orientation
823 // See the NOTE concerning reference orientations, below.
825 // The components of this quat are expressed in
826 // the conventional aviation basis set,
827 // i.e. x=forward, y=starboard, z=bottom
828 double FGViewMgr::getCurrentViewFrame_w() const{
829 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).w();
831 double FGViewMgr::getCurrentViewFrame_x() const{
832 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).x();
834 double FGViewMgr::getCurrentViewFrame_y() const{
835 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).y();
837 double FGViewMgr::getCurrentViewFrame_z() const{
838 return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).z();
843 // This rotation takes you from the aforementioned
844 // reference frame view orientation to whatever
845 // actual current view orientation is.
847 // The components of this quaternion are expressed in
848 // the conventional aviation basis set,
849 // i.e. x=forward, y=starboard, z=bottom
850 double FGViewMgr::getCurrentViewOrOffset_w() const{
851 return current_view_or_offset.w();
853 double FGViewMgr::getCurrentViewOrOffset_x() const{
854 return current_view_or_offset.x();
856 double FGViewMgr::getCurrentViewOrOffset_y() const{
857 return current_view_or_offset.y();
859 double FGViewMgr::getCurrentViewOrOffset_z() const{
860 return current_view_or_offset.z();
864 // current view orientation.
865 // This is a rotation relative to the earth-centered (ec)
868 // NOTE: Here we remove a factor of fsb2sta so that
869 // the components of this quat are displayed using the
870 // conventional ECEF basis set. This is *not* the way
871 // the view orientation is stored in the views[] array,
872 // but is easier for non-graphics hackers to understand.
873 // If we did not remove this factor of fsb2sta here and
874 // in getCurrentViewFrame, that would be equivalent to
875 // the following peculiar reference orientation:
876 // Suppose you are over the Gulf of Guinea, at (lat,lon) = (0,0).
877 // Then the reference frame orientation can be achieved via:
878 // -- The aircraft X-axis (nose) headed south.
879 // -- The aircraft Y-axis (starboard wingtip) pointing up.
880 // -- The aircraft Z-axis (belly) pointing west.
881 // To say the same thing in other words, and perhaps more to the
882 // point: If we use the OpenGL camera orientation conventions,
883 // i.e. Xprime=starboard, Yprime=top, Zprime=aft, then the
884 // aforementioned peculiar reference orientation at (lat,lon)
885 // = (0,0) can be described as:
886 // -- aircraft Xprime axis (starboard) pointed up
887 // -- aircraft Yprime axis (top) pointed east
888 // -- aircraft Zprime axis (aft) pointed north
889 // meaning the OpenGL axes are aligned with the ECEF axes.
890 double FGViewMgr::getCurrentViewOrientation_w() const{
891 return (current_view_orientation * conj(fsb2sta())).w();
893 double FGViewMgr::getCurrentViewOrientation_x() const{
894 return (current_view_orientation * conj(fsb2sta())).x();
896 double FGViewMgr::getCurrentViewOrientation_y() const{
897 return (current_view_orientation * conj(fsb2sta())).y();
899 double FGViewMgr::getCurrentViewOrientation_z() const{
900 return (current_view_orientation * conj(fsb2sta())).z();
904 FGViewMgr::do_axes ()
906 // Take no action when hat is centered
907 if ( ( axis_long < 0.01 ) &&
908 ( axis_long > -0.01 ) &&
909 ( axis_lat < 0.01 ) &&
914 double viewDir = 999;
916 /* Do all the quick and easy cases */
917 if (axis_long < 0) { // Longitudinal axis forward
918 if (axis_lat == axis_long)
919 viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
920 else if (axis_lat == - axis_long)
921 viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
922 else if (axis_lat == 0)
923 viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
924 } else if (axis_long > 0) { // Longitudinal axis backward
925 if (axis_lat == - axis_long)
926 viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
927 else if (axis_lat == axis_long)
928 viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
929 else if (axis_lat == 0)
930 viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
931 } else if (axis_long == 0) { // Longitudinal axis neutral
933 viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
934 else if (axis_lat > 0)
935 viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
936 else return; /* And assertion failure maybe? */
939 // Do all the difficult cases
941 viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
942 if ( viewDir < -1 ) viewDir += 360;
944 get_current_view()->setGoalHeadingOffset_deg(viewDir);