1
0
Fork 0

ViewManager::copyToCurrent is a no-op

This commit is contained in:
James Turner 2016-01-17 16:14:11 -06:00
parent 655ac851e0
commit 7391b9d76a
3 changed files with 76 additions and 128 deletions

View file

@ -89,6 +89,8 @@ View::View( ViewType Type, bool from_model, int from_model_index,
_offset_m.x() = x_offset_m;
_offset_m.y() = y_offset_m;
_offset_m.z() = z_offset_m;
_configOffset_m = _offset_m;
_heading_offset_deg = heading_offset_deg;
_pitch_offset_deg = pitch_offset_deg;
_roll_offset_deg = roll_offset_deg;
@ -112,6 +114,8 @@ View::View( ViewType Type, bool from_model, int from_model_index,
_target_offset_m.x() = target_x_offset_m;
_target_offset_m.y() = target_y_offset_m;
_target_offset_m.z() = target_z_offset_m;
_configTargetOffset_m = _target_offset_m;
_ground_level_nearplane_m = near_m;
// a reasonable guess for init, so that the math doesn't blow up
}
@ -189,7 +193,9 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
// Destructor
View::~View( void ) {
View::~View( void )
{
_tiedProperties.Untie();
}
void
@ -203,36 +209,44 @@ View::bind ()
_tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
_tiedProperties.Tie("heading-offset-deg", this,
&View::getHeadingOffset_deg,
&View::setHeadingOffset_deg_property);
&View::setHeadingOffset_deg_property,
false /* do not set current property value */);
fgSetArchivable("/sim/current-view/heading-offset-deg");
_tiedProperties.Tie("goal-heading-offset-deg", this,
&View::getGoalHeadingOffset_deg,
&View::setGoalHeadingOffset_deg);
&View::setGoalHeadingOffset_deg,
false /* do not set current property value */);
fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
_tiedProperties.Tie("pitch-offset-deg", this,
&View::getPitchOffset_deg,
&View::setPitchOffset_deg_property);
&View::setPitchOffset_deg_property,
false /* do not set current property value */);
fgSetArchivable("/sim/current-view/pitch-offset-deg");
_tiedProperties.Tie("goal-pitch-offset-deg", this,
&View::getGoalPitchOffset_deg,
&View::setGoalPitchOffset_deg);
&View::setGoalPitchOffset_deg,
false /* do not set current property value */);
fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
_tiedProperties.Tie("roll-offset-deg", this,
&View::getRollOffset_deg,
&View::setRollOffset_deg_property);
&View::setRollOffset_deg_property,
false /* do not set current property value */);
fgSetArchivable("/sim/current-view/roll-offset-deg");
_tiedProperties.Tie("goal-roll-offset-deg", this,
&View::getGoalRollOffset_deg,
&View::setGoalRollOffset_deg);
&View::setGoalRollOffset_deg,
false /* do not set current property value */);
fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
// following config properties are exposed on current-view but don't change,
// so we can simply copy them here.
_tiedProperties.getRoot()->setStringValue("name", _name);
_tiedProperties.getRoot()->setStringValue("type", _typeString);
_tiedProperties.getRoot()->setBoolValue("internal", _internal);
SGPropertyNode_ptr config = _tiedProperties.getRoot()->getChild("config", 0, true);
config->setBoolValue("from-model", _from_model);
@ -240,6 +254,17 @@ View::bind ()
config->setDoubleValue("pitch-offset-deg", _configPitchOffsetDeg);
config->setDoubleValue("roll-offset-deg", _configRollOffsetDeg);
config->setDoubleValue("default-field-of-view-deg", _configFOV_deg);
// following properties are not tied, but copied each frame (for now).
// copying /in/ happens in FGViewMgr::update; this is where we copy our current
// values /out/ when we are activated
_tiedProperties.getRoot()->setDoubleValue("x-offset-m", getXOffset_m());
_tiedProperties.getRoot()->setDoubleValue("y-offset-m", getYOffset_m());
_tiedProperties.getRoot()->setDoubleValue("z-offset-m", getZOffset_m());
_tiedProperties.getRoot()->setDoubleValue("target-x-offset-m", getTargetXOffset_m());
_tiedProperties.getRoot()->setDoubleValue("target-y-offset-m", getTargetYOffset_m());
_tiedProperties.getRoot()->setDoubleValue("target-z-offset-m", getTargetZOffset_m());
}
void
@ -248,6 +273,16 @@ View::unbind ()
_tiedProperties.Untie();
}
void View::resetOffsetsAndFOV()
{
_target_offset_m = _configTargetOffset_m;
_offset_m = _configOffset_m;
_pitch_offset_deg = _configPitchOffsetDeg;
_heading_offset_deg = _configHeadingOffsetDeg;
_roll_offset_deg = _configRollOffsetDeg;
_fov_deg = _configFOV_deg;
}
void
View::setType ( int type )
{

View file

@ -78,6 +78,8 @@ public:
// Part 2: user settings.
//////////////////////////////////////////////////////////////////////
void resetOffsetsAndFOV();
ViewType getType() const { return _type; }
void setType( int type );
@ -284,12 +286,13 @@ private:
// out the tail, Y is out the right wing, and Z is positive up.
// distance in meters
SGVec3d _offset_m;
SGVec3d _configOffset_m;
// Target offsets from FDM origin (for "lookat" targets) The X
// axis is positive out the tail, Y is out the right wing, and Z
// is positive up. distance in meters
SGVec3d _target_offset_m;
SGVec3d _configTargetOffset_m;
// orientation offsets from reference (_goal* are for smoothed transitions)
double _roll_offset_deg;

View file

@ -66,13 +66,7 @@ FGViewMgr::init ()
inited = true;
// stash properties
current_x_offs = fgGetNode("/sim/current-view/x-offset-m", true);
current_y_offs = fgGetNode("/sim/current-view/y-offset-m", true);
current_z_offs = fgGetNode("/sim/current-view/z-offset-m", true);
target_x_offs = fgGetNode("/sim/current-view/target-x-offset-m", true);
target_y_offs = fgGetNode("/sim/current-view/target-y-offset-m", true);
target_z_offs = fgGetNode("/sim/current-view/target-z-offset-m", true);
for (unsigned int i = 0; i < config_list.size(); i++) {
@ -87,6 +81,8 @@ FGViewMgr::init ()
copyToCurrent();
do_bind();
get_current_view()->bind();
}
void
@ -105,45 +101,16 @@ FGViewMgr::shutdown()
}
inited = false;
views.clear();
}
void
FGViewMgr::reinit ()
{
int current_view_index = current;
// reset offsets and fov to configuration defaults
for (unsigned int i = 0; i < config_list.size(); i++) {
SGPropertyNode *n = config_list[i];
setView(i);
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"));
fgSetDouble("/sim/current-view/pitch-offset-deg",
n->getDoubleValue("config/pitch-offset-deg"));
fgSetDouble("/sim/current-view/heading-offset-deg",
n->getDoubleValue("config/heading-offset-deg"));
fgSetDouble("/sim/current-view/roll-offset-deg",
n->getDoubleValue("config/roll-offset-deg"));
double fov_deg = n->getDoubleValue("config/default-field-of-view-deg");
if (fov_deg < 10.0)
fov_deg = 55.0;
fgSetDouble("/sim/current-view/field-of-view", fov_deg);
// target offsets for lookat mode only...
fgSetDouble("/sim/current-view/target-x-offset-m",
n->getDoubleValue("config/target-x-offset-m"));
fgSetDouble("/sim/current-view/target-y-offset-m",
n->getDoubleValue("config/target-y-offset-m"));
fgSetDouble("/sim/current-view/target-z-offset-m",
n->getDoubleValue("config/target-z-offset-m"));
}
setView(current_view_index);
viewer_list::iterator it;
for (it = views.begin(); it != views.end(); ++it) {
(*it)->resetOffsetsAndFOV();
}
}
typedef double (FGViewMgr::*double_getter)() const;
@ -153,6 +120,13 @@ FGViewMgr::bind()
{
// view-manager code was designed to init before bind, so
// this is a no-op; init() calls the real bind() impl below
current_x_offs = fgGetNode("/sim/current-view/x-offset-m", true);
current_y_offs = fgGetNode("/sim/current-view/y-offset-m", true);
current_z_offs = fgGetNode("/sim/current-view/z-offset-m", true);
target_x_offs = fgGetNode("/sim/current-view/target-x-offset-m", true);
target_y_offs = fgGetNode("/sim/current-view/target-y-offset-m", true);
target_z_offs = fgGetNode("/sim/current-view/target-z-offset-m", true);
}
void
@ -160,39 +134,12 @@ FGViewMgr::do_bind()
{
// these are bound to the current view properties
_tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
// _tiedProperties.Tie("heading-offset-deg", this,
// &FGViewMgr::getViewHeadingOffset_deg,
// &FGViewMgr::setViewHeadingOffset_deg);
// fgSetArchivable("/sim/current-view/heading-offset-deg");
// _tiedProperties.Tie("goal-heading-offset-deg", this,
// &FGViewMgr::getViewGoalHeadingOffset_deg,
// &FGViewMgr::setViewGoalHeadingOffset_deg);
//fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
#if 0
_tiedProperties.Tie("pitch-offset-deg", this,
&FGViewMgr::getViewPitchOffset_deg,
&FGViewMgr::setViewPitchOffset_deg);
fgSetArchivable("/sim/current-view/pitch-offset-deg");
_tiedProperties.Tie("goal-pitch-offset-deg", this,
&FGViewMgr::getGoalViewPitchOffset_deg,
&FGViewMgr::setGoalViewPitchOffset_deg);
fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
_tiedProperties.Tie("roll-offset-deg", this,
&FGViewMgr::getViewRollOffset_deg,
&FGViewMgr::setViewRollOffset_deg);
fgSetArchivable("/sim/current-view/roll-offset-deg");
_tiedProperties.Tie("goal-roll-offset-deg", this,
&FGViewMgr::getGoalViewRollOffset_deg,
&FGViewMgr::setGoalViewRollOffset_deg);
fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
#endif
_tiedProperties.Tie("view-number", this,
&FGViewMgr::getView, &FGViewMgr::setView);
SGPropertyNode* view_number =
_tiedProperties.getRoot()->getNode("view-number");
view_number->setAttribute(SGPropertyNode::ARCHIVE, false);
// Keep view on reset/reinit
view_number->setAttribute(SGPropertyNode::PRESERVE, true);
@ -257,9 +204,20 @@ FGViewMgr::do_bind()
void
FGViewMgr::unbind ()
{
flightgear::View* v = get_current_view();
if (v) {
v->unbind();
}
_tiedProperties.Untie();
config_list.clear();
view_number.clear();
target_x_offs.clear();
target_y_offs.clear();
target_z_offs.clear();
current_x_offs.clear();
current_y_offs.clear();
current_z_offs.clear();
}
void
@ -306,6 +264,8 @@ FGViewMgr::update (double dt)
}
}
// these properties aren't tied - manually propogate them to the
// currently active view
setViewXOffset_m(current_x_offs->getDoubleValue());
setViewYOffset_m(current_y_offs->getDoubleValue());
setViewZOffset_m(current_z_offs->getDoubleValue());
@ -340,56 +300,6 @@ FGViewMgr::update (double dt)
void
FGViewMgr::copyToCurrent()
{
if (!inited) {
return;
}
#if 0
SGPropertyNode *n = config_list[current];
fgSetString("/sim/current-view/name", n->getStringValue("name"));
fgSetString("/sim/current-view/type", n->getStringValue("type"));
// copy certain view config data for default values
fgSetDouble("/sim/current-view/config/heading-offset-deg",
n->getDoubleValue("config/default-heading-offset-deg"));
fgSetDouble("/sim/current-view/config/pitch-offset-deg",
n->getDoubleValue("config/pitch-offset-deg"));
fgSetDouble("/sim/current-view/config/roll-offset-deg",
n->getDoubleValue("config/roll-offset-deg"));
fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
n->getDoubleValue("config/default-field-of-view-deg"));
fgSetBool("/sim/current-view/config/from-model",
n->getBoolValue("config/from-model"));
#endif
// 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());
#if 0
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());
#endif
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());
fgSetBool("/sim/current-view/internal",
get_current_view()->getInternal());
}
void FGViewMgr::clear()