]> git.mxchange.org Git - simgear.git/commitdiff
Implement point light
authorFrederic Bouvier <fredfgfs01@free.fr>
Wed, 8 Feb 2012 23:04:02 +0000 (00:04 +0100)
committerFrederic Bouvier <fredfgfs01@free.fr>
Sun, 4 Mar 2012 19:21:52 +0000 (20:21 +0100)
simgear/scene/model/SGLightAnimation.cxx
simgear/scene/model/animation.hxx

index e4442ead4a340345eb0e02b422def4178f20e5e2..108cd6d10699947ea74ba20444f2150dddcea6ad 100644 (file)
@@ -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<simgear::EffectGeode*>(&node);
+        if (geode == 0) {
+            osg::Group* grp = node.asGroup();
+            if (grp != 0) {
+                for (size_t i=0; i<grp->getNumChildren(); ++i) {
+                    geode = dynamic_cast<simgear::EffectGeode*>(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<simgear::EffectGeode*>(&node);
         if (geode == 0) {
index 331ff3cf1886137b180c057d5e7ca96adb6981e4..31696192a44f4fba2c829669d807f2927f57abd4 100644 (file)
@@ -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;