The function p
(t)
in more verbose code form I call “point_at_parameter(t)”:
Now we are ready to turn the corner and make a ray tracer. At the core of a ray tracer is to
send rays through pixels and compute what color is seen in the direction of those rays. This is
of the form calculate which ray goes from the eye to a pixel, compute what that ray intersects,
and compute a color for that intersection point.
When first developing a ray tracer, I always do
a simple camera for getting the code up and running. I also make a simple color(ray)
function
that returns the color of the background (a simple gradient).
I’ve often gotten into trouble using square images for debugging because I transpose x and y
too often, so I’ll stick with a 200x100 image. I’ll put the “eye” (or camera center if you think of a
camera) at (0,0,0). I will have the y-axis go up, and the x-axis to the right. In order to respect the
convention of a right handed coordinate system, into the screen is the negative z-axis. I will
traverse the screen from the lower left hand corner and use two offset vectors along the screen
sides to move the ray endpoint across the screen. Note that I do not make the ray direction a
unit length vector because I think not doing that makes for simpler and slightly faster code.