From 431e78cf09a06ddab65122afe73c1a53d4d65ca9 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 28 Sep 2003 08:38:48 +0000 Subject: [PATCH] Add the ability to set three levels of detail for static scenery using the property tree --- simgear/scene/model/animation.cxx | 48 +++++++++++++++++++++++++++---- simgear/scene/model/animation.hxx | 9 +++++- simgear/scene/model/model.cxx | 2 +- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/simgear/scene/model/animation.cxx b/simgear/scene/model/animation.cxx index 928d90f1..8988c339 100644 --- a/simgear/scene/model/animation.cxx +++ b/simgear/scene/model/animation.cxx @@ -97,7 +97,7 @@ set_scale (sgMat4 &matrix, double x, double y, double z) static void change_alpha( ssgBase *_branch, float _blend ) { - unsigned int i; + int i; for (i = 0; i < ((ssgBranch *)_branch)->getNumKids(); i++) change_alpha( ((ssgBranch *)_branch)->getKid(i), _blend ); @@ -214,19 +214,55 @@ SGNullAnimation::~SGNullAnimation () // Implementation of SGRangeAnimation //////////////////////////////////////////////////////////////////////// -SGRangeAnimation::SGRangeAnimation (SGPropertyNode_ptr props) - : SGAnimation(props, new ssgRangeSelector) +SGRangeAnimation::SGRangeAnimation (SGPropertyNode *prop_root, + SGPropertyNode_ptr props) + : SGAnimation(props, new ssgRangeSelector), + _min(0.0), _max(0.0) { - float ranges[] = { props->getFloatValue("min-m", 0), - props->getFloatValue("max-m", 5000) }; + float ranges[2]; + + SGPropertyNode_ptr node = props->getChild( "min-property" ); + if (node != 0) { + _min_prop = (SGPropertyNode *)prop_root->getNode(node->getStringValue(), true); + ranges[0] = _min_prop->getFloatValue(); + } else { + ranges[0] = _min = props->getFloatValue("min-m", 0); + } + node = props->getChild( "max-property" ); + if (node != 0) { + _max_prop = (SGPropertyNode *)prop_root->getNode(node->getStringValue(), true); + ranges[1] = _max_prop->getFloatValue(); + } else { + ranges[1] = _max = props->getFloatValue("max-m", 0); + } ((ssgRangeSelector *)_branch)->setRanges(ranges, 2); - } SGRangeAnimation::~SGRangeAnimation () { } +void +SGRangeAnimation::update() +{ + float ranges[2]; + bool upd = false; + if (_min_prop != 0) { + ranges[0] = _min_prop->getFloatValue(); + upd = true; + } else { + ranges[0] = _min; + } + if (_max_prop != 0) { + ranges[1] = _max_prop->getFloatValue(); + upd = true; + } else { + ranges[1] = _max; + } + if (upd) + ((ssgRangeSelector *)_branch)->setRanges(ranges, 2); +} + //////////////////////////////////////////////////////////////////////// diff --git a/simgear/scene/model/animation.hxx b/simgear/scene/model/animation.hxx index c5079b59..609c33d5 100644 --- a/simgear/scene/model/animation.hxx +++ b/simgear/scene/model/animation.hxx @@ -99,8 +99,15 @@ public: class SGRangeAnimation : public SGAnimation { public: - SGRangeAnimation (SGPropertyNode_ptr props); + SGRangeAnimation (SGPropertyNode *prop_root, + SGPropertyNode_ptr props); virtual ~SGRangeAnimation (); + virtual void update(); +private: + SGPropertyNode_ptr _min_prop; + SGPropertyNode_ptr _max_prop; + float _min; + float _max; }; diff --git a/simgear/scene/model/model.cxx b/simgear/scene/model/model.cxx index 9d387ae2..757c3d2c 100644 --- a/simgear/scene/model/model.cxx +++ b/simgear/scene/model/model.cxx @@ -107,7 +107,7 @@ sgMakeAnimation( ssgBranch * model, if (!strcmp("none", type)) { animation = new SGNullAnimation(node); } else if (!strcmp("range", type)) { - animation = new SGRangeAnimation(node); + animation = new SGRangeAnimation(prop_root, node); } else if (!strcmp("billboard", type)) { animation = new SGBillboardAnimation(node); } else if (!strcmp("select", type)) { -- 2.39.5