CPSC310A Assignment 2 - Orthonormal Ray Tracer

Due Monday January 30

Details

Create a C++ program that can produce an orthonormal ray traced image of a single sphere. A ray tracer produces a two-dimensional image of a three-dimensional scene by creating a ray for every pixel in an image and finding the nearest object that intersects with the ray in the scene. In an orthonormal ray tracer all rays have the same direction, perpendicular to the view plane. You should create three classes to help write this program.

The Ray class represents a half-line and should have a point to represent the origin and a vector to represent the direction of the ray. The class should also have two floats to represent the minimum and maximum parametric distances of the ray.

The Sphere class represents a sphere that can be ray traced and should have a point to represent the center of the sphere and a float to represent the radius of the sphere. The class should also have a function that returns whether a ray intersects with a sphere. This method should only return true if the parametric distance is between the minimum and maximum parametric distance of the ray. If there is an intersection, the function should update the maximum parametric distance of the ray.

The Viewport class represents the two-dimensional rectangular region that a three-dimensional scene is projected onto during ray tracing and should have a point to represent the origin of the viewport and two vectors to represent the horizontal and vertical axes. The class should also have a function that takes normalized two-dimensional viewport coordinates and returns the ray with an origin at the specified coordinate and direction that is perpendicular to the view plane. The minimum parametric distance of the ray should be set to zero and the maximum parametric distance should be set to infinity.

The ray tracing program should create an image, a sphere, and a viewport such that the aspect ratio of the image and viewport are the same and the sphere will be projected onto the viewport. For every pixel in the image, calculate the corresponding normalized viewport coordinate and get the corresponding ray from the viewport. Use the intersection function in the sphere class to test if the ray intersects the sphere. If it does intersect, set the image's corresponding pixel to white. if it does not intersect, set the image's corresponding pixel to black. After setting the color of every pixel, write the image to a file.

Submission

Tar your code in a file that contains your name and submit it on the course Inquire site.