HW1 #2 asks you to derive the intersection point of a ray p + td with a general plane containing a point a on the plane and a plane normal vector n. In the following problems, let’s solve a special case (an axis-algined plane) but add bounds so that we can intersect rays with axis-aligned rectangles. Using a handful of these, we’ll be able to model an empty version of the famous Cornell Box scene (minus the light source):
Let’s start with the back wall of the box; if our camera is in canonical position, which two coordinate axes is this plane parallel to?
Write pseudocode for an intersection routine on such an axis-aligned bounded rectangle in the scene:
""" xyrect_intersect(ray_p, ray_d, rect_z, min_x, max_x, min_y, max_y)
intersect the ray (ray_p, ray_d) with the a bounded rectangle parallel to the xy plane
the rectangle lies in the z=rect_z plane and has minimum and maximum x and y
coordinates given by {min,max}_{x,y}. If the ray hits the rectangle,
return (t, Vec3(x,y,z)). Otherwise, `return nothing` """
function xyrect_intersect(ray_p, ray_d, rect_z, min_x, max_x, min_y, max_y):
# code here
Assume that you have also implemented analogous
xzrect_intersect
and yzrect_intersect
functions. Also suppose we’ve defined corresponding structs
XYRect
and so on to store a rectangle and its parameters
(instantiated using, e.g.,
XYRect(rect_z, min_x, max_x, min_y, max_y, color)
. The
perspective camera is in canonical pose with \(d = 1\) and \(vw
= vh = 1\), and the back of the box is at \(z=-2\). Model the scene (again, ignoring
the light on the ceiling) by listing the five rectangles that make up
the faces of the cube.
Suppose the camera used an orthographic projection instead of perspective projection. What would the scene look like?