Browse Source

Updated Node to include contribution of point light spheres into node bounding volume computation.

Steve Grenier 12 years ago
parent
commit
201710c4fd
3 changed files with 33 additions and 0 deletions
  1. 6 0
      gameplay/src/Light.cpp
  2. 26 0
      gameplay/src/Node.cpp
  3. 1 0
      gameplay/src/Node.h

+ 6 - 0
gameplay/src/Light.cpp

@@ -252,6 +252,9 @@ void Light::setRange(float range)
         GP_ERROR("Unsupported light type (%d).", _type);
         break;
     }
+
+    if (_node)
+        _node->setBoundsDirty();
 }
 
 float Light::getRangeInverse() const
@@ -300,6 +303,9 @@ void Light::setOuterAngle(float outerAngle)
 
     _spot->outerAngle = outerAngle;
     _spot->outerAngleCos = cos(outerAngle);
+
+    if (_node)
+        _node->setBoundsDirty();
 }
     
 float Light::getInnerAngleCos()  const

+ 26 - 0
gameplay/src/Node.cpp

@@ -126,6 +126,8 @@ void Node::addChild(Node* child)
 
     ++_childCount;
 
+    setBoundsDirty();
+
     if (_notifyHierarchyChanged)
     {
         hierarchyChanged();
@@ -768,6 +770,8 @@ void Node::setLight(Light* light)
             _light->addRef();
             _light->setNode(this);
         }
+
+        setBoundsDirty();
     }
 }
 
@@ -818,6 +822,8 @@ void Node::setTerrain(Terrain* terrain)
             _terrain->addRef();
             _terrain->setNode(this);
         }
+
+        setBoundsDirty();
     }
 }
 
@@ -874,6 +880,26 @@ const BoundingSphere& Node::getBoundingSphere() const
                 _bounds.merge(_model->getMesh()->getBoundingSphere());
             }
         }
+        if (_light)
+        {
+            switch (_light->getLightType())
+            {
+            case Light::POINT:
+                if (empty)
+                {
+                    _bounds.set(Vector3::zero(), _light->getRange());
+                    empty = false;
+                }
+                else
+                {
+                    _bounds.merge(BoundingSphere(Vector3::zero(), _light->getRange()));
+                }
+                break;
+            case Light::SPOT:
+                // TODO: Implement spot light bounds
+                break;
+            }
+        }
         if (empty)
         {
             // Empty bounding sphere, set the world translation with zero radius

+ 1 - 0
gameplay/src/Node.h

@@ -29,6 +29,7 @@ class Node : public Transform, public Ref
     friend class Scene;
     friend class Bundle;
     friend class MeshSkin;
+    friend class Light;
 
 public: