summaryrefslogtreecommitdiff
path: root/marching/Assets/Scripts/Physics/Quadtree.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-05-10 09:35:29 +0800
committerchai <215380520@qq.com>2023-05-10 09:35:29 +0800
commitcaeba98e0385edebb344e6dbd024c01801a75fc4 (patch)
tree989ad28501cee2ee47a14214c20bc7a8b9c8a71b /marching/Assets/Scripts/Physics/Quadtree.cs
parentfc2cfdad0d3cfb3844681855c1c45d9415f5ee8e (diff)
*misc
Diffstat (limited to 'marching/Assets/Scripts/Physics/Quadtree.cs')
-rw-r--r--marching/Assets/Scripts/Physics/Quadtree.cs11
1 files changed, 8 insertions, 3 deletions
diff --git a/marching/Assets/Scripts/Physics/Quadtree.cs b/marching/Assets/Scripts/Physics/Quadtree.cs
index f1237ab..9f8ecba 100644
--- a/marching/Assets/Scripts/Physics/Quadtree.cs
+++ b/marching/Assets/Scripts/Physics/Quadtree.cs
@@ -23,14 +23,16 @@ namespace mh
/// </summary>
public class Quadtree
{
- public const int kMaxObjectsPerBlock = 5;
- public const int kMaxLevel = 6;
+ public const int kMaxObjectsPerBlock = 4;
+ public const int kMaxLevel = 5;
private int m_Level;
private Vector4 m_Bounds; // x,y,z,w => posx,posy,width,height
private Quadtree[] m_SubTrees; // 从右上角开始逆时针索引
private List<IQuadTreeObject> m_Objects; // 当前层能容纳,但任何一个子树都无法容纳的对象
+ private bool m_IsRoot;
+ public Vector4 bound { get { return m_Bounds; } }
public float x { get { return m_Bounds.x; } }
public float y { get { return m_Bounds.y; } }
public float w { get { return m_Bounds.z; } }
@@ -42,6 +44,8 @@ namespace mh
public float top { get { return y + halfH; } }
public float bottom { get { return y - halfH; } }
+ public bool isRoot { get { return m_IsRoot; } }
+
private static Queue<List<IQuadTreeObject>> m_QuadtreeObjPool = new Queue<List<IQuadTreeObject>>();
private static Queue<Quadtree> m_QuadtreePool = new Queue<Quadtree>();
@@ -84,12 +88,13 @@ namespace mh
list = null;
}
- public Quadtree(int level, Vector4 bounds)
+ public Quadtree(int level, Vector4 bounds, bool isRoot = false)
{
m_Level = level;
m_Bounds = bounds;
m_SubTrees = new Quadtree[4];
m_Objects = QueryQuadtreeObjList();
+ m_IsRoot = isRoot;
}
public void Rebound(Vector4 bounds)