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
|
|
|
//
|
|
|
|
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
2002-03-20 22:15:22 +00:00
|
|
|
#include <string.h> // strcmp
|
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
#include <plib/sg.h>
|
|
|
|
|
2000-10-26 21:51:09 +00:00
|
|
|
#include "viewmgr.hxx"
|
2002-03-14 00:29:20 +00:00
|
|
|
#include "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),
|
|
|
|
current(0)
|
2000-10-30 15:09:17 +00:00
|
|
|
{
|
2000-10-26 21:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
FGViewMgr::~FGViewMgr( void ) {
|
|
|
|
}
|
2002-03-14 00:29:20 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
FGViewMgr::init ()
|
|
|
|
{
|
2002-04-05 18:49:04 +00:00
|
|
|
char stridx [ 20 ];
|
2002-06-28 18:00:21 +00:00
|
|
|
string viewpath, nodepath, strdata;
|
2002-04-11 04:26:07 +00:00
|
|
|
bool from_model = false;
|
|
|
|
bool at_model = false;
|
|
|
|
int from_model_index = 0;
|
|
|
|
int at_model_index = 0;
|
2002-04-18 16:51:47 +00:00
|
|
|
double x_offset_m, y_offset_m, z_offset_m;
|
|
|
|
double near_m;
|
2002-04-11 04:26:07 +00:00
|
|
|
|
2002-04-05 18:49:04 +00:00
|
|
|
for (int i = 0; i < fgGetInt("/sim/number-views"); i++) {
|
2002-04-11 04:26:07 +00:00
|
|
|
viewpath = "/sim/view";
|
2002-04-05 18:49:04 +00:00
|
|
|
sprintf(stridx, "[%d]", i);
|
2002-04-11 04:26:07 +00:00
|
|
|
viewpath += stridx;
|
|
|
|
|
|
|
|
// find out what type of view this is...
|
|
|
|
nodepath = viewpath;
|
2002-04-05 18:49:04 +00:00
|
|
|
nodepath += "/type";
|
|
|
|
strdata = fgGetString(nodepath.c_str());
|
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.
|
|
|
|
// find out if this is a model we are looking from...
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/from-model";
|
|
|
|
from_model = fgGetBool(nodepath.c_str());
|
|
|
|
|
|
|
|
// get model index (which model)
|
|
|
|
if (from_model) {
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/from-model-idx";
|
|
|
|
from_model_index = fgGetInt(nodepath.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcmp("lookat",strdata.c_str()) == 0 ) {
|
|
|
|
// find out if this is a model we are looking at...
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/at-model";
|
|
|
|
at_model = fgGetBool(nodepath.c_str());
|
|
|
|
|
|
|
|
// get model index (which model)
|
|
|
|
if (at_model) {
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/at-model-idx";
|
|
|
|
at_model_index = fgGetInt(nodepath.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-18 16:51:47 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/x-offset-m";
|
|
|
|
x_offset_m = fgGetDouble(nodepath.c_str());
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/y-offset-m";
|
|
|
|
y_offset_m = fgGetDouble(nodepath.c_str());
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/z-offset-m";
|
|
|
|
z_offset_m = fgGetDouble(nodepath.c_str());
|
|
|
|
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/ground-level-nearplane-m";
|
|
|
|
near_m = fgGetDouble(nodepath.c_str());
|
|
|
|
|
2002-04-11 04:26:07 +00:00
|
|
|
// supporting two types now "lookat" = 1 and "lookfrom" = 0
|
2002-04-05 18:49:04 +00:00
|
|
|
if ( strcmp("lookat",strdata.c_str()) == 0 )
|
2002-04-18 16:51:47 +00:00
|
|
|
add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
|
|
|
|
at_model, at_model_index, x_offset_m, y_offset_m,
|
|
|
|
z_offset_m, near_m ));
|
2002-04-05 18:49:04 +00:00
|
|
|
else
|
2002-04-18 16:51:47 +00:00
|
|
|
add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index, false,
|
|
|
|
0, x_offset_m, y_offset_m, z_offset_m, near_m ));
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2002-03-14 00:29:20 +00:00
|
|
|
&FGViewMgr::getViewOffset_deg, &FGViewMgr::setViewOffset_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,
|
2002-03-14 00:29:20 +00:00
|
|
|
&FGViewMgr::getGoalViewOffset_deg, &FGViewMgr::setGoalViewOffset_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,
|
2002-03-14 00:29:20 +00:00
|
|
|
&FGViewMgr::getViewTilt_deg, &FGViewMgr::setViewTilt_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,
|
2002-03-14 00:29:20 +00:00
|
|
|
&FGViewMgr::getGoalViewTilt_deg, &FGViewMgr::setGoalViewTilt_deg);
|
2002-04-18 16:51:47 +00:00
|
|
|
fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
|
|
|
|
|
|
|
|
fgTie("/sim/current-view/axes/long", this,
|
2002-03-14 00:29:20 +00:00
|
|
|
(double_getter)0, &FGViewMgr::setViewAxisLong);
|
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);
|
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");
|
|
|
|
|
|
|
|
fgTie("/sim/current-view/ground-level-nearplane-m", this,
|
|
|
|
&FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
|
|
|
|
fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
|
|
|
|
|
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");
|
2002-03-14 00:29:20 +00:00
|
|
|
fgUntie("/sim/field-of-view");
|
2002-04-18 16:51:47 +00:00
|
|
|
fgUntie("/sim/current-view/axes/long");
|
|
|
|
fgUntie("/sim/current-view/axes/lat");
|
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
|
|
|
{
|
2002-04-05 18:49:04 +00:00
|
|
|
char stridx [20];
|
2002-06-28 18:00:21 +00:00
|
|
|
string viewpath, nodepath;
|
2002-04-11 04:26:07 +00:00
|
|
|
double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
|
2002-04-05 18:49:04 +00:00
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
FGViewer * view = get_current_view();
|
|
|
|
if (view == 0)
|
|
|
|
return;
|
|
|
|
|
2002-04-11 04:26:07 +00:00
|
|
|
//
|
|
|
|
int i = current;
|
|
|
|
viewpath = "/sim/view";
|
|
|
|
sprintf(stridx, "[%d]", i);
|
|
|
|
viewpath += stridx;
|
|
|
|
|
2002-04-05 18:49:04 +00:00
|
|
|
|
2002-04-11 04:26:07 +00:00
|
|
|
FGViewer *loop_view = (FGViewer *)get_view( i );
|
2002-04-05 18:49:04 +00:00
|
|
|
|
2002-04-11 04:26:07 +00:00
|
|
|
// Set up view location and orientation
|
2002-04-05 18:49:04 +00:00
|
|
|
|
2002-04-11 04:26:07 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/from-model";
|
|
|
|
if (!fgGetBool(nodepath.c_str())) {
|
2002-04-05 18:49:04 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/eye-lon-deg-path";
|
2002-04-11 04:26:07 +00:00
|
|
|
lon_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
2002-04-05 18:49:04 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/eye-lat-deg-path";
|
2002-04-11 04:26:07 +00:00
|
|
|
lat_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
2002-04-05 18:49:04 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/eye-alt-ft-path";
|
2002-04-11 04:26:07 +00:00
|
|
|
alt_ft = fgGetDouble(fgGetString(nodepath.c_str()));
|
2002-04-05 18:49:04 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/eye-roll-deg-path";
|
2002-04-11 04:26:07 +00:00
|
|
|
roll_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
2002-04-05 18:49:04 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/eye-pitch-deg-path";
|
2002-04-11 04:26:07 +00:00
|
|
|
pitch_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
2002-04-05 18:49:04 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/eye-heading-deg-path";
|
2002-04-11 04:26:07 +00:00
|
|
|
heading_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
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) {
|
2002-04-11 04:26:07 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/from-model";
|
|
|
|
if (!fgGetBool(nodepath.c_str())) {
|
2002-04-05 18:49:04 +00:00
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/target-lon-deg-path";
|
|
|
|
lon_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/target-lat-deg-path";
|
|
|
|
lat_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/target-alt-ft-path";
|
|
|
|
alt_ft = fgGetDouble(fgGetString(nodepath.c_str()));
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/target-roll-deg-path";
|
|
|
|
roll_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/target-pitch-deg-path";
|
|
|
|
pitch_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
|
|
|
nodepath = viewpath;
|
|
|
|
nodepath += "/config/target-heading-deg-path";
|
|
|
|
heading_deg = fgGetDouble(fgGetString(nodepath.c_str()));
|
2002-04-11 04:26:07 +00:00
|
|
|
|
2002-04-05 18:49:04 +00:00
|
|
|
loop_view ->setTargetPosition(lon_deg, lat_deg, alt_ft);
|
|
|
|
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
|
|
|
}
|
2002-04-18 16:51:47 +00:00
|
|
|
setPilotXOffset_m(fgGetDouble("/sim/current-view/x-offset-m"));
|
|
|
|
setPilotYOffset_m(fgGetDouble("/sim/current-view/y-offset-m"));
|
|
|
|
setPilotZOffset_m(fgGetDouble("/sim/current-view/z-offset-m"));
|
2002-03-14 00:29:20 +00:00
|
|
|
|
2002-04-18 16:51:47 +00:00
|
|
|
// Update the current view
|
2002-03-14 00:29:20 +00:00
|
|
|
do_axes();
|
|
|
|
view->update(dt);
|
|
|
|
}
|
|
|
|
|
2002-04-18 16:51:47 +00:00
|
|
|
void
|
|
|
|
FGViewMgr::copyToCurrent()
|
|
|
|
{
|
|
|
|
fgSetDouble("/sim/current-view/x-offset-m", getPilotXOffset_m());
|
|
|
|
fgSetDouble("/sim/current-view/y-offset-m", getPilotYOffset_m());
|
|
|
|
fgSetDouble("/sim/current-view/z-offset-m", getPilotZOffset_m());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-14 00:29:20 +00:00
|
|
|
double
|
|
|
|
FGViewMgr::getViewOffset_deg () const
|
|
|
|
{
|
|
|
|
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
|
|
|
|
FGViewMgr::setViewOffset_deg (double offset)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
FGViewMgr::getGoalViewOffset_deg () const
|
|
|
|
{
|
|
|
|
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
|
|
|
|
FGViewMgr::setGoalViewOffset_deg (double offset)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
FGViewMgr::getViewTilt_deg () const
|
|
|
|
{
|
|
|
|
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
|
|
|
|
FGViewMgr::setViewTilt_deg (double tilt)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
FGViewMgr::getGoalViewTilt_deg () const
|
|
|
|
{
|
|
|
|
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
|
|
|
|
FGViewMgr::setGoalViewTilt_deg (double tilt)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
FGViewMgr::getPilotXOffset_m () const
|
|
|
|
{
|
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
|
|
|
|
FGViewMgr::setPilotXOffset_m (double x)
|
|
|
|
{
|
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
|
|
|
|
FGViewMgr::getPilotYOffset_m () const
|
|
|
|
{
|
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
|
|
|
|
FGViewMgr::setPilotYOffset_m (double y)
|
|
|
|
{
|
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
|
|
|
|
FGViewMgr::getPilotZOffset_m () const
|
|
|
|
{
|
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
|
|
|
|
FGViewMgr::setPilotZOffset_m (double z)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|