Пример #1
0
        public static void FastIntersectOrientedBoxPlane(
            XMVector center,
            XMVector extents,
            XMVector axis0,
            XMVector axis1,
            XMVector axis2,
            XMVector plane,
            out XMVector outside,
            out XMVector inside)
        {
            // Compute the distance to the center of the box.
            XMVector dist = XMVector4.Dot(center, plane);

            // 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.
            XMVector radius = XMVector3.Dot(plane, axis0);

            radius.Y = XMVector3.Dot(plane, axis1).Y;
            radius.Z = XMVector3.Dot(plane, axis2).Z;
            radius   = XMVector3.Dot(extents, radius.Abs());

            // Outside the plane?
            outside = XMVector.Greater(dist, radius);

            // Fully inside the plane?
            inside = XMVector.Less(dist, -radius);
        }
Пример #2
0
        public static void FastIntersectSpherePlane(XMVector center, XMVector radius, XMVector plane, out XMVector outside, out XMVector inside)
        {
            XMVector dist = XMVector4.Dot(center, plane);

            // Outside the plane?
            outside = XMVector.Greater(dist, radius);

            // Fully inside the plane?
            inside = XMVector.Less(dist, -radius);
        }
Пример #3
0
        public static void FastIntersectAxisAlignedBoxPlane(XMVector center, XMVector extents, XMVector plane, out XMVector outside, out XMVector inside)
        {
            // Compute the distance to the center of the box.
            XMVector dist = XMVector4.Dot(center, plane);

            // 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. In this case b(i) = [(1,0,0), (0,1,0), (0,0,1)].
            XMVector radius = XMVector3.Dot(extents, plane.Abs());

            // Outside the plane?
            outside = XMVector.Greater(dist, radius);

            // Fully inside the plane?
            inside = XMVector.Less(dist, -radius);
        }
Пример #4
0
        public static void FastIntersectTrianglePlane(XMVector v0, XMVector v1, XMVector v2, XMVector plane, out XMVector outside, out XMVector inside)
        {
            // Plane0
            XMVector dist0 = XMVector4.Dot(v0, plane);
            XMVector dist1 = XMVector4.Dot(v1, plane);
            XMVector dist2 = XMVector4.Dot(v2, plane);

            XMVector minDist = XMVector.Min(dist0, dist1);

            minDist = XMVector.Min(minDist, dist2);

            XMVector maxDist = XMVector.Max(dist0, dist1);

            maxDist = XMVector.Max(maxDist, dist2);

            XMVector zero = XMGlobalConstants.Zero;

            // Outside the plane?
            outside = XMVector.Greater(minDist, zero);

            // Fully inside the plane?
            inside = XMVector.Less(maxDist, zero);
        }