Asg 0: Ray Tracer

Objectives

To re-build a basic ray tracer

Assignment

  1. Download the asg00.tar.gz tarball, gunzip it, and compile the ray tracer with the Makefile provided:
    gunzip asg00.tar.gz
    tar xvf asg00.tar
    cd asg00
    make clean
    make
    	
  2. Run the ray tracer on the model file provided
    ./main cbox.txt > cbox.ppm
    	
  3. View the resulting cbox.ppm image with your favorite image viewer (e.g., xv), it should look like the one here, but larger:

  4. Rewrite the code by introducing a ray_t object with the following private data members:
      double dis;   // distance
      vec_t  pos;   // position
      vec_t  dir;   // direction
    	
    and public method:
      void trace(model_t&,rgb_t<double>&,object_t*);
    	
  5. Make sure to provide the C++ "big three" for the ray_t class.
  6. Follow the programming style used for other objects by splitting the interface and implementation in two separate files (e.g., ray.h and ray.cpp).
  7. Rewrite the main() subroutine to "spawn a ray" for each position and direction calculated and then call this ray's trace method to calculate the resultant color at each given pixel. This is usually done via instantiation of a new ray object, e.g.,
      // spawn new ray; analogous to C's malloc()
      ray = new ray_t(pos,dir);
    	
    and then by calling the ray's trace function:
      // trace ray (note the use of the -> operator, not the .)
      ray->trace(model,color,NULL);
    	
    Don't forget to delete the ray once it is no longer needed:
      // delete ray, analogous to C's free()
      delete ray;
    	
  8. Remove the old ray_trace() function from main.cpp.
  9. Your code, once rewritten and recompiled, should produce the same image as the one shown above for the given cbox.txt file.

Hints

  1. The goal of this assignment is to move the stand-alone trace() routine into a public member function of the ray_t class. What you need to watch out for are the stand-alone function's argument and local variables' semantics, i.e., how these variable contents change as the recursive ray tracing algorithm proceeds. In the new object-oriented version, clearly each ray maintains its own distance, position, and direction. One tricky aspect of this assignment is how to properly update these.
  2. Another tricky aspect of this assignment is the recursive call in the old non-object-oriented version of the program. In the object-oriented version, instead of calling the trace() routine agian, each ray needs to spawn a reflection ray and "bounce" that at the current surface point. Make sure that you free up any allocated memory here—do NOT create a memory leak!

Turn in

Turn in all of your code, in one tar.gz archive of your asg##/ directory, including:
  1. A README file containing
    1. Course id--section no
    2. Name
    3. Lab description
    4. Brief solution description (e.g., program design, description of algorithm, etc., however appropriate).
    5. Lessons learned, identified interesting features of your program
    6. Any special usage instructions
  2. Makefile
  3. source code (.h headers and .cpp source)
  4. object code (do a make clean before tar)

How to hand in

See handin notes