Exemple #1
0
 public Intersection Intersects(BoundingBox box)
 {
     throw new NotImplementedException();
 }
Exemple #2
0
 /// <summary>
 /// Checks if this ray intersects a bounding box
 /// </summary>
 /// <param name="box"></param>
 /// <param name="pos">Intersection point</param>
 /// <returns></returns>
 /// <remarks>This code is adjusted from http://www.3dkingdoms.com/weekly/weekly.php?a=3 </remarks>
 public bool Intersects(BoundingBox box, out Vector3 pos)
 {
     Vector3 s = box.Size / 2;
     Vector3 l1 = Origin;
     Vector3 l2 = Origin + Normal;
     Vector3 b1 = box.Position * -s;
     Vector3 b2 = box.Position * s;
     if (
             l2.x < b1.x && l1.x < b1.x
         || l2.x > b2.x && l1.x > b2.x
         || l2.y < b1.y && l1.y < b1.y
         || l2.y > b2.y && l1.y > b2.y
         || l2.z < b1.z && l1.z < b1.z
         || l2.z > b2.z && l1.z > b2.z
         )
     {
         pos = default(Vector3);
         return false;
     }
     if (l1.x > b1.x && l1.x < b2.x &&
         l1.y > b1.y && l1.y < b2.y &&
         l1.z > b1.z && l1.z < b2.z)
     {
         pos = l1;
         return true;
     }
     if ((Intersection(l1.x - b1.x, l2.x - b1.x, l1, l2, out pos) && IsInBox(pos, b1, b2, 1))
       || (Intersection(l1.y - b1.y, l2.y - b1.y, l1, l2, out pos) && IsInBox(pos, b1, b2, 2))
       || (Intersection(l1.z - b1.z, l2.z - b1.z, l1, l2, out pos) && IsInBox(pos, b1, b2, 3))
       || (Intersection(l1.x - b2.x, l2.x - b2.x, l1, l2, out pos) && IsInBox(pos, b1, b2, 1))
       || (Intersection(l1.y - b2.y, l2.y - b2.y, l1, l2, out pos) && IsInBox(pos, b1, b2, 2))
       || (Intersection(l1.z - b2.z, l2.z - b2.z, l1, l2, out pos) && IsInBox(pos, b1, b2, 3)))
         return true;
     else
     {
         pos = default(Vector3);
         return false;
     }
 }
Exemple #3
0
 public bool Intersects(BoundingBox other)
 {
     Vector3 sz = this.Size / 2;
     Vector3 os = other.Size / 2;
     return (Position.x + sz.x > other.Position.x - os.x && Position.x + sz.x < other.Position.x + os.x
         || Position.x - sz.x > other.Position.x - os.x && Position.x - sz.x < other.Position.x + os.x) &&
             (Position.y + sz.y > other.Position.y - os.y && Position.y + sz.y < other.Position.y + os.y
         || Position.y - sz.y > other.Position.y - os.y && Position.y - sz.y < other.Position.y + os.y) &&
             (Position.z + sz.z > other.Position.z - os.z && Position.z + sz.z < other.Position.z + os.z
         || Position.z - sz.z > other.Position.z - os.z && Position.z - sz.z < other.Position.z + os.z);
 }