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. Here, 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:
1""" xyrect_intersect(ray_p, ray_d, rect_z, min_x, max_x, min_y, max_y)
2intersect the ray (ray_p, ray_d) with the a bounded rectangle parallel to the xy plane
3the rectangle lies in the z=rect_z plane
4has minimum and maximum x and y coordinates given by {min,max}_{x,y}
5If the ray hits the rectangle, return (t, Vec3(x,y,z))
6Otherwise, `return nothing` """
7function xyrect_intersect(ray_p, ray_d, rect_z, min_x, max_x, min_y, max_y):
8# code here
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 and , and the back of the box is at . Model the scene (again, ignoring the light on the ceiling) by listing the five rectangles that make up the faces of the cube.