diff options
author | chai <215380520@qq.com> | 2023-05-10 09:35:29 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-05-10 09:35:29 +0800 |
commit | caeba98e0385edebb344e6dbd024c01801a75fc4 (patch) | |
tree | 989ad28501cee2ee47a14214c20bc7a8b9c8a71b /marching/Assets/Scripts/Physics/PhysicsQuadtree.cs | |
parent | fc2cfdad0d3cfb3844681855c1c45d9415f5ee8e (diff) |
*misc
Diffstat (limited to 'marching/Assets/Scripts/Physics/PhysicsQuadtree.cs')
-rw-r--r-- | marching/Assets/Scripts/Physics/PhysicsQuadtree.cs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/marching/Assets/Scripts/Physics/PhysicsQuadtree.cs b/marching/Assets/Scripts/Physics/PhysicsQuadtree.cs index cb17900..f4bad27 100644 --- a/marching/Assets/Scripts/Physics/PhysicsQuadtree.cs +++ b/marching/Assets/Scripts/Physics/PhysicsQuadtree.cs @@ -16,7 +16,7 @@ class PhysicsQuadtree public PhysicsQuadtree(Vector4 range) { m_QuadtreeRange = range; - m_Quadtree = new Quadtree(0, range); + m_Quadtree = new Quadtree(0, range, true); } public void AddObject(IQuadTreeObject obj) @@ -33,17 +33,22 @@ class PhysicsQuadtree { m_Quadtree.Clear(false); m_Quadtree.Rebound(m_QuadtreeRange); + Vector4 bound = m_Quadtree.bound; for (int i = 0; i < m_Objects.Count; i++) { IQuadTreeObject obj = m_Objects[i]; - m_Quadtree.Insert(obj); + // 简单的忽略中心在边界外的object + if(PhysicsManager.IsPointInsideBox(bound, obj.bound.xy())) + { + m_Quadtree.Insert(obj); + } } } public void Debug() { Color c = Gizmos.color; - Gizmos.color = Color.red; + Gizmos.color = Color.green; m_Quadtree?.Iterate((t) => { Vector3 pos = new Vector3(t.x, t.y, 0); @@ -63,5 +68,4 @@ class PhysicsQuadtree return m_Quadtree.Retrieve(ref returnObjs, bound); } -} - +}
\ No newline at end of file |