Start moving view-manager logic into View
- work in progress, goal is to make copyToCurrent and most of the bind/unbind logic sink into each specific View, avoiding all the null pointer checks in view manager.
This commit is contained in:
parent
8c918c6cec
commit
655ac851e0
4 changed files with 137 additions and 138 deletions
|
@ -78,7 +78,7 @@ View::View( ViewType Type, bool from_model, int from_model_index,
|
|||
_dampFactor = SGVec3d::zeros();
|
||||
_dampOutput = SGVec3d::zeros();
|
||||
_dampTarget = SGVec3d::zeros();
|
||||
|
||||
|
||||
if (damp_roll > 0.0)
|
||||
_dampFactor[0] = 1.0 / pow(10.0, fabs(damp_roll));
|
||||
if (damp_pitch > 0.0)
|
||||
|
@ -95,12 +95,19 @@ View::View( ViewType Type, bool from_model, int from_model_index,
|
|||
_goal_heading_offset_deg = heading_offset_deg;
|
||||
_goal_pitch_offset_deg = pitch_offset_deg;
|
||||
_goal_roll_offset_deg = roll_offset_deg;
|
||||
|
||||
_configHeadingOffsetDeg = heading_offset_deg;
|
||||
_configPitchOffsetDeg = pitch_offset_deg;
|
||||
_configRollOffsetDeg = roll_offset_deg;
|
||||
|
||||
if (fov_deg > 0) {
|
||||
_fov_deg = fov_deg;
|
||||
} else {
|
||||
_fov_deg = 55;
|
||||
}
|
||||
|
||||
_configFOV_deg = _fov_deg;
|
||||
|
||||
_aspect_ratio_multiplier = aspect_ratio_multiplier;
|
||||
_target_offset_m.x() = target_x_offset_m;
|
||||
_target_offset_m.y() = target_y_offset_m;
|
||||
|
@ -118,6 +125,7 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
|
|||
// FIXME : should be a child of config
|
||||
bool internal = config->getParent()->getBoolValue("internal", false);
|
||||
|
||||
|
||||
// FIXME:
|
||||
// this is assumed to be an aircraft model...we will need to read
|
||||
// model-from-type as well.
|
||||
|
@ -131,15 +139,16 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
|
|||
double z_offset_m = config->getDoubleValue("z-offset-m");
|
||||
|
||||
double heading_offset_deg = config->getDoubleValue("heading-offset-deg");
|
||||
config->setDoubleValue("heading-offset-deg", heading_offset_deg);
|
||||
// config->setDoubleValue("heading-offset-deg", heading_offset_deg);
|
||||
double pitch_offset_deg = config->getDoubleValue("pitch-offset-deg");
|
||||
config->setDoubleValue("pitch-offset-deg", pitch_offset_deg);
|
||||
// config->setDoubleValue("pitch-offset-deg", pitch_offset_deg);
|
||||
double roll_offset_deg = config->getDoubleValue("roll-offset-deg");
|
||||
config->setDoubleValue("roll-offset-deg", roll_offset_deg);
|
||||
// config->setDoubleValue("roll-offset-deg", roll_offset_deg);
|
||||
|
||||
double fov_deg = config->getDoubleValue("default-field-of-view-deg");
|
||||
double near_m = config->getDoubleValue("ground-level-nearplane-m");
|
||||
|
||||
View* v = 0;
|
||||
// supporting two types "lookat" = 1 and "lookfrom" = 0
|
||||
const char *type = config->getParent()->getStringValue("type");
|
||||
if (!strcmp(type, "lookat")) {
|
||||
|
@ -154,7 +163,7 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
|
|||
double target_y_offset_m = config->getDoubleValue("target-y-offset-m");
|
||||
double target_z_offset_m = config->getDoubleValue("target-z-offset-m");
|
||||
|
||||
return new View ( FG_LOOKAT, from_model, from_model_index,
|
||||
v = new View ( FG_LOOKAT, from_model, from_model_index,
|
||||
at_model, at_model_index,
|
||||
damp_roll, damp_pitch, damp_heading,
|
||||
x_offset_m, y_offset_m,z_offset_m,
|
||||
|
@ -163,7 +172,7 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
|
|||
target_x_offset_m, target_y_offset_m,
|
||||
target_z_offset_m, near_m, internal );
|
||||
} else {
|
||||
return new View ( FG_LOOKFROM, from_model, from_model_index,
|
||||
v = new View ( FG_LOOKFROM, from_model, from_model_index,
|
||||
false, 0, 0.0, 0.0, 0.0,
|
||||
x_offset_m, y_offset_m, z_offset_m,
|
||||
heading_offset_deg, pitch_offset_deg,
|
||||
|
@ -171,6 +180,11 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
|
|||
0, 0, 0, near_m, internal );
|
||||
}
|
||||
|
||||
v->_name = config->getParent()->getStringValue("name");
|
||||
v->_typeString = type;
|
||||
v->_configHeadingOffsetDeg = config->getDoubleValue("default-heading-offset-deg");
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
|
@ -186,11 +200,52 @@ View::init ()
|
|||
void
|
||||
View::bind ()
|
||||
{
|
||||
_tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
|
||||
_tiedProperties.Tie("heading-offset-deg", this,
|
||||
&View::getHeadingOffset_deg,
|
||||
&View::setHeadingOffset_deg_property);
|
||||
|
||||
fgSetArchivable("/sim/current-view/heading-offset-deg");
|
||||
|
||||
_tiedProperties.Tie("goal-heading-offset-deg", this,
|
||||
&View::getGoalHeadingOffset_deg,
|
||||
&View::setGoalHeadingOffset_deg);
|
||||
|
||||
fgSetArchivable("/sim/current-view/goal-heading-offset-deg");
|
||||
|
||||
_tiedProperties.Tie("pitch-offset-deg", this,
|
||||
&View::getPitchOffset_deg,
|
||||
&View::setPitchOffset_deg_property);
|
||||
fgSetArchivable("/sim/current-view/pitch-offset-deg");
|
||||
_tiedProperties.Tie("goal-pitch-offset-deg", this,
|
||||
&View::getGoalPitchOffset_deg,
|
||||
&View::setGoalPitchOffset_deg);
|
||||
fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
|
||||
_tiedProperties.Tie("roll-offset-deg", this,
|
||||
&View::getRollOffset_deg,
|
||||
&View::setRollOffset_deg_property);
|
||||
fgSetArchivable("/sim/current-view/roll-offset-deg");
|
||||
_tiedProperties.Tie("goal-roll-offset-deg", this,
|
||||
&View::getGoalRollOffset_deg,
|
||||
&View::setGoalRollOffset_deg);
|
||||
fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
|
||||
|
||||
|
||||
_tiedProperties.getRoot()->setStringValue("name", _name);
|
||||
_tiedProperties.getRoot()->setStringValue("type", _typeString);
|
||||
|
||||
SGPropertyNode_ptr config = _tiedProperties.getRoot()->getChild("config", 0, true);
|
||||
config->setBoolValue("from-model", _from_model);
|
||||
config->setDoubleValue("heading-offset-deg", _configHeadingOffsetDeg);
|
||||
config->setDoubleValue("pitch-offset-deg", _configPitchOffsetDeg);
|
||||
config->setDoubleValue("roll-offset-deg", _configRollOffsetDeg);
|
||||
config->setDoubleValue("default-field-of-view-deg", _configFOV_deg);
|
||||
}
|
||||
|
||||
void
|
||||
View::unbind ()
|
||||
{
|
||||
_tiedProperties.Untie();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -361,6 +416,27 @@ View::setHeadingOffset_deg (double heading_offset_deg)
|
|||
_heading_offset_deg = heading_offset_deg;
|
||||
}
|
||||
|
||||
void
|
||||
View::setHeadingOffset_deg_property (double heading_offset_deg)
|
||||
{
|
||||
setHeadingOffset_deg(heading_offset_deg);
|
||||
setGoalHeadingOffset_deg(heading_offset_deg);
|
||||
}
|
||||
|
||||
void
|
||||
View::setPitchOffset_deg_property (double pitch_offset_deg)
|
||||
{
|
||||
setPitchOffset_deg(pitch_offset_deg);
|
||||
setGoalPitchOffset_deg(pitch_offset_deg);
|
||||
}
|
||||
|
||||
void
|
||||
View::setRollOffset_deg_property (double roll_offset_deg)
|
||||
{
|
||||
setRollOffset_deg(roll_offset_deg);
|
||||
setGoalRollOffset_deg(roll_offset_deg);
|
||||
}
|
||||
|
||||
void
|
||||
View::setGoalRollOffset_deg (double goal_roll_offset_deg)
|
||||
{
|
||||
|
@ -397,7 +473,7 @@ View::setGoalHeadingOffset_deg (double goal_heading_offset_deg)
|
|||
_goal_heading_offset_deg = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_goal_heading_offset_deg = goal_heading_offset_deg;
|
||||
while ( _goal_heading_offset_deg < 0.0 ) {
|
||||
_goal_heading_offset_deg += 360;
|
||||
|
@ -416,8 +492,8 @@ View::setOrientationOffsets (double roll_offset_deg, double pitch_offset_deg, do
|
|||
_heading_offset_deg = heading_offset_deg;
|
||||
}
|
||||
|
||||
// recalc() is done every time one of the setters is called (making the
|
||||
// cached data "dirty") on the next "get". It calculates all the outputs
|
||||
// recalc() is done every time one of the setters is called (making the
|
||||
// cached data "dirty") on the next "get". It calculates all the outputs
|
||||
// for viewer.
|
||||
void
|
||||
View::recalc ()
|
||||
|
@ -568,28 +644,28 @@ View::updateDampOutput(double dt)
|
|||
last_view = this;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const double interval = 0.01;
|
||||
while (dt > interval) {
|
||||
|
||||
|
||||
for (unsigned int i=0; i<3; ++i) {
|
||||
if (_dampFactor[i] <= 0.0) {
|
||||
// axis is un-damped, set output to target directly
|
||||
_dampOutput[i] = _dampTarget[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
double d = _dampOutput[i] - _dampTarget[i];
|
||||
if (d > 180.0) {
|
||||
_dampOutput[i] -= 360.0;
|
||||
} else if (d < -180.0) {
|
||||
_dampOutput[i] += 360.0;
|
||||
}
|
||||
|
||||
_dampOutput[i] = (_dampTarget[i] * _dampFactor[i]) +
|
||||
|
||||
_dampOutput[i] = (_dampTarget[i] * _dampFactor[i]) +
|
||||
(_dampOutput[i] * (1.0 - _dampFactor[i]));
|
||||
} // of axis iteration
|
||||
|
||||
|
||||
dt -= interval;
|
||||
} // of dt subdivision by interval
|
||||
}
|
||||
|
@ -626,7 +702,7 @@ View::get_v_fov()
|
|||
double aspectRatio = get_aspect_ratio();
|
||||
switch (_scaling_type) {
|
||||
case FG_SCALING_WIDTH: // h_fov == fov
|
||||
return
|
||||
return
|
||||
atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
|
||||
* (aspectRatio*_aspect_ratio_multiplier))
|
||||
* SG_RADIANS_TO_DEGREES * 2;
|
||||
|
@ -651,7 +727,7 @@ void
|
|||
View::update (double dt)
|
||||
{
|
||||
updateDampOutput(dt);
|
||||
|
||||
|
||||
int i;
|
||||
int dt_ms = int(dt * 1000);
|
||||
for ( i = 0; i < dt_ms; i++ ) {
|
||||
|
@ -732,4 +808,3 @@ double View::get_aspect_ratio() const
|
|||
{
|
||||
return flightgear::CameraGroup::getDefault()->getMasterAspectRatio();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <simgear/constants.h>
|
||||
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/props/tiedpropertylist.hxx>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
|
||||
|
@ -242,13 +243,21 @@ private:
|
|||
|
||||
void set_clean() { _dirty = false; }
|
||||
|
||||
void setHeadingOffset_deg_property (double heading_offset_deg);
|
||||
void setPitchOffset_deg_property(double pitch_offset_deg);
|
||||
void setRollOffset_deg_property(double roll_offset_deg);
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// private data //
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string _name, _typeString;
|
||||
|
||||
// flag forcing a recalc of derived view parameters
|
||||
bool _dirty;
|
||||
|
||||
simgear::TiedPropertyList _tiedProperties;
|
||||
|
||||
SGQuatd mViewOrientation;
|
||||
SGQuatd mViewOffsetOr;
|
||||
SGVec3d _absolute_view_pos;
|
||||
|
@ -263,6 +272,10 @@ private:
|
|||
double _target_pitch_deg;
|
||||
double _target_heading_deg;
|
||||
|
||||
double _configRollOffsetDeg,
|
||||
_configHeadingOffsetDeg,
|
||||
_configPitchOffsetDeg;
|
||||
|
||||
SGVec3d _dampTarget; ///< current target value we are damping towards
|
||||
SGVec3d _dampOutput; ///< current output of damping filter
|
||||
SGVec3d _dampFactor; ///< weighting of the damping filter
|
||||
|
@ -305,7 +318,7 @@ private:
|
|||
|
||||
// the nominal field of view (angle, in degrees)
|
||||
double _fov_deg;
|
||||
|
||||
double _configFOV_deg;
|
||||
// default = 1.0, this value is user configurable and is
|
||||
// multiplied into the aspect_ratio to get the actual vertical fov
|
||||
double _aspect_ratio_multiplier;
|
||||
|
|
|
@ -160,14 +160,15 @@ 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");
|
||||
// _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);
|
||||
|
@ -184,7 +185,8 @@ FGViewMgr::do_bind()
|
|||
&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 =
|
||||
|
@ -341,8 +343,10 @@ 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"));
|
||||
|
||||
|
@ -357,12 +361,13 @@ FGViewMgr::copyToCurrent()
|
|||
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",
|
||||
|
@ -375,6 +380,8 @@ FGViewMgr::copyToCurrent()
|
|||
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",
|
||||
|
@ -449,102 +456,6 @@ FGViewMgr::add_view( flightgear::View * v )
|
|||
views.push_back(v);
|
||||
v->init();
|
||||
}
|
||||
|
||||
double
|
||||
FGViewMgr::getViewHeadingOffset_deg () const
|
||||
{
|
||||
const flightgear::View * view = get_current_view();
|
||||
return (view == 0 ? 0 : view->getHeadingOffset_deg());
|
||||
}
|
||||
|
||||
void
|
||||
FGViewMgr::setViewHeadingOffset_deg (double offset)
|
||||
{
|
||||
flightgear::View * view = get_current_view();
|
||||
if (view != 0) {
|
||||
view->setGoalHeadingOffset_deg(offset);
|
||||
view->setHeadingOffset_deg(offset);
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
FGViewMgr::getViewGoalHeadingOffset_deg () const
|
||||
{
|
||||
const flightgear::View * view = get_current_view();
|
||||
return (view == 0 ? 0 : view->getGoalHeadingOffset_deg());
|
||||
}
|
||||
|
||||
void
|
||||
FGViewMgr::setViewGoalHeadingOffset_deg (double offset)
|
||||
{
|
||||
flightgear::View * view = get_current_view();
|
||||
if (view != 0)
|
||||
view->setGoalHeadingOffset_deg(offset);
|
||||
}
|
||||
|
||||
double
|
||||
FGViewMgr::getViewPitchOffset_deg () const
|
||||
{
|
||||
const flightgear::View * view = get_current_view();
|
||||
return (view == 0 ? 0 : view->getPitchOffset_deg());
|
||||
}
|
||||
|
||||
void
|
||||
FGViewMgr::setViewPitchOffset_deg (double tilt)
|
||||
{
|
||||
flightgear::View * view = get_current_view();
|
||||
if (view != 0) {
|
||||
view->setGoalPitchOffset_deg(tilt);
|
||||
view->setPitchOffset_deg(tilt);
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
FGViewMgr::getGoalViewPitchOffset_deg () const
|
||||
{
|
||||
const flightgear::View * view = get_current_view();
|
||||
return (view == 0 ? 0 : view->getGoalPitchOffset_deg());
|
||||
}
|
||||
|
||||
void
|
||||
FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
|
||||
{
|
||||
flightgear::View * view = get_current_view();
|
||||
if (view != 0)
|
||||
view->setGoalPitchOffset_deg(tilt);
|
||||
}
|
||||
|
||||
double
|
||||
FGViewMgr::getViewRollOffset_deg () const
|
||||
{
|
||||
const flightgear::View * view = get_current_view();
|
||||
return (view == 0 ? 0 : view->getRollOffset_deg());
|
||||
}
|
||||
|
||||
void
|
||||
FGViewMgr::setViewRollOffset_deg (double tilt)
|
||||
{
|
||||
flightgear::View * view = get_current_view();
|
||||
if (view != 0) {
|
||||
view->setGoalRollOffset_deg(tilt);
|
||||
view->setRollOffset_deg(tilt);
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
FGViewMgr::getGoalViewRollOffset_deg () const
|
||||
{
|
||||
const flightgear::View * view = get_current_view();
|
||||
return (view == 0 ? 0 : view->getGoalRollOffset_deg());
|
||||
}
|
||||
|
||||
void
|
||||
FGViewMgr::setGoalViewRollOffset_deg (double tilt)
|
||||
{
|
||||
flightgear::View * view = get_current_view();
|
||||
if (view != 0)
|
||||
view->setGoalRollOffset_deg(tilt);
|
||||
}
|
||||
|
||||
double
|
||||
FGViewMgr::getViewXOffset_m () const
|
||||
|
@ -694,11 +605,22 @@ FGViewMgr::setView (int newview)
|
|||
if (newview >= (int)views.size())
|
||||
newview = 0;
|
||||
|
||||
if (get_current_view()) {
|
||||
get_current_view()->unbind();
|
||||
}
|
||||
|
||||
// set new view
|
||||
current = newview;
|
||||
|
||||
if (get_current_view()) {
|
||||
get_current_view()->bind();
|
||||
}
|
||||
|
||||
// copy in view data
|
||||
copyToCurrent();
|
||||
|
||||
|
||||
|
||||
// force an update now, to avoid returning bogus data.
|
||||
// real fix would to be make all the accessors use the dirty mechanism
|
||||
// on FGViewer, so update() is a no-op.
|
||||
|
|
|
@ -89,18 +89,7 @@ private:
|
|||
void do_axes ();
|
||||
|
||||
// callbacks in manager to access viewer methods
|
||||
double getViewHeadingOffset_deg () const;
|
||||
void setViewHeadingOffset_deg (double offset);
|
||||
double getViewGoalHeadingOffset_deg () const;
|
||||
void setViewGoalHeadingOffset_deg (double offset);
|
||||
double getViewPitchOffset_deg () const;
|
||||
void setViewPitchOffset_deg (double tilt);
|
||||
double getGoalViewPitchOffset_deg () const;
|
||||
void setGoalViewRollOffset_deg (double tilt);
|
||||
double getViewRollOffset_deg () const;
|
||||
void setViewRollOffset_deg (double tilt);
|
||||
double getGoalViewRollOffset_deg () const;
|
||||
void setGoalViewPitchOffset_deg (double tilt);
|
||||
|
||||
double getViewXOffset_m () const;
|
||||
void setViewXOffset_m (double x);
|
||||
double getViewYOffset_m () const;
|
||||
|
|
Loading…
Add table
Reference in a new issue