Esempio n. 1
0
        public bool Intersection(AxisAlignedBoundingBox bounds)
        {
            Ray ray = this;
            // we calculate distance to the intersection with the x planes of the box
            double minDistFound = (bounds[(int)ray.sign[0]].x - ray.origin.x) * ray.oneOverDirection.x;
            double maxDistFound = (bounds[1 - (int)ray.sign[0]].x - ray.origin.x) * ray.oneOverDirection.x;
            // now find the distance to the y planes of the box
            double minDistToY = (bounds[(int)ray.sign[1]].y - ray.origin.y) * ray.oneOverDirection.y;
            double maxDistToY = (bounds[1 - (int)ray.sign[1]].y - ray.origin.y) * ray.oneOverDirection.y;
            if ((minDistFound > maxDistToY) || (minDistToY > maxDistFound))
            {
                return false;
            }

            if (minDistToY > minDistFound)
            {
                minDistFound = minDistToY;
            }

            if (maxDistToY < maxDistFound)
            {
                maxDistFound = maxDistToY;
            }

            // and finaly the z planes
            double minDistToZ = (bounds[(int)ray.sign[2]].z - ray.origin.z) * ray.oneOverDirection.z;
            double maxDistToZ = (bounds[1 - (int)ray.sign[2]].z - ray.origin.z) * ray.oneOverDirection.z;
            if ((minDistFound > maxDistToZ) || (minDistToZ > maxDistFound))
            {
                return false;
            }

            if (minDistToZ > minDistFound)
            {
                minDistFound = minDistToZ;
            }

            if (maxDistToZ < maxDistFound)
            {
                maxDistFound = maxDistToZ;
            }

            bool withinDistanceToConsider = (minDistFound < ray.maxDistanceToConsider) && (maxDistFound > ray.minDistanceToConsider);
            return withinDistanceToConsider;
        }
        public bool Contains(AxisAlignedBoundingBox bounds)
        {
            if (this.minXYZ.x <= bounds.minXYZ.x
                && this.maxXYZ.x >= bounds.maxXYZ.x
                && this.minXYZ.y <= bounds.minXYZ.y
                && this.maxXYZ.y >= bounds.maxXYZ.y
                && this.minXYZ.z <= bounds.minXYZ.z
                && this.maxXYZ.z >= bounds.maxXYZ.z)
            {
                return true;
            }

            return false;
        }
 public static AxisAlignedBoundingBox Union(AxisAlignedBoundingBox bounds, Vector3 vertex)
 {
     Vector3 minXYZ = Vector3.Zero;
     minXYZ.x = Math.Min(bounds.minXYZ.x, vertex.x);
     minXYZ.y = Math.Min(bounds.minXYZ.y, vertex.y);
     minXYZ.z = Math.Min(bounds.minXYZ.z, vertex.z);
     Vector3 maxXYZ = Vector3.Zero;
     maxXYZ.x = Math.Max(bounds.maxXYZ.x, vertex.x);
     maxXYZ.y = Math.Max(bounds.maxXYZ.y, vertex.y);
     maxXYZ.z = Math.Max(bounds.maxXYZ.z, vertex.z);
     return new AxisAlignedBoundingBox(minXYZ, maxXYZ);
 }
 public static AxisAlignedBoundingBox Intersection(AxisAlignedBoundingBox boundsA, AxisAlignedBoundingBox boundsB)
 {
     Vector3 minXYZ = Vector3.Zero;
     minXYZ.x = Math.Max(boundsA.minXYZ.x, boundsB.minXYZ.x);
     minXYZ.y = Math.Max(boundsA.minXYZ.y, boundsB.minXYZ.y);
     minXYZ.z = Math.Max(boundsA.minXYZ.z, boundsB.minXYZ.z);
     Vector3 maxXYZ = Vector3.Zero;
     maxXYZ.x = Math.Max(minXYZ.x, Math.Min(boundsA.maxXYZ.x, boundsB.maxXYZ.x));
     maxXYZ.y = Math.Max(minXYZ.y, Math.Min(boundsA.maxXYZ.y, boundsB.maxXYZ.y));
     maxXYZ.z = Math.Max(minXYZ.z, Math.Min(boundsA.maxXYZ.z, boundsB.maxXYZ.z));
     return new AxisAlignedBoundingBox(minXYZ, maxXYZ);
 }
 public static AxisAlignedBoundingBox operator +(AxisAlignedBoundingBox A, AxisAlignedBoundingBox B)
 {
     Vector3 calcMinXYZ = new Vector3();
     calcMinXYZ.x = Math.Min(A.minXYZ.x, B.minXYZ.x);
     calcMinXYZ.y = Math.Min(A.minXYZ.y, B.minXYZ.y);
     calcMinXYZ.z = Math.Min(A.minXYZ.z, B.minXYZ.z);
     Vector3 calcMaxXYZ = new Vector3();
     calcMaxXYZ.x = Math.Max(A.maxXYZ.x, B.maxXYZ.x);
     calcMaxXYZ.y = Math.Max(A.maxXYZ.y, B.maxXYZ.y);
     calcMaxXYZ.z = Math.Max(A.maxXYZ.z, B.maxXYZ.z);
     AxisAlignedBoundingBox combinedBounds = new AxisAlignedBoundingBox(calcMinXYZ, calcMaxXYZ);
     return combinedBounds;
 }
        public static AxisAlignedBoundingBox Intersection(AxisAlignedBoundingBox boundsA, AxisAlignedBoundingBox boundsB)
        {
            Vector3 minXYZ = Vector3.Zero;

            minXYZ.x = Math.Max(boundsA.minXYZ.x, boundsB.minXYZ.x);
            minXYZ.y = Math.Max(boundsA.minXYZ.y, boundsB.minXYZ.y);
            minXYZ.z = Math.Max(boundsA.minXYZ.z, boundsB.minXYZ.z);

            Vector3 maxXYZ = Vector3.Zero;

            maxXYZ.x = Math.Max(minXYZ.x, Math.Min(boundsA.maxXYZ.x, boundsB.maxXYZ.x));
            maxXYZ.y = Math.Max(minXYZ.y, Math.Min(boundsA.maxXYZ.y, boundsB.maxXYZ.y));
            maxXYZ.z = Math.Max(minXYZ.z, Math.Min(boundsA.maxXYZ.z, boundsB.maxXYZ.z));

            return(new AxisAlignedBoundingBox(minXYZ, maxXYZ));
        }