From 1e889c4d078d2a3455e97292512bb663a0b59fe3 Mon Sep 17 00:00:00 2001 From: Frederic Bouvier Date: Thu, 9 Feb 2012 00:04:02 +0100 Subject: [PATCH] Implement point light --- simgear/scene/model/SGLightAnimation.cxx | 39 ++++++++++++++++++++++-- simgear/scene/model/animation.hxx | 1 + 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/simgear/scene/model/SGLightAnimation.cxx b/simgear/scene/model/SGLightAnimation.cxx index e4442ead..108cd6d1 100644 --- a/simgear/scene/model/SGLightAnimation.cxx +++ b/simgear/scene/model/SGLightAnimation.cxx @@ -44,6 +44,7 @@ SGLightAnimation::SGLightAnimation(const SGPropertyNode* configNode, const string &path, int i) : SGAnimation(configNode, modelRoot) { + _light_type = getConfig()->getStringValue("light-type"); _position = SGVec3d( getConfig()->getDoubleValue("position/x"), getConfig()->getDoubleValue("position/y"), getConfig()->getDoubleValue("position/z") ); _direction = SGVec3d( getConfig()->getDoubleValue("direction/x"), getConfig()->getDoubleValue("direction/y"), getConfig()->getDoubleValue("direction/z") ); double l = length(_direction); @@ -73,8 +74,7 @@ SGLightAnimation::install(osg::Node& node) { SGAnimation::install(node); - std::string light_type = getConfig()->getStringValue("light-type"); - if (light_type == "spot") { + if (_light_type == "spot") { simgear::Effect* effect = 0; EffectMap::iterator iter = lightEffectMap.find(_key); @@ -100,6 +100,41 @@ SGLightAnimation::install(osg::Node& node) effect = iter->second.get(); } + node.setNodeMask( simgear::MODELLIGHT_BIT ); + simgear::EffectGeode* geode = dynamic_cast(&node); + if (geode == 0) { + osg::Group* grp = node.asGroup(); + if (grp != 0) { + for (size_t i=0; igetNumChildren(); ++i) { + geode = dynamic_cast(grp->getChild(i)); + if (geode) + geode->setEffect(effect); + } + } + } + } + else if (_light_type == "point") { + + simgear::Effect* effect = 0; + EffectMap::iterator iter = lightEffectMap.find(_key); + if (iter == lightEffectMap.end()) { + SGPropertyNode_ptr effectProp = new SGPropertyNode; + makeChild(effectProp, "inherits-from")->setStringValue("Effects/light-point"); + SGPropertyNode* params = makeChild(effectProp, "parameters"); + params->getNode("light-spot/position",true)->setValue(SGVec4d(_position.x(),_position.y(),_position.z(),1.0)); + params->getNode("light-spot/ambient",true)->setValue(_ambient); + params->getNode("light-spot/diffuse",true)->setValue(_diffuse); + params->getNode("light-spot/specular",true)->setValue(_specular); + params->getNode("light-spot/attenuation",true)->setValue(_attenuation); + params->getNode("light-spot/near",true)->setValue(_near); + params->getNode("light-spot/far",true)->setValue(_far); + + effect = simgear::makeEffect(effectProp, true); + lightEffectMap.insert(EffectMap::value_type(_key, effect)); + } else { + effect = iter->second.get(); + } + node.setNodeMask( simgear::MODELLIGHT_BIT ); simgear::EffectGeode* geode = dynamic_cast(&node); if (geode == 0) { diff --git a/simgear/scene/model/animation.hxx b/simgear/scene/model/animation.hxx index 331ff3cf..31696192 100644 --- a/simgear/scene/model/animation.hxx +++ b/simgear/scene/model/animation.hxx @@ -357,6 +357,7 @@ public: virtual osg::Group* createAnimationGroup(osg::Group& parent); virtual void install(osg::Node& node); private: + string _light_type; SGVec3d _position; SGVec3d _direction; SGVec4d _ambient; -- 2.39.5