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.
Your existing dotProd test just tells you whether the direction of your ray is along the normal or away from it.
What you probably want to do is:
s
and end distance ise
then it's necessarily at the points / (s - e)
along the line;