Ray Tracing, Version 3.1
Day #6
|
Goal: Ray trace a scene where
|
Scene Class:
At this point you will probably want to take all of your ray tracing functions in your driver program and make them methods of a new class, Scene. This class should be kept in a separate file, scene.h and scene.cpp. You will need to change your makefile to reflect this. The necessary global variables that you have in your driver program will now become data members of the Scene class. The functions in your driver program pertaining to ray tracing will now become method members of the Scene class. Those functions are: readScene, rayTracer, getFirstHit, shadePixel, and shade. Your driver program will be very simple now. Before adding anything new to your ray tracer, make this change and verify that your program still works correctly.
Ray Tracing Tools:
Add the following data fields to class hitInfo:
int surface; //which surface was hit
bool isEntering; //is ray entering the object?
and change Sphere::hit( ) so that it records values for these two new fields. Surface is 0 for both sphere hits; the first hit is entering the sphere but the second hit is not.
Add these new classes: Plane, TaperedCylinder, Square. Like the Sphere class, each of these generic object classes will have one method: hit. Be sure to test each before entrusting it to your ray tracer.
Add Method to Scene Class:
Add a new method to Scene,
bool isInShadow(Ray3D shadow_feeler);
which goes through the object list looking for a hit; if one is found it returns
true, else it returns false. It does not keep any any information about the
hit -- we are only interested in whether or not there was one. The precondition
for this methods is that shadow_feeler is the ray starting from a point
slightly offset from the hit point on the object, going in the direction toward
the light source.
ReadScene:
As you add each new generic object to your ray tracer, the readScene method needs to be updated to reflect this.
Test Files:
The test file shadow.scn is available to test the shadow method.
All files are located in /classes/cs3114/Advanced_Graphics/files directory