Triangles

While it’s certainly possible to implement a triangle primitive at the origin, with unit dimensions, and then transform it into place like you’ve done with every other primitive you’ve implemented, it turns out that it makes these triangles really difficult to use well. So, your triangle primitive will actually accept three parameters, describing the location of each of its corners in object space. You can still transform the triangle as well, if needed.

Your implementation of triangles will follow these steps:

  1. Create the triangle shape itself, precomputing several values to optimize the intersection calculations.
  2. Implement the local_normal_at function to compute the normal vector for triangles.
  3. Implement the Möller–Trumbore ray-triangle ...

Get The Ray Tracer Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.