Browse Source

fixed culling node drawing

Ronen 8 years ago
parent
commit
7bf286dcdb
1 changed files with 21 additions and 7 deletions
  1. 21 7
      MonoGameSceneGraph/Source/Nodes/CullingNode.cs

+ 21 - 7
MonoGameSceneGraph/Source/Nodes/CullingNode.cs

@@ -64,19 +64,22 @@ namespace MonoGameSceneGraph
         /// </summary>
         /// </summary>
         public override void Draw()
         public override void Draw()
         {
         {
-            // if camera frustum is not defined, draw this node as a regular node
-            if (CameraFrustum == null)
+            // if not visible skip
+            if (!IsVisible)
             {
             {
-                base.Draw();
                 return;
                 return;
             }
             }
 
 
-            // if not visible stop here so we won't calculate bounding boxes etc.
-            if (!IsVisible)
+            // if camera frustum is not defined, draw this node as a regular node
+            if (CameraFrustum == null)
             {
             {
+                base.Draw();
                 return;
                 return;
             }
             }
 
 
+            // update transformations (only if needed, testing logic is inside)
+            UpdateTransformations();
+
             // check if need to recalculate bounding box
             // check if need to recalculate bounding box
             if (_isBoundingBoxDirty)
             if (_isBoundingBoxDirty)
             {
             {
@@ -85,13 +88,24 @@ namespace MonoGameSceneGraph
             }
             }
 
 
             // if this node is out of screen, don't draw it
             // if this node is out of screen, don't draw it
-            if (!_currBoundingBox.Intersects(CameraFrustum))
+            if (CameraFrustum.Contains(_currBoundingBox) == ContainmentType.Disjoint)
             {
             {
                 return;
                 return;
             }
             }
 
 
             // if got here it means this node is in screen and should be rendered. draw it.
             // if got here it means this node is in screen and should be rendered. draw it.
-            base.Draw();
+
+            // draw all child nodes
+            foreach (Node node in _childNodes)
+            {
+                node.Draw();
+            }
+
+            // draw all child entities
+            foreach (IEntity entity in _childEntities)
+            {
+                entity.Draw(this, _localTransform, _worldTransform);
+            }
         }
         }
     }
     }
 }
 }