 |
I started out by implementing a basic ray tracer. I decided to only use
triangles because anything can be made from triangles, and they make
most computations (except possibly ray intersections) very easy. They
can't be concave or non-planar, for instance. The basic ray tracer
shoots a rays into the image from the center of projection through the view
plane, returning the color of the closest intersecting polygon. In order
to determine polygon intersections, I first determine the intersection
of the ray with the plane defined by the polygon (having stored the
normal of the triangle at creation, determining the plane equation is
trivial). Then, to deterimine if the intersection point was within
the polygon, I drop the X, Y, or Z coordinate of the polygon and intersection
point, depending on what produces an acceptable (the vertices of
the triangle aren't colinear) projection. Then, I take the
2D dot product of each vector from each vertex to the intersection
point with a corresponding edge direciton. If all the dot products
have the same sign, the point must be within the polygon.
|