Example #1
0
 public unsafe BoundingBoxWide(BoundingBox* boundingBoxes, Vector<int>[] masks)
 {
     Min = new Vector3Wide(ref boundingBoxes[0].Min);
     Max = new Vector3Wide(ref boundingBoxes[0].Max);
     for (int i = 1; i < Vector<float>.Count; ++i)
     {
         BoundingBoxWide wide = new BoundingBoxWide(ref boundingBoxes[i]);
         ConditionalSelect(ref masks[i], ref wide, ref this, out this);
     }
 }
Example #2
0
        public static bool Intersects(ref BoundingBox a, ref BoundingBox b)
        {
            ////May be able to do better than this. Consider unbranching it.
            //return Vector3.Clamp(a.Min, b.Min, b.Max) == a.Min || Vector3.Clamp(a.Max, b.Min, b.Max) == a.Max;
            //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);
            //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);
            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;
            //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;
            //return Vector3.Min(Vector3.Max(a.Min, b.Min), b.Max) == a.Min ||
            //    Vector3.Min(Vector3.Max(a.Max, b.Min), b.Max) == a.Max ||
            //    Vector3.Min(Vector3.Max(b.Min, a.Min), a.Max) == b.Min ||
            //    Vector3.Min(Vector3.Max(b.Max, a.Min), a.Max) == b.Max;

            //This could be changed to result = And(GEQ(a.Max, b.Min), GEQ(b.Max, a.Min))
            //Then, horizontal And...
            //Could implement as dot(result, One). If that's -3, then we're good!
            //geq, geq, and, dot, load 3, compare. Six instructions instead of eleven, and no scalar swap.
        }
Example #3
0
 public void GetBoundingBox(out BoundingBox box)
 {
     box.Min = Position - HalfSize;
     box.Max = Position + HalfSize;
 }
Example #4
0
 public BoundingBoxWide(ref BoundingBox boundingBox)
 {
     Min = new Vector3Wide(ref boundingBox.Min);
     Max = new Vector3Wide(ref boundingBox.Max);
 }
Example #5
0
 public static void Merge(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);
 }
Example #6
0
 public static unsafe float ComputeVolume(ref BoundingBox a)
 {
     var diagonal = (a.Max - a.Min);
     return diagonal.X * diagonal.Y * diagonal.Z;
 }
Example #7
0
 public static void GetBoundingBox(ref BoundingBoxWide boundingBoxes, int i, out BoundingBox box)
 {
     box = new BoundingBox
     {
         Min = new Vector3(boundingBoxes.Min.X[i], boundingBoxes.Min.Y[i], boundingBoxes.Min.Z[i]),
         Max = new Vector3(boundingBoxes.Max.X[i], boundingBoxes.Max.Y[i], boundingBoxes.Max.Z[i])
     };
 }