2000-10-26 21:51:09 +00:00
|
|
|
// viewmgr.cxx -- class for managing all the views in the flightgear world.
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started October 2000.
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
// partially rewritten by Jim Wilson March 2002
|
2000-10-26 21:51:09 +00:00
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
|
2000-10-26 21:51:09 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2000-10-26 21:51:09 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
2006-02-18 13:58:09 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-09-18 16:50:08 +00:00
|
|
|
#include "viewmgr.hxx"
|
|
|
|
|
2002-03-20 22:15:22 +00:00
|
|
|
#include <string.h> // strcmp
|
|
|
|
|
Mathias:
I have done a patch to eliminate the jitter of 3D-objects near the viewpoint
(for example 3D cockpit objects).
The problem is the roundoff accuracy of the float values used in the
scenegraph together with the transforms of the eyepoint relative to the
scenery center.
The solution will be to move the scenery center near the view point.
This way floats relative accuracy is enough to show a stable picture.
To get that right I have introduced a transform node for the scenegraph which
is responsible for that shift and uses double values as long as possible.
The scenery subsystem now has a list of all those transforms required to place
objects in the world and will tell all those transforms that the scenery
center has changed when the set_scenery_center() of the scenery subsystem is
called.
The problem was not solvable by SGModelPlacement and SGLocation, since not all
objects, especially the scenery, are placed using these classes.
The first approach was to have the scenery center exactly at the eyepoint.
This works well for the cockpit.
But then the ground jitters a bit below the aircraft. With our default views
you can't see that, but that F-18 has a camera view below the left engine
intake with the nose gear and the ground in its field of view, here I could
see that.
Having the scenery center constant will still have this roundoff problems, but
like it is now too, the roundoff error here is exactly the same in each
frame, so you will not notice any jitter.
The real solution is now to keep the scenery center constant as long as it is
in a ball of 30m radius around the view point. If the scenery center is
outside this ball, just put it at the view point.
As a sideeffect of now beeing able to switch the scenery center in the whole
scenegraph with one function call, I was able to remove a one half of a
problem when switching views, where the scenery center was far off for one or
two frames past switching from one view to the next. Also included is a fix
to the other half of this problem, where the view position was not yet copied
into a view when it is switched (at least under glut). This was responsible
for the 'Error: ...' messages of the cloud subsystem when views were
switched.
2005-04-29 14:38:24 +00:00
|
|
|
#include <simgear/compiler.h>
|
2009-10-04 13:52:53 +00:00
|
|
|
#include <simgear/sound/soundmgr_openal.hxx>
|
Mathias:
I have done a patch to eliminate the jitter of 3D-objects near the viewpoint
(for example 3D cockpit objects).
The problem is the roundoff accuracy of the float values used in the
scenegraph together with the transforms of the eyepoint relative to the
scenery center.
The solution will be to move the scenery center near the view point.
This way floats relative accuracy is enough to show a stable picture.
To get that right I have introduced a transform node for the scenegraph which
is responsible for that shift and uses double values as long as possible.
The scenery subsystem now has a list of all those transforms required to place
objects in the world and will tell all those transforms that the scenery
center has changed when the set_scenery_center() of the scenery subsystem is
called.
The problem was not solvable by SGModelPlacement and SGLocation, since not all
objects, especially the scenery, are placed using these classes.
The first approach was to have the scenery center exactly at the eyepoint.
This works well for the cockpit.
But then the ground jitters a bit below the aircraft. With our default views
you can't see that, but that F-18 has a camera view below the left engine
intake with the nose gear and the ground in its field of view, here I could
see that.
Having the scenery center constant will still have this roundoff problems, but
like it is now too, the roundoff error here is exactly the same in each
frame, so you will not notice any jitter.
The real solution is now to keep the scenery center constant as long as it is
in a ball of 30m radius around the view point. If the scenery center is
outside this ball, just put it at the view point.
As a sideeffect of now beeing able to switch the scenery center in the whole
scenegraph with one function call, I was able to remove a one half of a
problem when switching views, where the scenery center was far off for one or
two frames past switching from one view to the next. Also included is a fix
to the other half of this problem, where the view position was not yet copied
into a view when it is switched (at least under glut). This was responsible
for the 'Error: ...' messages of the cloud subsystem when views were
switched.
2005-04-29 14:38:24 +00:00
|
|
|
#include <Model/acmodel.hxx>
|
2009-09-18 16:50:08 +00:00
|
|
|
#include <Main/viewer.hxx>
|
|
|
|
#include <Main/fg_props.hxx>
|
2000-10-26 21:51:09 +00:00
|
|
|
|
|
|
|
// Constructor
|
2000-10-30 15:09:17 +00:00
|
|
|
FGViewMgr::FGViewMgr( void ) :
|
2002-03-14 00:29:20 +00:00
|
|
|
axis_long(0),
|
|
|
|
axis_lat(0),
|
2007-06-11 19:02:01 +00:00
|
|
|
view_number(fgGetNode("/sim/current-view/view-number", true)),
|
2007-05-04 14:58:52 +00:00
|
|
|
config_list(fgGetNode("/sim", true)->getChildren("view")),
|
2002-03-14 00:29:20 +00:00
|
|
|
current(0)
|
2000-10-30 15:09:17 +00:00
|
|
|
{
|
2009-10-24 08:31:37 +00:00
|
|
|
smgr = globals->get_soundmgr();
|
2000-10-26 21:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
FGViewMgr::~FGViewMgr( void ) {
|
|
|
|
}
|
2002-03-14 00:29:20 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::init ()
|
|
|
|
{
|
2005-02-25 22:27:15 +00:00
|
|
|
double aspect_ratio_multiplier
|
|
|
|
= fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
|
|
|
|
|
2007-05-04 14:58:52 +00:00
|
|
|
for (unsigned int i = 0; i < config_list.size(); i++) {
|
|
|
|
SGPropertyNode *n = config_list[i];
|
2002-04-11 04:26:07 +00:00
|
|
|
|
2003-10-22 18:48:31 +00:00
|
|
|
// find out if this is an internal view (e.g. in cockpit, low near plane)
|
2007-05-04 14:58:52 +00:00
|
|
|
bool internal = n->getBoolValue("internal", false);
|
2003-10-22 18:48:31 +00:00
|
|
|
|
2002-04-11 04:26:07 +00:00
|
|
|
// FIXME:
|
|
|
|
// this is assumed to be an aircraft model...we will need to read
|
|
|
|
// model-from-type as well.
|
2007-05-04 14:58:52 +00:00
|
|
|
|
2002-04-11 04:26:07 +00:00
|
|
|
// find out if this is a model we are looking from...
|
2007-05-04 14:58:52 +00:00
|
|
|
bool from_model = n->getBoolValue("config/from-model");
|
|
|
|
int from_model_index = n->getIntValue("config/from-model-idx");
|
2002-04-11 04:26:07 +00:00
|
|
|
|
2007-05-04 14:58:52 +00:00
|
|
|
double x_offset_m = n->getDoubleValue("config/x-offset-m");
|
|
|
|
double y_offset_m = n->getDoubleValue("config/y-offset-m");
|
|
|
|
double z_offset_m = n->getDoubleValue("config/z-offset-m");
|
2002-04-11 04:26:07 +00:00
|
|
|
|
2007-05-04 14:58:52 +00:00
|
|
|
double heading_offset_deg = n->getDoubleValue("config/heading-offset-deg");
|
2007-05-04 19:34:19 +00:00
|
|
|
n->setDoubleValue("config/heading-offset-deg", heading_offset_deg);
|
2007-05-04 14:58:52 +00:00
|
|
|
double pitch_offset_deg = n->getDoubleValue("config/pitch-offset-deg");
|
2007-05-04 19:34:19 +00:00
|
|
|
n->setDoubleValue("config/pitch-offset-deg", pitch_offset_deg);
|
2007-05-04 14:58:52 +00:00
|
|
|
double roll_offset_deg = n->getDoubleValue("config/roll-offset-deg");
|
2007-05-04 19:34:19 +00:00
|
|
|
n->setDoubleValue("config/roll-offset-deg", roll_offset_deg);
|
2007-05-04 14:58:52 +00:00
|
|
|
|
|
|
|
double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
|
|
|
|
double near_m = n->getDoubleValue("config/ground-level-nearplane-m");
|
|
|
|
|
|
|
|
// supporting two types "lookat" = 1 and "lookfrom" = 0
|
|
|
|
const char *type = n->getStringValue("type");
|
|
|
|
if (!strcmp(type, "lookat")) {
|
|
|
|
|
|
|
|
bool at_model = n->getBoolValue("config/at-model");
|
|
|
|
int at_model_index = n->getIntValue("config/at-model-idx");
|
|
|
|
|
|
|
|
double damp_roll = n->getDoubleValue("config/at-model-roll-damping");
|
|
|
|
double damp_pitch = n->getDoubleValue("config/at-model-pitch-damping");
|
|
|
|
double damp_heading = n->getDoubleValue("config/at-model-heading-damping");
|
|
|
|
|
|
|
|
double target_x_offset_m = n->getDoubleValue("config/target-x-offset-m");
|
|
|
|
double target_y_offset_m = n->getDoubleValue("config/target-y-offset-m");
|
|
|
|
double target_z_offset_m = n->getDoubleValue("config/target-z-offset-m");
|
2003-02-06 19:44:32 +00:00
|
|
|
|
2002-04-18 16:51:47 +00:00
|
|
|
add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
|
2003-07-14 14:20:45 +00:00
|
|
|
at_model, at_model_index,
|
2003-07-24 15:00:16 +00:00
|
|
|
damp_roll, damp_pitch, damp_heading,
|
2003-07-11 08:58:26 +00:00
|
|
|
x_offset_m, y_offset_m,z_offset_m,
|
2003-02-06 19:44:32 +00:00
|
|
|
heading_offset_deg, pitch_offset_deg,
|
2005-02-25 21:20:17 +00:00
|
|
|
roll_offset_deg, fov_deg, aspect_ratio_multiplier,
|
2003-02-06 19:44:32 +00:00
|
|
|
target_x_offset_m, target_y_offset_m,
|
2003-10-22 18:48:31 +00:00
|
|
|
target_z_offset_m, near_m, internal ));
|
2007-05-04 14:58:52 +00:00
|
|
|
} else {
|
2003-07-14 14:20:45 +00:00
|
|
|
add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index,
|
2003-07-24 15:00:16 +00:00
|
|
|
false, 0, 0.0, 0.0, 0.0,
|
2003-07-14 14:20:45 +00:00
|
|
|
x_offset_m, y_offset_m, z_offset_m,
|
2003-02-06 19:44:32 +00:00
|
|
|
heading_offset_deg, pitch_offset_deg,
|
2005-02-25 21:20:17 +00:00
|
|
|
roll_offset_deg, fov_deg, aspect_ratio_multiplier,
|
|
|
|
0, 0, 0, near_m, internal ));
|
2007-05-04 14:58:52 +00:00
|
|
|
}
|
2002-04-05 18:49:04 +00:00
|
|
|
}
|
2002-04-18 16:51:47 +00:00
|
|
|
|
|
|
|
copyToCurrent();
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
2003-02-06 19:44:32 +00:00
|
|
|
void
|
|
|
|
FGViewMgr::reinit ()
|
|
|
|
{
|
|
|
|
// reset offsets and fov to configuration defaults
|
2007-05-04 14:58:52 +00:00
|
|
|
for (unsigned int i = 0; i < config_list.size(); i++) {
|
|
|
|
SGPropertyNode *n = config_list[i];
|
2003-02-06 19:44:32 +00:00
|
|
|
setView(i);
|
|
|
|
|
2007-05-04 14:58:52 +00:00
|
|
|
fgSetDouble("/sim/current-view/x-offset-m",
|
|
|
|
n->getDoubleValue("config/x-offset-m"));
|
|
|
|
fgSetDouble("/sim/current-view/y-offset-m",
|
|
|
|
n->getDoubleValue("config/y-offset-m"));
|
|
|
|
fgSetDouble("/sim/current-view/z-offset-m",
|
|
|
|
n->getDoubleValue("config/z-offset-m"));
|
2003-02-06 19:44:32 +00:00
|
|
|
fgSetDouble("/sim/current-view/pitch-offset-deg",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/pitch-offset-deg"));
|
2003-02-06 19:44:32 +00:00
|
|
|
fgSetDouble("/sim/current-view/heading-offset-deg",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/heading-offset-deg"));
|
2003-02-06 19:44:32 +00:00
|
|
|
fgSetDouble("/sim/current-view/roll-offset-deg",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/roll-offset-deg"));
|
2003-02-06 19:44:32 +00:00
|
|
|
|
2007-05-04 14:58:52 +00:00
|
|
|
double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
|
|
|
|
if (fov_deg < 10.0)
|
2003-02-06 19:44:32 +00:00
|
|
|
fov_deg = 55.0;
|
2007-05-04 14:58:52 +00:00
|
|
|
fgSetDouble("/sim/current-view/field-of-view", fov_deg);
|
2003-02-06 19:44:32 +00:00
|
|
|
|
|
|
|
// target offsets for lookat mode only...
|
2009-02-01 11:40:03 +00:00
|
|
|
fgSetDouble("/sim/current-view/target-x-offset-m",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/target-x-offset-m"));
|
2009-02-01 11:40:03 +00:00
|
|
|
fgSetDouble("/sim/current-view/target-y-offset-m",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/target-y-offset-m"));
|
2009-02-01 11:40:03 +00:00
|
|
|
fgSetDouble("/sim/current-view/target-z-offset-m",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/target-z-offset-m"));
|
|
|
|
}
|
|
|
|
setView(0);
|
2003-02-06 19:44:32 +00:00
|
|
|
}
|
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
typedef double (FGViewMgr::*double_getter)() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::bind ()
|
|
|
|
{
|
2002-04-18 16:51:47 +00:00
|
|
|
// these are bound to the current view properties
|
|
|
|
fgTie("/sim/current-view/heading-offset-deg", this,
|
2003-02-06 19:44:32 +00:00
|
|
|
&FGViewMgr::getViewHeadingOffset_deg,
|
|
|
|
&FGViewMgr::setViewHeadingOffset_deg);
|
2002-04-18 16:51:47 +00:00
|
|
|
fgSetArchivable("/sim/current-view/heading-offset-deg");
|
|
|
|
fgTie("/sim/current-view/goal-heading-offset-deg", this,
|
2003-02-06 19:44:32 +00:00
|
|
|
&FGViewMgr::getViewGoalHeadingOffset_deg,
|
|
|
|
&FGViewMgr::setViewGoalHeadingOffset_deg);
|
2002-04-18 16:51:47 +00:00
|
|
|
fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
|
|
|
|
fgTie("/sim/current-view/pitch-offset-deg", this,
|
2003-02-06 19:44:32 +00:00
|
|
|
&FGViewMgr::getViewPitchOffset_deg,
|
|
|
|
&FGViewMgr::setViewPitchOffset_deg);
|
2002-04-18 16:51:47 +00:00
|
|
|
fgSetArchivable("/sim/current-view/pitch-offset-deg");
|
|
|
|
fgTie("/sim/current-view/goal-pitch-offset-deg", this,
|
2003-02-06 19:44:32 +00:00
|
|
|
&FGViewMgr::getGoalViewPitchOffset_deg,
|
|
|
|
&FGViewMgr::setGoalViewPitchOffset_deg);
|
2002-04-18 16:51:47 +00:00
|
|
|
fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
|
2004-03-19 03:30:18 +00:00
|
|
|
fgTie("/sim/current-view/roll-offset-deg", this,
|
|
|
|
&FGViewMgr::getViewRollOffset_deg,
|
|
|
|
&FGViewMgr::setViewRollOffset_deg);
|
|
|
|
fgSetArchivable("/sim/current-view/roll-offset-deg");
|
|
|
|
fgTie("/sim/current-view/goal-roll-offset-deg", this,
|
|
|
|
&FGViewMgr::getGoalViewRollOffset_deg,
|
|
|
|
&FGViewMgr::setGoalViewRollOffset_deg);
|
|
|
|
fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
|
2002-04-18 16:51:47 +00:00
|
|
|
|
2007-05-04 14:58:52 +00:00
|
|
|
fgTie("/sim/current-view/view-number", this,
|
2003-02-06 19:44:32 +00:00
|
|
|
&FGViewMgr::getView, &FGViewMgr::setView);
|
|
|
|
fgSetArchivable("/sim/current-view/view-number", FALSE);
|
|
|
|
|
2002-04-18 16:51:47 +00:00
|
|
|
fgTie("/sim/current-view/axes/long", this,
|
2002-03-14 00:29:20 +00:00
|
|
|
(double_getter)0, &FGViewMgr::setViewAxisLong);
|
2003-02-06 19:44:32 +00:00
|
|
|
fgSetArchivable("/sim/current-view/axes/long");
|
|
|
|
|
2002-04-18 16:51:47 +00:00
|
|
|
fgTie("/sim/current-view/axes/lat", this,
|
2002-03-14 00:29:20 +00:00
|
|
|
(double_getter)0, &FGViewMgr::setViewAxisLat);
|
2003-02-06 19:44:32 +00:00
|
|
|
fgSetArchivable("/sim/current-view/axes/lat");
|
2002-04-18 16:51:47 +00:00
|
|
|
|
|
|
|
fgTie("/sim/current-view/field-of-view", this,
|
|
|
|
&FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
|
|
|
|
fgSetArchivable("/sim/current-view/field-of-view");
|
|
|
|
|
2005-02-25 21:20:17 +00:00
|
|
|
fgTie("/sim/current-view/aspect-ratio-multiplier", this,
|
|
|
|
&FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
|
|
|
|
fgSetArchivable("/sim/current-view/field-of-view");
|
|
|
|
|
2002-04-18 16:51:47 +00:00
|
|
|
fgTie("/sim/current-view/ground-level-nearplane-m", this,
|
|
|
|
&FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
|
|
|
|
fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
|
|
|
|
|
2008-12-20 12:49:37 +00:00
|
|
|
SGPropertyNode *n = fgGetNode("/sim/current-view", true);
|
|
|
|
n->tie("viewer-x-m", SGRawValuePointer<double>(&abs_viewer_position[0]));
|
|
|
|
n->tie("viewer-y-m", SGRawValuePointer<double>(&abs_viewer_position[1]));
|
|
|
|
n->tie("viewer-z-m", SGRawValuePointer<double>(&abs_viewer_position[2]));
|
2009-11-05 09:18:27 +00:00
|
|
|
|
2009-11-11 08:22:30 +00:00
|
|
|
// for automatic untying:
|
|
|
|
#define x(str) ((void)tied_props.push_back(str), str)
|
|
|
|
|
|
|
|
fgTie(x("/sim/current-view/debug/orientation-w"), this,
|
|
|
|
&FGViewMgr::getCurrentViewOrientation_w);
|
|
|
|
fgTie(x("/sim/current-view/debug/orientation-x"), this,
|
|
|
|
&FGViewMgr::getCurrentViewOrientation_x);
|
|
|
|
fgTie(x("/sim/current-view/debug/orientation-y"), this,
|
|
|
|
&FGViewMgr::getCurrentViewOrientation_y);
|
|
|
|
fgTie(x("/sim/current-view/debug/orientation-z"), this,
|
|
|
|
&FGViewMgr::getCurrentViewOrientation_z);
|
|
|
|
|
|
|
|
fgTie(x("/sim/current-view/debug/orientation_offset-w"), this,
|
|
|
|
&FGViewMgr::getCurrentViewOrOffset_w);
|
|
|
|
fgTie(x("/sim/current-view/debug/orientation_offset-x"), this,
|
|
|
|
&FGViewMgr::getCurrentViewOrOffset_x);
|
|
|
|
fgTie(x("/sim/current-view/debug/orientation_offset-y"), this,
|
|
|
|
&FGViewMgr::getCurrentViewOrOffset_y);
|
|
|
|
fgTie(x("/sim/current-view/debug/orientation_offset-z"), this,
|
|
|
|
&FGViewMgr::getCurrentViewOrOffset_z);
|
|
|
|
|
|
|
|
fgTie(x("/sim/current-view/debug/frame-w"), this,
|
|
|
|
&FGViewMgr::getCurrentViewFrame_w);
|
|
|
|
fgTie(x("/sim/current-view/debug/frame-x"), this,
|
|
|
|
&FGViewMgr::getCurrentViewFrame_x);
|
|
|
|
fgTie(x("/sim/current-view/debug/frame-y"), this,
|
|
|
|
&FGViewMgr::getCurrentViewFrame_y);
|
|
|
|
fgTie(x("/sim/current-view/debug/frame-z"), this,
|
|
|
|
&FGViewMgr::getCurrentViewFrame_z);
|
|
|
|
|
2009-11-05 09:18:27 +00:00
|
|
|
#undef x
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::unbind ()
|
|
|
|
{
|
2002-04-05 18:49:04 +00:00
|
|
|
// FIXME:
|
|
|
|
// need to redo these bindings to the new locations (move to viewer?)
|
2002-04-18 16:51:47 +00:00
|
|
|
fgUntie("/sim/current-view/heading-offset-deg");
|
|
|
|
fgUntie("/sim/current-view/goal-heading-offset-deg");
|
|
|
|
fgUntie("/sim/current-view/pitch-offset-deg");
|
|
|
|
fgUntie("/sim/current-view/goal-pitch-offset-deg");
|
2005-02-25 21:20:17 +00:00
|
|
|
fgUntie("/sim/current-view/field-of-view");
|
|
|
|
fgUntie("/sim/current-view/aspect-ratio-multiplier");
|
2003-02-06 19:44:32 +00:00
|
|
|
fgUntie("/sim/current-view/view-number");
|
2002-04-18 16:51:47 +00:00
|
|
|
fgUntie("/sim/current-view/axes/long");
|
|
|
|
fgUntie("/sim/current-view/axes/lat");
|
2003-02-06 19:44:32 +00:00
|
|
|
fgUntie("/sim/current-view/ground-level-nearplane-m");
|
2008-12-19 13:37:54 +00:00
|
|
|
fgUntie("/sim/current-view/viewer-x-m");
|
|
|
|
fgUntie("/sim/current-view/viewer-y-m");
|
|
|
|
fgUntie("/sim/current-view/viewer-z-m");
|
2009-11-05 09:18:27 +00:00
|
|
|
|
|
|
|
list<const char*>::const_iterator it;
|
|
|
|
for (it = tied_props.begin(); it != tied_props.end(); it++){
|
|
|
|
fgUntie(*it);
|
|
|
|
}
|
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-05-11 16:28:50 +00:00
|
|
|
FGViewMgr::update (double dt)
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
|
|
|
|
2009-11-02 13:48:09 +00:00
|
|
|
FGViewer *loop_view = (FGViewer *)get_current_view();
|
2009-11-02 13:26:45 +00:00
|
|
|
if (loop_view == 0) return;
|
|
|
|
|
2007-05-04 14:58:52 +00:00
|
|
|
SGPropertyNode *n = config_list[current];
|
|
|
|
double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
|
|
|
|
|
|
|
|
// Set up view location and orientation
|
|
|
|
|
|
|
|
if (!n->getBoolValue("config/from-model")) {
|
|
|
|
lon_deg = fgGetDouble(n->getStringValue("config/eye-lon-deg-path"));
|
|
|
|
lat_deg = fgGetDouble(n->getStringValue("config/eye-lat-deg-path"));
|
|
|
|
alt_ft = fgGetDouble(n->getStringValue("config/eye-alt-ft-path"));
|
|
|
|
roll_deg = fgGetDouble(n->getStringValue("config/eye-roll-deg-path"));
|
|
|
|
pitch_deg = fgGetDouble(n->getStringValue("config/eye-pitch-deg-path"));
|
|
|
|
heading_deg = fgGetDouble(n->getStringValue("config/eye-heading-deg-path"));
|
|
|
|
|
2002-04-05 18:49:04 +00:00
|
|
|
loop_view->setPosition(lon_deg, lat_deg, alt_ft);
|
|
|
|
loop_view->setOrientation(roll_deg, pitch_deg, heading_deg);
|
2002-04-11 04:26:07 +00:00
|
|
|
} else {
|
|
|
|
// force recalc in viewer
|
|
|
|
loop_view->set_dirty();
|
|
|
|
}
|
2002-04-05 18:49:04 +00:00
|
|
|
|
2002-04-11 04:26:07 +00:00
|
|
|
// if lookat (type 1) then get target data...
|
2002-06-28 18:00:21 +00:00
|
|
|
if (loop_view->getType() == FG_LOOKAT) {
|
2007-05-04 14:58:52 +00:00
|
|
|
if (!n->getBoolValue("config/from-model")) {
|
|
|
|
lon_deg = fgGetDouble(n->getStringValue("config/target-lon-deg-path"));
|
|
|
|
lat_deg = fgGetDouble(n->getStringValue("config/target-lat-deg-path"));
|
|
|
|
alt_ft = fgGetDouble(n->getStringValue("config/target-alt-ft-path"));
|
|
|
|
roll_deg = fgGetDouble(n->getStringValue("config/target-roll-deg-path"));
|
|
|
|
pitch_deg = fgGetDouble(n->getStringValue("config/target-pitch-deg-path"));
|
|
|
|
heading_deg = fgGetDouble(n->getStringValue("config/target-heading-deg-path"));
|
2003-07-14 14:20:45 +00:00
|
|
|
|
|
|
|
loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft);
|
2002-04-05 18:49:04 +00:00
|
|
|
loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
|
2002-04-11 04:26:07 +00:00
|
|
|
} else {
|
|
|
|
loop_view->set_dirty();
|
2002-04-05 18:49:04 +00:00
|
|
|
}
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
2003-02-06 19:44:32 +00:00
|
|
|
|
|
|
|
setViewXOffset_m(fgGetDouble("/sim/current-view/x-offset-m"));
|
|
|
|
setViewYOffset_m(fgGetDouble("/sim/current-view/y-offset-m"));
|
|
|
|
setViewZOffset_m(fgGetDouble("/sim/current-view/z-offset-m"));
|
|
|
|
|
|
|
|
setViewTargetXOffset_m(fgGetDouble("/sim/current-view/target-x-offset-m"));
|
|
|
|
setViewTargetYOffset_m(fgGetDouble("/sim/current-view/target-y-offset-m"));
|
|
|
|
setViewTargetZOffset_m(fgGetDouble("/sim/current-view/target-z-offset-m"));
|
2002-03-14 00:29:20 +00:00
|
|
|
|
2009-11-05 09:18:27 +00:00
|
|
|
current_view_orientation = loop_view->getViewOrientation();
|
|
|
|
current_view_or_offset = loop_view->getViewOrientationOffset();
|
|
|
|
|
2007-05-04 14:58:52 +00:00
|
|
|
// Update the current view
|
2002-03-14 00:29:20 +00:00
|
|
|
do_axes();
|
2009-11-02 13:26:45 +00:00
|
|
|
loop_view->update(dt);
|
2008-12-19 13:37:54 +00:00
|
|
|
abs_viewer_position = loop_view->getViewPosition();
|
2009-10-04 13:52:53 +00:00
|
|
|
|
|
|
|
// update audio listener values
|
2009-10-05 09:12:50 +00:00
|
|
|
// set the viewer posotion in Cartesian coordinates in meters
|
2009-11-03 09:59:05 +00:00
|
|
|
smgr->set_position( abs_viewer_position );
|
2009-11-05 09:18:27 +00:00
|
|
|
smgr->set_orientation( current_view_orientation );
|
2009-10-11 13:40:12 +00:00
|
|
|
|
2009-10-29 13:34:43 +00:00
|
|
|
// get the model velocity
|
|
|
|
SGVec3f velocity = SGVec3f::zeros();
|
2009-10-11 13:40:12 +00:00
|
|
|
if ( !stationary() ) {
|
2009-10-29 13:34:43 +00:00
|
|
|
velocity = globals->get_aircraft_model()->getVelocity();
|
2009-10-11 13:40:12 +00:00
|
|
|
}
|
2009-10-06 12:09:50 +00:00
|
|
|
smgr->set_velocity(velocity);
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
2002-04-18 16:51:47 +00:00
|
|
|
void
|
|
|
|
FGViewMgr::copyToCurrent()
|
|
|
|
{
|
2007-05-04 14:58:52 +00:00
|
|
|
SGPropertyNode *n = config_list[current];
|
2007-11-09 17:43:22 +00:00
|
|
|
fgSetString("/sim/current-view/name", n->getStringValue("name"));
|
|
|
|
fgSetString("/sim/current-view/type", n->getStringValue("type"));
|
2003-02-06 19:44:32 +00:00
|
|
|
|
|
|
|
// copy certain view config data for default values
|
|
|
|
fgSetDouble("/sim/current-view/config/heading-offset-deg",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/default-heading-offset-deg"));
|
2003-02-06 19:44:32 +00:00
|
|
|
fgSetDouble("/sim/current-view/config/pitch-offset-deg",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/pitch-offset-deg"));
|
2003-02-06 19:44:32 +00:00
|
|
|
fgSetDouble("/sim/current-view/config/roll-offset-deg",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/roll-offset-deg"));
|
2003-02-06 19:44:32 +00:00
|
|
|
fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getDoubleValue("config/default-field-of-view-deg"));
|
2004-03-19 03:30:18 +00:00
|
|
|
fgSetBool("/sim/current-view/config/from-model",
|
2007-05-04 14:58:52 +00:00
|
|
|
n->getBoolValue("config/from-model"));
|
2004-03-19 03:30:18 +00:00
|
|
|
|
2003-02-06 19:44:32 +00:00
|
|
|
// copy view data
|
|
|
|
fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
|
|
|
|
fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
|
|
|
|
fgSetDouble("/sim/current-view/z-offset-m", getViewZOffset_m());
|
2007-05-04 14:58:52 +00:00
|
|
|
|
2003-02-06 19:44:32 +00:00
|
|
|
fgSetDouble("/sim/current-view/goal-heading-offset-deg",
|
|
|
|
get_current_view()->getGoalHeadingOffset_deg());
|
|
|
|
fgSetDouble("/sim/current-view/goal-pitch-offset-deg",
|
|
|
|
get_current_view()->getGoalPitchOffset_deg());
|
|
|
|
fgSetDouble("/sim/current-view/goal-roll-offset-deg",
|
|
|
|
get_current_view()->getRollOffset_deg());
|
|
|
|
fgSetDouble("/sim/current-view/heading-offset-deg",
|
|
|
|
get_current_view()->getHeadingOffset_deg());
|
|
|
|
fgSetDouble("/sim/current-view/pitch-offset-deg",
|
|
|
|
get_current_view()->getPitchOffset_deg());
|
|
|
|
fgSetDouble("/sim/current-view/roll-offset-deg",
|
|
|
|
get_current_view()->getRollOffset_deg());
|
|
|
|
fgSetDouble("/sim/current-view/target-x-offset-m",
|
|
|
|
get_current_view()->getTargetXOffset_m());
|
|
|
|
fgSetDouble("/sim/current-view/target-y-offset-m",
|
|
|
|
get_current_view()->getTargetYOffset_m());
|
|
|
|
fgSetDouble("/sim/current-view/target-z-offset-m",
|
|
|
|
get_current_view()->getTargetZOffset_m());
|
2004-03-19 03:30:18 +00:00
|
|
|
fgSetBool("/sim/current-view/internal",
|
|
|
|
get_current_view()->getInternal());
|
2002-04-18 16:51:47 +00:00
|
|
|
}
|
|
|
|
|
2009-09-19 18:41:55 +00:00
|
|
|
void FGViewMgr::clear()
|
|
|
|
{
|
|
|
|
views.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
FGViewer*
|
|
|
|
FGViewMgr::get_current_view()
|
|
|
|
{
|
|
|
|
if ( current < (int)views.size() ) {
|
|
|
|
return views[current];
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const FGViewer*
|
|
|
|
FGViewMgr::get_current_view() const
|
|
|
|
{
|
|
|
|
if ( current < (int)views.size() ) {
|
|
|
|
return views[current];
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FGViewer*
|
|
|
|
FGViewMgr::get_view( int i )
|
|
|
|
{
|
|
|
|
if ( i < 0 ) { i = 0; }
|
|
|
|
if ( i >= (int)views.size() ) { i = views.size() - 1; }
|
|
|
|
return views[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
const FGViewer*
|
|
|
|
FGViewMgr::get_view( int i ) const
|
|
|
|
{
|
|
|
|
if ( i < 0 ) { i = 0; }
|
|
|
|
if ( i >= (int)views.size() ) { i = views.size() - 1; }
|
|
|
|
return views[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
FGViewer*
|
|
|
|
FGViewMgr::next_view()
|
|
|
|
{
|
|
|
|
setView((current+1 < (int)views.size()) ? (current + 1) : 0);
|
|
|
|
view_number->fireValueChanged();
|
|
|
|
return views[current];
|
|
|
|
}
|
|
|
|
|
|
|
|
FGViewer*
|
|
|
|
FGViewMgr::prev_view()
|
|
|
|
{
|
|
|
|
setView((0 < current) ? (current - 1) : (views.size() - 1));
|
|
|
|
view_number->fireValueChanged();
|
|
|
|
return views[current];
|
|
|
|
}
|
|
|
|
|
2009-09-18 16:50:08 +00:00
|
|
|
void
|
|
|
|
FGViewMgr::add_view( FGViewer * v )
|
|
|
|
{
|
|
|
|
views.push_back(v);
|
|
|
|
v->init();
|
|
|
|
}
|
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
double
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::getViewHeadingOffset_deg () const
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
return (view == 0 ? 0 : view->getHeadingOffset_deg());
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::setViewHeadingOffset_deg (double offset)
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
2002-03-26 13:44:43 +00:00
|
|
|
if (view != 0) {
|
|
|
|
view->setGoalHeadingOffset_deg(offset);
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
view->setHeadingOffset_deg(offset);
|
2002-03-26 13:44:43 +00:00
|
|
|
}
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::getViewGoalHeadingOffset_deg () const
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
2002-03-21 20:59:43 +00:00
|
|
|
return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0)
|
2002-03-21 20:59:43 +00:00
|
|
|
view->setGoalHeadingOffset_deg(offset);
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::getViewPitchOffset_deg () const
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
return (view == 0 ? 0 : view->getPitchOffset_deg());
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::setViewPitchOffset_deg (double tilt)
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
2002-03-26 13:44:43 +00:00
|
|
|
if (view != 0) {
|
|
|
|
view->setGoalPitchOffset_deg(tilt);
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
view->setPitchOffset_deg(tilt);
|
2002-03-26 13:44:43 +00:00
|
|
|
}
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::getGoalViewPitchOffset_deg () const
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
2002-03-21 20:59:43 +00:00
|
|
|
return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0)
|
2002-03-21 20:59:43 +00:00
|
|
|
view->setGoalPitchOffset_deg(tilt);
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
|
2004-03-19 03:30:18 +00:00
|
|
|
double
|
|
|
|
FGViewMgr::getViewRollOffset_deg () const
|
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
return (view == 0 ? 0 : view->getRollOffset_deg());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::setViewRollOffset_deg (double tilt)
|
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
view->setGoalRollOffset_deg(tilt);
|
|
|
|
view->setRollOffset_deg(tilt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
FGViewMgr::getGoalViewRollOffset_deg () const
|
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
return (view == 0 ? 0 : view->getGoalRollOffset_deg());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::setGoalViewRollOffset_deg (double tilt)
|
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0)
|
|
|
|
view->setGoalRollOffset_deg(tilt);
|
|
|
|
}
|
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
double
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::getViewXOffset_m () const
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
2002-04-18 16:51:47 +00:00
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
return ((FGViewer *)view)->getXOffset_m();
|
2002-03-14 00:29:20 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::setViewXOffset_m (double x)
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
2002-04-18 16:51:47 +00:00
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
view->setXOffset_m(x);
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::getViewYOffset_m () const
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
2002-04-18 16:51:47 +00:00
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
return ((FGViewer *)view)->getYOffset_m();
|
2002-03-14 00:29:20 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::setViewYOffset_m (double y)
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
2002-04-18 16:51:47 +00:00
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
view->setYOffset_m(y);
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::getViewZOffset_m () const
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
2002-04-18 16:51:47 +00:00
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
return ((FGViewer *)view)->getZOffset_m();
|
2002-03-14 00:29:20 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-02-06 19:44:32 +00:00
|
|
|
FGViewMgr::setViewZOffset_m (double z)
|
2002-03-14 00:29:20 +00:00
|
|
|
{
|
2002-04-18 16:51:47 +00:00
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
view->setZOffset_m(z);
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-11 13:40:12 +00:00
|
|
|
bool
|
|
|
|
FGViewMgr::stationary () const
|
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
if (((FGViewer *)view)->getXOffset_m() == 0.0 &&
|
|
|
|
((FGViewer *)view)->getYOffset_m() == 0.0 &&
|
|
|
|
((FGViewer *)view)->getZOffset_m() == 0.0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-06 19:44:32 +00:00
|
|
|
double
|
|
|
|
FGViewMgr::getViewTargetXOffset_m () const
|
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
return ((FGViewer *)view)->getTargetXOffset_m();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::setViewTargetXOffset_m (double x)
|
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
view->setTargetXOffset_m(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
FGViewMgr::getViewTargetYOffset_m () const
|
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
return ((FGViewer *)view)->getTargetYOffset_m();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::setViewTargetYOffset_m (double y)
|
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
view->setTargetYOffset_m(y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
FGViewMgr::getViewTargetZOffset_m () const
|
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
return ((FGViewer *)view)->getTargetZOffset_m();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::setViewTargetZOffset_m (double z)
|
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0) {
|
|
|
|
view->setTargetZOffset_m(z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
FGViewMgr::getView () const
|
|
|
|
{
|
|
|
|
return ( current );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-05-04 14:58:52 +00:00
|
|
|
FGViewMgr::setView (int newview)
|
|
|
|
{
|
|
|
|
// negative numbers -> set view with node index -newview
|
|
|
|
if (newview < 0) {
|
|
|
|
for (int i = 0; i < (int)config_list.size(); i++) {
|
2007-06-11 19:02:01 +00:00
|
|
|
int index = -config_list[i]->getIndex();
|
|
|
|
if (index == newview)
|
|
|
|
newview = i;
|
2007-05-04 14:58:52 +00:00
|
|
|
}
|
|
|
|
if (newview < 0)
|
2007-06-11 19:02:01 +00:00
|
|
|
return;
|
2007-05-04 14:58:52 +00:00
|
|
|
}
|
|
|
|
|
2003-05-09 08:31:56 +00:00
|
|
|
// if newview number too low wrap to last view...
|
2007-05-04 14:58:52 +00:00
|
|
|
if (newview < 0)
|
2007-06-11 19:02:01 +00:00
|
|
|
newview = (int)views.size() - 1;
|
2007-05-04 14:58:52 +00:00
|
|
|
|
2003-05-09 08:31:56 +00:00
|
|
|
// if newview number to high wrap to zero...
|
2007-06-11 19:02:01 +00:00
|
|
|
if (newview >= (int)views.size())
|
2003-02-06 19:44:32 +00:00
|
|
|
newview = 0;
|
2007-05-04 14:58:52 +00:00
|
|
|
|
2003-02-06 19:44:32 +00:00
|
|
|
// set new view
|
2007-05-04 14:58:52 +00:00
|
|
|
set_view(newview);
|
2003-02-06 19:44:32 +00:00
|
|
|
// copy in view data
|
2007-05-04 14:58:52 +00:00
|
|
|
copyToCurrent();
|
Mathias:
I have done a patch to eliminate the jitter of 3D-objects near the viewpoint
(for example 3D cockpit objects).
The problem is the roundoff accuracy of the float values used in the
scenegraph together with the transforms of the eyepoint relative to the
scenery center.
The solution will be to move the scenery center near the view point.
This way floats relative accuracy is enough to show a stable picture.
To get that right I have introduced a transform node for the scenegraph which
is responsible for that shift and uses double values as long as possible.
The scenery subsystem now has a list of all those transforms required to place
objects in the world and will tell all those transforms that the scenery
center has changed when the set_scenery_center() of the scenery subsystem is
called.
The problem was not solvable by SGModelPlacement and SGLocation, since not all
objects, especially the scenery, are placed using these classes.
The first approach was to have the scenery center exactly at the eyepoint.
This works well for the cockpit.
But then the ground jitters a bit below the aircraft. With our default views
you can't see that, but that F-18 has a camera view below the left engine
intake with the nose gear and the ground in its field of view, here I could
see that.
Having the scenery center constant will still have this roundoff problems, but
like it is now too, the roundoff error here is exactly the same in each
frame, so you will not notice any jitter.
The real solution is now to keep the scenery center constant as long as it is
in a ball of 30m radius around the view point. If the scenery center is
outside this ball, just put it at the view point.
As a sideeffect of now beeing able to switch the scenery center in the whole
scenegraph with one function call, I was able to remove a one half of a
problem when switching views, where the scenery center was far off for one or
two frames past switching from one view to the next. Also included is a fix
to the other half of this problem, where the view position was not yet copied
into a view when it is switched (at least under glut). This was responsible
for the 'Error: ...' messages of the cloud subsystem when views were
switched.
2005-04-29 14:38:24 +00:00
|
|
|
|
|
|
|
// Copy the fdm's position into the SGLocation which is shared with
|
|
|
|
// some views ...
|
|
|
|
globals->get_aircraft_model()->update(0);
|
|
|
|
// Do the update ...
|
|
|
|
update(0);
|
2003-02-06 19:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
double
|
|
|
|
FGViewMgr::getFOV_deg () const
|
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
return (view == 0 ? 0 : view->get_fov());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::setFOV_deg (double fov)
|
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0)
|
|
|
|
view->set_fov(fov);
|
|
|
|
}
|
|
|
|
|
2005-02-25 21:20:17 +00:00
|
|
|
double
|
|
|
|
FGViewMgr::getARM_deg () const
|
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
|
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0)
|
|
|
|
view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
|
|
|
|
}
|
|
|
|
|
2002-04-18 16:51:47 +00:00
|
|
|
double
|
|
|
|
FGViewMgr::getNear_m () const
|
|
|
|
{
|
|
|
|
const FGViewer * view = get_current_view();
|
|
|
|
return (view == 0 ? 0.5f : view->getNear_m());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::setNear_m (double near_m)
|
|
|
|
{
|
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view != 0)
|
|
|
|
view->setNear_m(near_m);
|
|
|
|
}
|
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
void
|
|
|
|
FGViewMgr::setViewAxisLong (double axis)
|
|
|
|
{
|
|
|
|
axis_long = axis;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::setViewAxisLat (double axis)
|
|
|
|
{
|
|
|
|
axis_lat = axis;
|
|
|
|
}
|
|
|
|
|
2009-11-08 13:41:03 +00:00
|
|
|
// reference frame orientation.
|
|
|
|
// This is the view orientation you get when you have no
|
|
|
|
// view offset, i.e. the offset operator is the identity.
|
|
|
|
//
|
|
|
|
// For example, in the familiar "cockpit lookfrom" view,
|
|
|
|
// the reference frame is equal to the aircraft attitude,
|
|
|
|
// i.e. it is the view looking towards 12:00 straight ahead.
|
|
|
|
//
|
|
|
|
// FIXME: Somebody needs to figure out what is the reference
|
|
|
|
// frame view for the other view modes.
|
|
|
|
//
|
|
|
|
// Conceptually, this quat represents a rotation relative
|
|
|
|
// to the ECEF reference orientation, as described at
|
|
|
|
// http://www.av8n.com/physics/coords.htm#sec-orientation
|
|
|
|
//
|
|
|
|
// See the NOTE concerning reference orientations, below.
|
|
|
|
//
|
|
|
|
// The components of this quat are expressed in
|
|
|
|
// the conventional aviation basis set,
|
|
|
|
// i.e. x=forward, y=starboard, z=bottom
|
2009-11-11 08:22:30 +00:00
|
|
|
double FGViewMgr::getCurrentViewFrame_w() const{
|
|
|
|
return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).w();
|
|
|
|
}
|
|
|
|
double FGViewMgr::getCurrentViewFrame_x() const{
|
|
|
|
return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).x();
|
|
|
|
}
|
|
|
|
double FGViewMgr::getCurrentViewFrame_y() const{
|
|
|
|
return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).y();
|
|
|
|
}
|
|
|
|
double FGViewMgr::getCurrentViewFrame_z() const{
|
|
|
|
return ((current_view_orientation*conj(fsb2sta())*conj(current_view_or_offset))).z();
|
2009-11-08 13:41:03 +00:00
|
|
|
}
|
|
|
|
|
2009-11-11 08:22:30 +00:00
|
|
|
|
2009-11-08 13:41:03 +00:00
|
|
|
// view offset.
|
|
|
|
// This rotation takes you from the aforementioned
|
|
|
|
// reference frame view orientation to whatever
|
|
|
|
// actual current view orientation is.
|
|
|
|
//
|
2009-11-05 09:18:27 +00:00
|
|
|
// The components of this quaternion are expressed in
|
2009-11-08 13:41:03 +00:00
|
|
|
// the conventional aviation basis set,
|
|
|
|
// i.e. x=forward, y=starboard, z=bottom
|
2009-11-11 08:22:30 +00:00
|
|
|
double FGViewMgr::getCurrentViewOrOffset_w() const{
|
|
|
|
return current_view_or_offset.w();
|
|
|
|
}
|
|
|
|
double FGViewMgr::getCurrentViewOrOffset_x() const{
|
|
|
|
return current_view_or_offset.x();
|
|
|
|
}
|
|
|
|
double FGViewMgr::getCurrentViewOrOffset_y() const{
|
|
|
|
return current_view_or_offset.y();
|
2009-11-05 09:18:27 +00:00
|
|
|
}
|
2009-11-11 08:22:30 +00:00
|
|
|
double FGViewMgr::getCurrentViewOrOffset_z() const{
|
|
|
|
return current_view_or_offset.z();
|
|
|
|
}
|
|
|
|
|
2009-11-05 09:18:27 +00:00
|
|
|
|
2009-11-08 13:41:03 +00:00
|
|
|
// current view orientation.
|
|
|
|
// This is a rotation relative to the earth-centered (ec)
|
|
|
|
// reference frame.
|
|
|
|
//
|
|
|
|
// NOTE: Here we remove a factor of fsb2sta so that
|
|
|
|
// the components of this quat are displayed using the
|
|
|
|
// conventional ECEF basis set. This is *not* the way
|
|
|
|
// the view orientation is stored in the views[] array,
|
2009-11-09 09:24:46 +00:00
|
|
|
// but is easier for non-graphics hackers to understand.
|
2009-11-08 13:41:03 +00:00
|
|
|
// If we did not remove this factor of fsb2sta here and
|
|
|
|
// in getCurrentViewFrame, that would be equivalent to
|
|
|
|
// the following peculiar reference orientation:
|
|
|
|
// Suppose you are over the Gulf of Guinea, at (lat,lon) = (0,0).
|
|
|
|
// Then the reference frame orientation can be achieved via:
|
|
|
|
// -- The aircraft X-axis (nose) headed south.
|
|
|
|
// -- The aircraft Y-axis (starboard wingtip) pointing up.
|
|
|
|
// -- The aircraft Z-axis (belly) pointing west.
|
|
|
|
// To say the same thing in other words, and perhaps more to the
|
|
|
|
// point: If we use the OpenGL camera orientation conventions,
|
|
|
|
// i.e. Xprime=starboard, Yprime=top, Zprime=aft, then the
|
|
|
|
// aforementioned peculiar reference orientation at (lat,lon)
|
|
|
|
// = (0,0) can be described as:
|
|
|
|
// -- aircraft Xprime axis (starboard) pointed up
|
|
|
|
// -- aircraft Yprime axis (top) pointed east
|
|
|
|
// -- aircraft Zprime axis (aft) pointed north
|
|
|
|
// meaning the OpenGL axes are aligned with the ECEF axes.
|
2009-11-11 08:22:30 +00:00
|
|
|
double FGViewMgr::getCurrentViewOrientation_w() const{
|
|
|
|
return (current_view_orientation * conj(fsb2sta())).w();
|
|
|
|
}
|
|
|
|
double FGViewMgr::getCurrentViewOrientation_x() const{
|
|
|
|
return (current_view_orientation * conj(fsb2sta())).x();
|
|
|
|
}
|
|
|
|
double FGViewMgr::getCurrentViewOrientation_y() const{
|
|
|
|
return (current_view_orientation * conj(fsb2sta())).y();
|
|
|
|
}
|
|
|
|
double FGViewMgr::getCurrentViewOrientation_z() const{
|
|
|
|
return (current_view_orientation * conj(fsb2sta())).z();
|
2009-11-05 09:18:27 +00:00
|
|
|
}
|
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
void
|
|
|
|
FGViewMgr::do_axes ()
|
|
|
|
{
|
|
|
|
// Take no action when hat is centered
|
|
|
|
if ( ( axis_long < 0.01 ) &&
|
|
|
|
( axis_long > -0.01 ) &&
|
|
|
|
( axis_lat < 0.01 ) &&
|
|
|
|
( axis_lat > -0.01 )
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
|
|
|
|
double viewDir = 999;
|
|
|
|
|
|
|
|
/* Do all the quick and easy cases */
|
|
|
|
if (axis_long < 0) { // Longitudinal axis forward
|
|
|
|
if (axis_lat == axis_long)
|
2002-11-02 21:43:15 +00:00
|
|
|
viewDir = fgGetDouble("/sim/view/config/front-left-direction-deg");
|
2002-03-14 00:29:20 +00:00
|
|
|
else if (axis_lat == - axis_long)
|
2002-11-02 21:43:15 +00:00
|
|
|
viewDir = fgGetDouble("/sim/view/config/front-right-direction-deg");
|
2002-03-14 00:29:20 +00:00
|
|
|
else if (axis_lat == 0)
|
2002-11-02 21:43:15 +00:00
|
|
|
viewDir = fgGetDouble("/sim/view/config/front-direction-deg");
|
2002-03-14 00:29:20 +00:00
|
|
|
} else if (axis_long > 0) { // Longitudinal axis backward
|
|
|
|
if (axis_lat == - axis_long)
|
2002-11-02 21:43:15 +00:00
|
|
|
viewDir = fgGetDouble("/sim/view/config/back-left-direction-deg");
|
2002-03-14 00:29:20 +00:00
|
|
|
else if (axis_lat == axis_long)
|
2002-11-02 21:43:15 +00:00
|
|
|
viewDir = fgGetDouble("/sim/view/config/back-right-direction-deg");
|
2002-03-14 00:29:20 +00:00
|
|
|
else if (axis_lat == 0)
|
2002-11-02 21:43:15 +00:00
|
|
|
viewDir = fgGetDouble("/sim/view/config/back-direction-deg");
|
2002-03-14 00:29:20 +00:00
|
|
|
} else if (axis_long == 0) { // Longitudinal axis neutral
|
|
|
|
if (axis_lat < 0)
|
2002-11-02 21:43:15 +00:00
|
|
|
viewDir = fgGetDouble("/sim/view/config/left-direction-deg");
|
2002-03-14 00:29:20 +00:00
|
|
|
else if (axis_lat > 0)
|
2002-11-02 21:43:15 +00:00
|
|
|
viewDir = fgGetDouble("/sim/view/config/right-direction-deg");
|
2002-03-14 00:29:20 +00:00
|
|
|
else return; /* And assertion failure maybe? */
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do all the difficult cases
|
|
|
|
if ( viewDir > 900 )
|
|
|
|
viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axis_lat, -axis_long );
|
|
|
|
if ( viewDir < -1 ) viewDir += 360;
|
|
|
|
|
2002-03-21 20:59:43 +00:00
|
|
|
get_current_view()->setGoalHeadingOffset_deg(viewDir);
|
2002-03-14 00:29:20 +00:00
|
|
|
}
|