_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)
_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;
// 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.
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")) {
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,
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,
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;
}
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
_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)
{
_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;
_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 ()
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
}
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;
View::update (double dt)
{
updateDampOutput(dt);
-
+
int i;
int dt_ms = int(dt * 1000);
for ( i = 0; i < dt_ms; i++ ) {
{
return flightgear::CameraGroup::getDefault()->getMasterAspectRatio();
}
-
{
// 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);
&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 =
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"));
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()->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",
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
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.