示例#1
0
 public BoundingSphere(BoundingSphere one, BoundingSphere two)
 {
     Vector3 centreOffset = two.Center - one.Center;
     float distance = centreOffset.SquaredMagnitude;
     float radiusDiff = two.Radius - one.Radius;
     if (radiusDiff * radiusDiff >= distance)
     {
         if (one.Radius > two.Radius)
         {
             _center = one.Center;
             _radius = one.Radius;
         }
         else
         {
             _center = two.Center;
             _radius = two.Radius;
         }
     }
     else
     {
         distance = MathHelper.Sqrt(distance);
         _radius = (distance + one.Radius + two.Radius) * ((float)0.5);
         _center = one.Center;
         if (distance > 0)
         {
             _center += centreOffset * ((_radius - one.Radius) / distance);
         }
     }
 }
示例#2
0
 public HNode(HNode parent, BoundingSphere volume, RigidBody body = null)
 {
     Parent = parent;
     Volume = volume;
     Body = body;
     Children = new HNode[2];
 }
示例#3
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);
     }
 }
示例#4
0
 public float GetGrowth(BoundingSphere other)
 {
     BoundingSphere newSphere = new BoundingSphere(this, other);
     return newSphere.Radius * newSphere.Radius - _radius * _radius;
 }
示例#5
0
 public bool Overlaps(BoundingSphere other)
 {
     float distanceSquared = (_center - other.Center).SquaredMagnitude;
     return distanceSquared < (_radius + other._radius) * (_radius + other.Radius);
 }
示例#6
0
 void recalculateboundingVolume(bool recurse = true)
 {
     if (IsLeaf) return;
     Volume = new BoundingSphere(Children[0].Volume, Children[1].Volume);
     if (Parent != null) Parent.recalculateboundingVolume(true);
 }