我遇到了计算线段/射线是否与三维空间中的矩形相交的问题。这个矩形在平面上。我进行了搜索,唯一找到的是Ray and square/rectangle intersection in 3D,但我无法理解最后几步以及如何将其应用于我的系统。
所以我有一个射线
struct Ray
{
Vector3 m_startPoint; // P0
Vector3 m_direction; // Direction Unit Vector
float m_length; // Ray length
};
and I have a quad defined by
struct Quad
{
Vector3 p1;
Vector3 p2;
Vector3 p3;
Vector3 p4;
Vector3 normal;
}
我首先做的是使用点积计算光线是否会击中平面。
float dotProd = D3DXVec3Dot(&ray.m_direction, &quad.normal);
if (dotProd < 0) // if <0 ray will travel into the plane
{
// Get the point of intersection
float distToIntersection
//Vector3D intersectPoint = ray.m_startPoint + (distToIntersection * ray.m_direction);
// Check whether the point of intersection is within the bounds of the Quad
}
我现在遇到了困难...
我知道之前已经有人回答过这个问题,但是我无法在我的系统上使其正常运行,因此真的需要一些帮助。