public SphereTreeNode FindSubsphereContainerInternal(CollisionShape shape) { // If more than one child contains shape, return this int count = 0; SphereTreeNode container = null; for (int i = 0; i < childCount; i++) { SphereTreeNode child = children[i]; if (child != null && child.Contains(shape)) { count++; container = child; } } if (count > 1) { return(this); } else if (count == 0) { return(null); } else { container = container.FindSubsphereContainer(shape); SphereTreeNode result = (container == null ? this : container); return(result); } }
// private string lastLoggedContainer = ""; public SphereTreeNode FindSmallestContainer(CollisionShape shape, SphereTreeNode lastSphere) { // if (lastSphere != null) { // if (lastSphere.Contains(shape)) // return lastSphere.FindSubsphereContainer(shape); // else { // // Move up the parent chain // while (lastSphere != this) { // lastSphere = lastSphere.parent; // Debug.Assert(lastSphere != null, "Parent is null!"); // Debug.Assert(!lastSphere.leafNode); // if (lastSphere.Contains(shape)) { // if (MO.DoLog) // MO.Log(" Container {0} for shape {1}", lastSphere, shape); // return lastSphere; // } // } // Debug.Assert(false, "Didn't find container!"); // } // } SphereTreeNode container = root.FindSubsphereContainer(shape); // if (MO.DoLog) { // string s = string.Format(" Returning smallest subsphere container {0} for shape {1}", // container, shape); // if (lastLoggedContainer != s) { // lastLoggedContainer = s; // MO.Log(s); // } // } return(container); }