I'm in a class where we are creating a ray tracer from the ground up in C++. I'm at a point where I can't seem to wrap my head around the math that is required to calculate the point at which a ray intersects a polygon.
We have some direction for how to do this, but all of the class materials as well as my Googling of the subject have not helped.
These are the functions we must complete:
bool polygon::Intersect(const ray &R, intersection &inter)
{
// To Do: If you have implemented the "CalculateNormal" method
// below, should already be calculated and placed in the member
// "n".
//
// Now, using n, you need to calculate the intersection of the
// ray with the plane containing the polygon. Then, once you
// have that point, you need to loop through each edge in the
// polygon and make sure the point is to the left of that edge.
//
// If it is to the left of every edge, then fill the structure
// inter with all of the data for the intersection and return
// true, if not, return 0.
//
// Don't forget to check to see if the t you calculate for the
// ray is > 0.
return false;
}
void polygon::CalculateNormal(void)
{
// To Do: Use the edges of the polygon to calculate the normal
// of the polygon. You should be careful to take care of the
// case where two edges give you a zero normal. Place the
// normal into the member "n" so that the intersection method
// can use it when called.
//
}
Could someone please explain this in a bit further detail?
Note: I am not asking for anyone to write the code or do my homework for me, but instead help me understand what exactly is going on here.
Thank you.