From: James Turner Date: Sun, 17 Jan 2016 21:13:42 +0000 (-0600) Subject: View can created itself from config properties X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d4d2121641dc54a48425e92f93e4c864995c8ba9;p=flightgear.git View can created itself from config properties - use in view manager - make View constructor private --- diff --git a/src/Viewer/viewer.cxx b/src/Viewer/viewer.cxx index cde4ca2d6..583f57c73 100644 --- a/src/Viewer/viewer.cxx +++ b/src/Viewer/viewer.cxx @@ -109,6 +109,70 @@ View::View( ViewType Type, bool from_model, int from_model_index, // a reasonable guess for init, so that the math doesn't blow up } +View* View::createFromProperties(SGPropertyNode_ptr config) +{ + double aspect_ratio_multiplier + = fgGetDouble("/sim/current-view/aspect-ratio-multiplier"); + + // find out if this is an internal view (e.g. in cockpit, low near plane) + // 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. + + // find out if this is a model we are looking from... + bool from_model = config->getBoolValue("from-model"); + int from_model_index = config->getIntValue("from-model-idx"); + + double x_offset_m = config->getDoubleValue("x-offset-m"); + double y_offset_m = config->getDoubleValue("y-offset-m"); + 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); + double pitch_offset_deg = config->getDoubleValue("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); + + double fov_deg = config->getDoubleValue("default-field-of-view-deg"); + double near_m = config->getDoubleValue("ground-level-nearplane-m"); + + // supporting two types "lookat" = 1 and "lookfrom" = 0 + const char *type = config->getParent()->getStringValue("type"); + if (!strcmp(type, "lookat")) { + bool at_model = config->getBoolValue("at-model"); + int at_model_index = config->getIntValue("at-model-idx"); + + double damp_roll = config->getDoubleValue("at-model-roll-damping"); + double damp_pitch = config->getDoubleValue("at-model-pitch-damping"); + double damp_heading = config->getDoubleValue("at-model-heading-damping"); + + double target_x_offset_m = config->getDoubleValue("target-x-offset-m"); + 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, + at_model, at_model_index, + damp_roll, damp_pitch, damp_heading, + x_offset_m, y_offset_m,z_offset_m, + heading_offset_deg, pitch_offset_deg, + roll_offset_deg, fov_deg, aspect_ratio_multiplier, + 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, + false, 0, 0.0, 0.0, 0.0, + x_offset_m, y_offset_m, z_offset_m, + heading_offset_deg, pitch_offset_deg, + roll_offset_deg, fov_deg, aspect_ratio_multiplier, + 0, 0, 0, near_m, internal ); + } + +} + // Destructor View::~View( void ) { diff --git a/src/Viewer/viewer.hxx b/src/Viewer/viewer.hxx index 9bdfc6ee1..c342284ae 100644 --- a/src/Viewer/viewer.hxx +++ b/src/Viewer/viewer.hxx @@ -30,6 +30,8 @@ #include #include + +#include #include #include @@ -56,17 +58,7 @@ public: FG_LOOKAT = 1 }; - - // Constructor - View( ViewType Type, bool from_model, int from_model_index, - bool at_model, int at_model_index, - double damp_roll, double damp_pitch, double damp_heading, - double x_offset_m, double y_offset_m, double z_offset_m, - double heading_offset_deg, double pitch_offset_deg, - double roll_offset_deg, - double fov_deg, double aspect_ratio_multiplier, - double target_x_offset_m, double target_y_offset_m, - double target_z_offset_m, double near_m, bool internal ); + static View* createFromProperties(SGPropertyNode_ptr props); // Destructor virtual ~View(); @@ -238,6 +230,18 @@ public: private: + // Constructor + View( ViewType Type, bool from_model, int from_model_index, + bool at_model, int at_model_index, + double damp_roll, double damp_pitch, double damp_heading, + double x_offset_m, double y_offset_m, double z_offset_m, + double heading_offset_deg, double pitch_offset_deg, + double roll_offset_deg, + double fov_deg, double aspect_ratio_multiplier, + double target_x_offset_m, double target_y_offset_m, + double target_z_offset_m, double near_m, bool internal ); + + ////////////////////////////////////////////////////////////////// // private data // ////////////////////////////////////////////////////////////////// diff --git a/src/Viewer/viewmgr.cxx b/src/Viewer/viewmgr.cxx index f9e9e6ae5..4bf934383 100644 --- a/src/Viewer/viewmgr.cxx +++ b/src/Viewer/viewmgr.cxx @@ -74,69 +74,15 @@ FGViewMgr::init () target_y_offs = fgGetNode("/sim/current-view/target-y-offset-m", true); target_z_offs = fgGetNode("/sim/current-view/target-z-offset-m", true); - double aspect_ratio_multiplier - = fgGetDouble("/sim/current-view/aspect-ratio-multiplier"); for (unsigned int i = 0; i < config_list.size(); i++) { SGPropertyNode *n = config_list[i]; SGPropertyNode *config = n->getChild("config", 0, true); - // find out if this is an internal view (e.g. in cockpit, low near plane) - bool internal = n->getBoolValue("internal", false); - - // FIXME: - // this is assumed to be an aircraft model...we will need to read - // model-from-type as well. - - // find out if this is a model we are looking from... - bool from_model = config->getBoolValue("from-model"); - int from_model_index = config->getIntValue("from-model-idx"); - - double x_offset_m = config->getDoubleValue("x-offset-m"); - double y_offset_m = config->getDoubleValue("y-offset-m"); - 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); - double pitch_offset_deg = config->getDoubleValue("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); - - double fov_deg = config->getDoubleValue("default-field-of-view-deg"); - double near_m = config->getDoubleValue("ground-level-nearplane-m"); - - // supporting two types "lookat" = 1 and "lookfrom" = 0 - const char *type = n->getStringValue("type"); - if (!strcmp(type, "lookat")) { - - bool at_model = config->getBoolValue("at-model"); - int at_model_index = config->getIntValue("at-model-idx"); - - double damp_roll = config->getDoubleValue("at-model-roll-damping"); - double damp_pitch = config->getDoubleValue("at-model-pitch-damping"); - double damp_heading = config->getDoubleValue("at-model-heading-damping"); - - double target_x_offset_m = config->getDoubleValue("target-x-offset-m"); - double target_y_offset_m = config->getDoubleValue("target-y-offset-m"); - double target_z_offset_m = config->getDoubleValue("target-z-offset-m"); - - add_view(new flightgear::View ( flightgear::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, - heading_offset_deg, pitch_offset_deg, - roll_offset_deg, fov_deg, aspect_ratio_multiplier, - target_x_offset_m, target_y_offset_m, - target_z_offset_m, near_m, internal )); - } else { - add_view(new flightgear::View ( flightgear::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, - roll_offset_deg, fov_deg, aspect_ratio_multiplier, - 0, 0, 0, near_m, internal )); - } + flightgear::View* v = flightgear::View::createFromProperties(config); + if (v) { + add_view(v); + } } copyToCurrent();