Move data updating into the View class
This commit is contained in:
parent
7391b9d76a
commit
03d5e55b57
3 changed files with 86 additions and 32 deletions
|
@ -175,6 +175,9 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
|
||||||
roll_offset_deg, fov_deg, aspect_ratio_multiplier,
|
roll_offset_deg, fov_deg, aspect_ratio_multiplier,
|
||||||
target_x_offset_m, target_y_offset_m,
|
target_x_offset_m, target_y_offset_m,
|
||||||
target_z_offset_m, near_m, internal );
|
target_z_offset_m, near_m, internal );
|
||||||
|
if (!from_model) {
|
||||||
|
v->_targetProperties = PositionAttitudeProperties(config, "target-");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
v = 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,
|
false, 0, 0.0, 0.0, 0.0,
|
||||||
|
@ -184,6 +187,10 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
|
||||||
0, 0, 0, near_m, internal );
|
0, 0, 0, near_m, internal );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!from_model) {
|
||||||
|
v->_eyeProperties = PositionAttitudeProperties(config, "eye-");
|
||||||
|
}
|
||||||
|
|
||||||
v->_name = config->getParent()->getStringValue("name");
|
v->_name = config->getParent()->getStringValue("name");
|
||||||
v->_typeString = type;
|
v->_typeString = type;
|
||||||
v->_configHeadingOffsetDeg = config->getDoubleValue("default-heading-offset-deg");
|
v->_configHeadingOffsetDeg = config->getDoubleValue("default-heading-offset-deg");
|
||||||
|
@ -758,6 +765,32 @@ View::get_v_fov()
|
||||||
return 0.0;
|
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
|
void
|
||||||
View::update (double dt)
|
View::update (double dt)
|
||||||
{
|
{
|
||||||
|
@ -843,3 +876,31 @@ double View::get_aspect_ratio() const
|
||||||
{
|
{
|
||||||
return flightgear::CameraGroup::getDefault()->getMasterAspectRatio();
|
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());
|
||||||
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ public:
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void resetOffsetsAndFOV();
|
void resetOffsetsAndFOV();
|
||||||
|
void updateData();
|
||||||
|
|
||||||
ViewType getType() const { return _type; }
|
ViewType getType() const { return _type; }
|
||||||
void setType( int type );
|
void setType( int type );
|
||||||
|
@ -326,6 +327,27 @@ private:
|
||||||
// multiplied into the aspect_ratio to get the actual vertical fov
|
// multiplied into the aspect_ratio to get the actual vertical fov
|
||||||
double _aspect_ratio_multiplier;
|
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 //
|
// private functions //
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -232,37 +232,7 @@ FGViewMgr::update (double dt)
|
||||||
|
|
||||||
// Set up view location and orientation
|
// Set up view location and orientation
|
||||||
|
|
||||||
if (!config->getBoolValue("from-model")) {
|
currentView->updateData();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// these properties aren't tied - manually propogate them to the
|
// these properties aren't tied - manually propogate them to the
|
||||||
// currently active view
|
// currently active view
|
||||||
|
@ -300,6 +270,7 @@ FGViewMgr::update (double dt)
|
||||||
void
|
void
|
||||||
FGViewMgr::copyToCurrent()
|
FGViewMgr::copyToCurrent()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGViewMgr::clear()
|
void FGViewMgr::clear()
|
||||||
|
|
Loading…
Add table
Reference in a new issue