Provides XNA-like axis-aligned bounding box functionality.
Esempio n. 1
0
 public static void CreateFromSphere(ref BoundingSphere boundingSphere, out BoundingBox boundingBox)
 {
     var radius = new Vector3(boundingSphere.Radius);
     boundingBox.Min = boundingSphere.Center - radius;
     boundingBox.Max = boundingSphere.Center + radius;
 }
Esempio n. 2
0
 public static void CreateMerged(ref BoundingBox a, ref BoundingBox b, out BoundingBox merged)
 {
     merged.Min = Vector3.Min(a.Min, b.Min);
     merged.Max = Vector3.Max(a.Max, b.Max);
 }
Esempio n. 3
0
 public bool Intersects(ref BoundingBox a, ref BoundingBox b)
 {
     return a.Max.X >= b.Min.X & a.Max.Y >= b.Min.Y & a.Max.Z >= b.Min.Z &
            b.Max.X >= a.Min.X & b.Max.Y >= a.Min.Y & b.Max.Z >= a.Min.Z;
 }
Esempio n. 4
0
 public static unsafe float ComputeVolume(ref BoundingBox box)
 {
     var diagonal = (box.Max - box.Min);
     return diagonal.X * diagonal.Y * diagonal.Z;
 }
Esempio n. 5
0
 public ContainmentType Contains(ref BoundingBox boundingBox)
 {
     if (Max.X < boundingBox.Min.X || Min.X > boundingBox.Max.X ||
         Max.Y < boundingBox.Min.Y || Min.Y > boundingBox.Max.Y ||
         Max.Z < boundingBox.Min.Z || Min.Z > boundingBox.Max.Z)
         return ContainmentType.Disjoint;
     //It is known to be at least intersecting. Is it contained?
     if (Min.X <= boundingBox.Min.X && Max.X >= boundingBox.Max.X &&
         Min.Y <= boundingBox.Min.Y && Max.Y >= boundingBox.Max.Y &&
         Min.Z <= boundingBox.Min.Z && Max.Z >= boundingBox.Max.Z)
         return ContainmentType.Contains;
     return ContainmentType.Intersects;
 }
Esempio n. 6
0
        public static void TestIntersection(Ray simdRay, BoundingBox simdBox, ref int intersectionCount)
        {
            bRay scalarRay;
            bBoundingBox scalarBox;

            scalarRay.Position = Convert(simdRay.Position);
            scalarRay.Direction = Convert(simdRay.Direction);
            scalarBox.Min = Convert(simdBox.Min);
            scalarBox.Max = Convert(simdBox.Max);

            float simdT;
            var simdIntersects = Ray.Intersects(ref simdRay, ref simdBox, out simdT);

            float scalarT;
            var scalarIntersects = scalarRay.Intersects(ref scalarBox, out scalarT);
            //Console.WriteLine($"Simd says: {simdIntersects}, scalar says {scalarIntersects}");
            Assert.IsTrue(simdIntersects == scalarIntersects);
            if (simdIntersects)
            {
                var error = Math.Abs(simdT - scalarT);
                Assert.IsTrue(error <= 1e-5f);
                intersectionCount++;
            }
            //Just treat T as undefined if it's not intersecting. No need to check it.
        }
Esempio n. 7
0
 public static void CreateMerged(ref BoundingBox a, ref BoundingBox b, out BoundingBox merged)
 {
     merged.Min = Vector3.Min(a.Min, b.Min);
     merged.Max = Vector3.Max(a.Max, b.Max);
 }
Esempio n. 8
0
        public static unsafe float ComputeVolume(ref BoundingBox box)
        {
            var diagonal = (box.Max - box.Min);

            return(diagonal.X * diagonal.Y * diagonal.Z);
        }
Esempio n. 9
0
 public bool Intersects(ref BoundingBox a, ref BoundingBox b)
 {
     return(a.Max.X >= b.Min.X & a.Max.Y >= b.Min.Y & a.Max.Z >= b.Min.Z &
            b.Max.X >= a.Min.X & b.Max.Y >= a.Min.Y & b.Max.Z >= a.Min.Z);
 }