public static XMVector PointOnPlaneInsideTriangle(XMVector p, XMVector v0, XMVector v1, XMVector v2) { // Compute the triangle normal. XMVector n = XMVector3.Cross(v2 - v0, v1 - v0); // Compute the cross products of the vector from the base of each edge to // the point with each edge vector. XMVector c0 = XMVector3.Cross(p - v0, v1 - v0); XMVector c1 = XMVector3.Cross(p - v1, v2 - v1); XMVector c2 = XMVector3.Cross(p - v2, v0 - v2); // If the cross product points in the same direction as the normal the the // point is inside the edge (it is zero if is on the edge). XMVector zero = XMGlobalConstants.Zero; XMVector inside0 = XMVector.GreaterOrEqual(XMVector3.Dot(c0, n), zero); XMVector inside1 = XMVector.GreaterOrEqual(XMVector3.Dot(c1, n), zero); XMVector inside2 = XMVector.GreaterOrEqual(XMVector3.Dot(c2, n), zero); // If the point inside all of the edges it is inside. return(XMVector.AndInt(XMVector.AndInt(inside0, inside1), inside2)); }