Im having trouble with calculating whether line/ray intersects a rectangle (thats on a plane) in 3d space.
I have searched and the only thing I found was Ray and square/rectangle intersection in 3D but I just cant quite understand the last steps and how to apply it for my system.
So I have a Ray
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;
}
What I first did was calculate whether the ray would ever hit the plane using the dot product
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
}
And this is where I get stuck...
I know its been answered before but I can't make it work for my system so would really appreciate some help.
Quad
struct fully defines a quad. Even if I collapse them down to the plane, how do I know e.g. whether (0, 0) and (1, 1) defines a zero-height quad with (1, 1) being a basis vector or a 1x1 quad with (0, 1) and (1, 0) being basis vectors, or any other quad entirely? Are you assuming axis alignment? – Tommy