Ejemplo n.º 1
0
 private void GetBodies(Vector2 point, float radius, List <IQuadTreeBody> bods)
 {
     //no children
     if (_childA == null)
     {
         for (int i = 0; i < _bodies.Count; i++)
         {
             bods.Add(_bodies[i]);
         }
     }
     else
     {
         if (_childA.ContainsCircle(point, radius))
         {
             _childA.GetBodies(point, radius, bods);
         }
         if (_childB.ContainsCircle(point, radius))
         {
             _childB.GetBodies(point, radius, bods);
         }
         if (_childC.ContainsCircle(point, radius))
         {
             _childC.GetBodies(point, radius, bods);
         }
         if (_childD.ContainsCircle(point, radius))
         {
             _childD.GetBodies(point, radius, bods);
         }
     }
 }
        ///// Methods /////

        public override void DetectBodyVsBody()
        {
            for (int i = 0; i < bodyList.Count; i++)
            {
                if (bodyList[i].Sleeping)
                {
                    continue;
                }

                // todo: something better maybe?
                var maxDist = bodyList[i].CollisionShape.Extents.x;
                maxDist = Mathf.Max(maxDist, bodyList[i].CollisionShape.Extents.y);
                maxDist = Mathf.Max(maxDist, bodyList[i].CollisionShape.Extents.z);

                var ents = _quadTree.GetBodies(bodyList[i].CollisionShape.Center, maxDist);
                for (int j = 0; j < ents.Count; j++)
                {
                    var body2 = ents[j] as ICollisionBody;
                    if (body2 == null ||
                        body2.Sleeping ||
                        ReferenceEquals(bodyList[i], body2))
                    {
                        continue;
                    }

                    Test(bodyList[i], body2);
                }
            }
        }