public void Cull(Camera cam) { Object3D obj; int i; cam.Reset(); if (m_Objects.Count > 0) { try { switch (cam.CheckFrustum(m_vPosition, m_fRadius)) { case Camera.CullState.AllInside: for (i = 0; i < m_Objects.Count; i++) { obj = (Object3D)m_Objects.GetByIndex(i); obj.Range = cam.GetDistance(obj); obj.Culled = false; m_Objects.SetByIndex(i, obj); cam.AddVisibleObject(obj); } break; case Camera.CullState.AllOutside: if (m_Parent == null) // i.e. if this is the root quad { goto case Camera.CullState.PartiallyIn; } // do nothing since the default state is true (reset after each render) break; case Camera.CullState.PartiallyIn: if (m_NorthEast != null) { m_NorthEast.Cull(cam); m_NorthWest.Cull(cam); m_SouthWest.Cull(cam); m_SouthEast.Cull(cam); } else // if partially in at the bottom level treat as in { for (i = 0; i < m_Objects.Count; i++) { obj = (Object3D)m_Objects.GetByIndex(i); obj.Culled = false; m_Objects.SetByIndex(i, obj); cam.AddVisibleObject(obj); } } break; } } catch (DirectXException d3de) { Console.AddLine("Unable to cull object"); Console.AddLine(d3de.ErrorString); } catch (Exception e) { Console.AddLine("Unable to cull object"); Console.AddLine(e.Message); } } }