//两点在直线同一边(vP1,vP2在A,B同一边) Bool HawkTriangle3D::IsOnSameSide(const HawkVector3D& vP1,const HawkVector3D& vP2,const HawkVector3D& vA, const HawkVector3D& vB) { HawkVector3D bminusa = vB - vA; HawkVector3D cp1 = bminusa.CrossProduct(vP1 - vA); HawkVector3D cp2 = bminusa.CrossProduct(vP2 - vA); return (cp1.DotProduct(cp2) >= 0.0f); }
////////////////////////////////////////////////////////////////////////// //直线和三角形相交 Bool HawkLine3D::Intersect(const HawkTriangle3D& oTriangle,Vec3IntrResult* pResult) const { HawkVector3D vDiff = Point - oTriangle.GetPoint(0); HawkVector3D edge1 = oTriangle.GetEdge(0); HawkVector3D edge2 = oTriangle.GetEdge(1); HawkVector3D normal = edge1.CrossProduct(edge2); Float DdN = Direction.DotProduct(normal); Float fSign = 0.0f; if (DdN > HawkMath::FLOAT_DIFF) { fSign = 1.0f; } else if (DdN < -HawkMath::FLOAT_DIFF) { fSign = -1.0f; DdN = -DdN; } else { return false; } Float DdQxE2 = fSign*Direction.DotProduct(vDiff.CrossProduct(edge2)); if (DdQxE2 >= 0.0f) { Float DdE1xQ = fSign*Direction.DotProduct(edge1.CrossProduct(vDiff)); if (DdE1xQ >= 0.0f) { if (DdQxE2 + DdE1xQ <= DdN) { if (pResult) { Float QdN = -fSign*vDiff.DotProduct(normal); pResult->Factor = QdN / DdN; pResult->Point = Point + pResult->Factor*Direction; } return true; } } } return false; }