Exemplo n.º 1
0
 public HNode(HNode parent, BoundingSphere volume, RigidBody body = null)
 {
     Parent = parent;
     Volume = volume;
     Body = body;
     Children = new HNode[2];
 }
Exemplo n.º 2
0
 public void Insert(RigidBody body, BoundingSphere volume)
 {
     if (IsLeaf)
     {
         Children[0] = new HNode(this, Volume, Body);
         Children[1] = new HNode(this, volume, body);
         Body = null;
         recalculateboundingVolume();
     }
     else
     {
         if (Children[0].Volume.GetGrowth(volume) < Children[1].Volume.GetGrowth(volume))
             Children[0].Insert(body, volume);
         else
             Children[1].Insert(body, volume);
     }
 }
Exemplo n.º 3
0
 int getPotentialcontactswith(HNode other, List<PotentialContact> contacts, int limit, int current = 0)
 {
     if (!overlaps(other) || limit == 0) return 0;
     if (IsLeaf && other.IsLeaf)
     {
         contacts.Add(new PotentialContact());
         contacts[current].Bodies = new RigidBody[2];
         contacts[current].Bodies[0] = Body;
         contacts[current].Bodies[1] = other.Body;
         return 1;
     }
     if (other.IsLeaf || (!IsLeaf && Volume.GetSize() >= other.Volume.GetSize()))
     {
         int count = Children[0].getPotentialcontactswith(other, contacts, limit, current);
         if (limit > count)
         {
             return count + Children[1].getPotentialcontactswith(other, contacts, limit - count, current + count);
         }
         else
         {
             return count;
         }
     }
     else
     {
         int count = getPotentialcontactswith(other.Children[0], contacts, limit, current);
         if (limit > count)
         {
             return count + getPotentialcontactswith(other.Children[1], contacts, limit - count, current + count);
         }
         else
         {
             return count;
         }
     }
 }
Exemplo n.º 4
0
 void constructTree()
 {
     hnode = new HNode(null, bodies[0].BoundingSphere, bodies[0]);
     for (int i = 1; i < bodies.Count; i++)
         hnode.Insert(bodies[i], bodies[i].BoundingSphere);
 }
Exemplo n.º 5
0
 bool overlaps(HNode other)
 {
     return Volume.Overlaps(other.Volume);
 }