コード例 #1
0
        // Classify this bounding box as entirely in front of, in back of, or
        // intersecting the given plane.
        public PlaneIntersectionType Intersects(ref PlaneD plane)
        {
            double dist = plane.DotCoordinate(Center);

            // Transform the plane's normal into this box's space
            Vector3D localNormal = Vector3D.Transform(plane.Normal, Quaternion.Conjugate(Orientation));

            // Project the axes of the box onto the normal of the plane.  Half the
            // length of the projection (sometime called the "radius") is equal to
            // h(u) * abs(n dot b(u))) + h(v) * abs(n dot b(v)) + h(w) * abs(n dot b(w))
            // where h(i) are extents of the box, n is the plane normal, and b(i) are the
            // axes of the box.
            double r = Math.Abs(HalfExtent.X * localNormal.X)
                       + Math.Abs(HalfExtent.Y * localNormal.Y)
                       + Math.Abs(HalfExtent.Z * localNormal.Z);

            if (dist > r)
            {
                return(PlaneIntersectionType.Front);
            }
            else if (dist < -r)
            {
                return(PlaneIntersectionType.Back);
            }
            else
            {
                return(PlaneIntersectionType.Intersecting);
            }
        }
コード例 #2
0
        public PlaneIntersectionType Intersects(ref PlaneD plane)
        {
            double   num         = plane.DotCoordinate(this.Center);
            Vector3D vectord     = Vector3D.Transform(plane.Normal, Quaternion.Conjugate(this.Orientation));
            double   introduced3 = Math.Abs((double)(this.HalfExtent.X * vectord.X));
            double   num2        = (introduced3 + Math.Abs((double)(this.HalfExtent.Y * vectord.Y))) + Math.Abs((double)(this.HalfExtent.Z * vectord.Z));

            if (num > num2)
            {
                return(PlaneIntersectionType.Front);
            }
            if (num < -num2)
            {
                return(PlaneIntersectionType.Back);
            }
            return(PlaneIntersectionType.Intersecting);
        }