Building a World

The first step is to implement the world object. Think of how much work it was to render a single sphere, and then multiply that by dozens of objects. You begin to see what you gain by having something that will keep track of all of those things for you.

Initially, a world is empty, containing no objects and no light source. Write a test like the following, demonstrating a world function that returns just such a data structure.

 Scenario​: Creating a world
 Given​ w ← world()
 Then​ w contains no objects
 And​ w has no light source

Some of the tests you’ll write in this chapter assume a default world exists with a light source at (-10, 10, -10). This world contains two concentric spheres, where the ...

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.