示例#1
0
 /// <summary>
 /// Test whether this sphere penetrates another, and by how far.
 /// </summary>
 /// <param name="other"></param>
 /// <returns>The distance by which my sphere penetrates the other, or -1 if they don't touch</returns>
 public float PenetrationBy(Sphere other)
 {
     // dist between cell centres (squared)
     float distSq = Vector3.LengthSq(this.Centre - other.Centre);
     // sum of the two radii
     float radii = this.Radius + other.Radius;
     // If the dist from centre to centre is smaller than the sum of the radii we are in contact
     if (distSq < (radii * radii))
     {
         // return the penetration distance
         return (radii - (float)Math.Sqrt(distSq));
     }
     return -1;
 }
示例#2
0
 /// <summary>
 /// Combine two bounding spheres to create a single sphere enclosing both.
 /// Overload accepting a Sphere as argument
 /// </summary>
 public void CombineBounds(Sphere add)
 {
     CombineBounds(add.Centre, add.Radius);
 }
示例#3
0
 /// <summary>
 /// Test whether this sphere penetrates another.
 /// Faster than PenetrationBy() but doesn't return penetration distance (use if dist not needed)
 /// </summary>
 /// <param name="other"></param>
 /// <returns>The distance by which my sphere penetrates the other, or -1 if they don't touch</returns>
 public bool IsPenetrating(Sphere other)
 {
     // dist between cell centres (squared)
     float distSq = Vector3.LengthSq(this.Centre - other.Centre);
     // sum of the two radii
     float radii = this.Radius + other.Radius;
     // If the dist from centre to centre is smaller than the sum of the radii we are in contact
     if (distSq < (radii * radii))
         return true;
     return false;
 }
示例#4
0
 /// <summary>
 /// Return the SQUARE of the distance between this sphere's centre and another's
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public float CentreToCentreSq(Sphere other)
 {
     return Vector3.LengthSq(this.Centre - other.Centre);
 }