diff options
Diffstat (limited to 'marching/Assets')
-rw-r--r-- | marching/Assets/Scripts/Physics/Quadtree.cs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/marching/Assets/Scripts/Physics/Quadtree.cs b/marching/Assets/Scripts/Physics/Quadtree.cs index c157512..af7a005 100644 --- a/marching/Assets/Scripts/Physics/Quadtree.cs +++ b/marching/Assets/Scripts/Physics/Quadtree.cs @@ -16,7 +16,7 @@ namespace mh public class Quadtree { - public const int kMaxObjectsPerBlock = 5; + public const int kMaxObjectsPerBlock = 4; public const int kMaxLevel = 20; private int m_Level; @@ -146,16 +146,23 @@ namespace mh public void Insert(IQuadTreeObject obj) { - if (m_SubTrees[0] != null) + int index = GetSubtreeIndex(obj.bound); + if(index != -1) { - int index = GetSubtreeIndex(obj.bound); - if (index != -1) - { - m_SubTrees[index].Insert(obj); - return; - } + if (m_SubTrees[0] == null) Split(); + m_SubTrees[index].Insert(obj); + return; } + //if (m_SubTrees[0] != null) + //{ + // if (index != -1) + // { + // m_SubTrees[index].Insert(obj); + // return; + // } + //} + m_Objects.Add(obj); if(m_Objects.Count > kMaxObjectsPerBlock && m_Level < kMaxLevel) // 本层满了之后重新排布层内对象 @@ -164,7 +171,7 @@ namespace mh for(int i = m_Objects.Count - 1; i >= 0; i--) { - int index = GetSubtreeIndex(m_Objects[i].bound); + index = GetSubtreeIndex(m_Objects[i].bound); if(index != -1) { IQuadTreeObject o = m_Objects[i]; @@ -173,6 +180,8 @@ namespace mh } } } + + // Debug.Log(m_Objects.Count); } /// <summary> |