1
0
Fork 0

Move data updating into the View class

This commit is contained in:
James Turner 2016-01-17 21:21:20 -05:00
parent 7391b9d76a
commit 03d5e55b57
3 changed files with 86 additions and 32 deletions

View file

@ -175,6 +175,9 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
roll_offset_deg, fov_deg, aspect_ratio_multiplier,
target_x_offset_m, target_y_offset_m,
target_z_offset_m, near_m, internal );
if (!from_model) {
v->_targetProperties = PositionAttitudeProperties(config, "target-");
}
} else {
v = new View ( FG_LOOKFROM, from_model, from_model_index,
false, 0, 0.0, 0.0, 0.0,
@ -184,6 +187,10 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
0, 0, 0, near_m, internal );
}
if (!from_model) {
v->_eyeProperties = PositionAttitudeProperties(config, "eye-");
}
v->_name = config->getParent()->getStringValue("name");
v->_typeString = type;
v->_configHeadingOffsetDeg = config->getDoubleValue("default-heading-offset-deg");
@ -758,6 +765,32 @@ View::get_v_fov()
return 0.0;
}
void
View::updateData()
{
if (!_from_model) {
SGVec3d pos = _eyeProperties.position();
SGVec3d att = _eyeProperties.attitude();
setPosition(pos.x(), pos.y(), pos.z());
setOrientation(att[2], att[1], att[0]);
} else {
set_dirty();
}
// if lookat (type 1) then get target data...
if (getType() == FG_LOOKAT) {
if (!_from_model) {
SGVec3d pos = _targetProperties.position();
SGVec3d att = _targetProperties.attitude();
setTargetPosition(pos.x(), pos.y(), pos.z());
setTargetOrientation(att[2], att[1], att[0]);
} else {
set_dirty();
}
}
}
void
View::update (double dt)
{
@ -843,3 +876,31 @@ double View::get_aspect_ratio() const
{
return flightgear::CameraGroup::getDefault()->getMasterAspectRatio();
}
View::PositionAttitudeProperties::PositionAttitudeProperties()
{
}
View::PositionAttitudeProperties::PositionAttitudeProperties(SGPropertyNode_ptr parent, const std::string& prefix)
{
_lonProp = parent->getNode(prefix + "lon-deg-path", 0, true);
_latProp = parent->getNode(prefix + "lat-deg-path", 0, true);
_altProp = parent->getNode(prefix + "alt-ft-path", 0, true);
_headingProp = parent->getNode(prefix + "heading-deg-path", 0, true);
_pitchProp = parent->getNode(prefix + "pitch-deg-path", 0, true);
_rollProp = parent->getNode(prefix + "roll-deg-path", 0, true);
}
SGVec3d View::PositionAttitudeProperties::position() const
{
return SGVec3d(_lonProp->getDoubleValue(),
_latProp->getDoubleValue(),
_altProp->getDoubleValue());
}
SGVec3d View::PositionAttitudeProperties::attitude() const
{
return SGVec3d(_headingProp->getDoubleValue(),
_pitchProp->getDoubleValue(),
_rollProp->getDoubleValue());
}

View file

@ -79,7 +79,8 @@ public:
//////////////////////////////////////////////////////////////////////
void resetOffsetsAndFOV();
void updateData();
ViewType getType() const { return _type; }
void setType( int type );
@ -326,6 +327,27 @@ private:
// multiplied into the aspect_ratio to get the actual vertical fov
double _aspect_ratio_multiplier;
class PositionAttitudeProperties
{
public:
PositionAttitudeProperties();
PositionAttitudeProperties(SGPropertyNode_ptr parent, const std::string& prefix);
SGVec3d position() const;
SGVec3d attitude() const; // as heading pitch roll
private:
SGPropertyNode_ptr _lonProp,
_latProp,
_altProp,
_headingProp,
_pitchProp,
_rollProp;
};
PositionAttitudeProperties _eyeProperties;
PositionAttitudeProperties _targetProperties;
//////////////////////////////////////////////////////////////////
// private functions //
//////////////////////////////////////////////////////////////////

View file

@ -232,37 +232,7 @@ FGViewMgr::update (double dt)
// Set up view location and orientation
if (!config->getBoolValue("from-model")) {
lon_deg = fgGetDouble(config->getStringValue("eye-lon-deg-path"));
lat_deg = fgGetDouble(config->getStringValue("eye-lat-deg-path"));
alt_ft = fgGetDouble(config->getStringValue("eye-alt-ft-path"));
roll_deg = fgGetDouble(config->getStringValue("eye-roll-deg-path"));
pitch_deg = fgGetDouble(config->getStringValue("eye-pitch-deg-path"));
heading_deg = fgGetDouble(config->getStringValue("eye-heading-deg-path"));
currentView->setPosition(lon_deg, lat_deg, alt_ft);
currentView->setOrientation(roll_deg, pitch_deg, heading_deg);
} else {
// force recalc in viewer
currentView->set_dirty();
}
// if lookat (type 1) then get target data...
if (currentView->getType() == flightgear::View::FG_LOOKAT) {
if (!config->getBoolValue("from-model")) {
lon_deg = fgGetDouble(config->getStringValue("target-lon-deg-path"));
lat_deg = fgGetDouble(config->getStringValue("target-lat-deg-path"));
alt_ft = fgGetDouble(config->getStringValue("target-alt-ft-path"));
roll_deg = fgGetDouble(config->getStringValue("target-roll-deg-path"));
pitch_deg = fgGetDouble(config->getStringValue("target-pitch-deg-path"));
heading_deg = fgGetDouble(config->getStringValue("target-heading-deg-path"));
currentView->setTargetPosition(lon_deg, lat_deg, alt_ft);
currentView->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
} else {
currentView->set_dirty();
}
}
currentView->updateData();
// these properties aren't tied - manually propogate them to the
// currently active view
@ -300,6 +270,7 @@ FGViewMgr::update (double dt)
void
FGViewMgr::copyToCurrent()
{
}
void FGViewMgr::clear()