Ray Tracing, Version 2.0
Day #4
|
Goal: Ray trace a scene where
|
Ray Tracing Tools:
Add the following classes to ray_tracing_tools, thoroughly testing each:
class HitInfo, which will be used to keep information about the current hit point. At this time, HitInfo needs to contain the data:GLdouble hit_time; //time at which the object was hit
int which_obj; //index of which object was hit
GLdoublePoint generic_hit_point; //where ray hit the generic object
GLdoubleVector generic_hit_normal; //normal to the generic surface at the generic_hit_pointand these methods:
A constructor, which initializes hit_time to -1.0 and which_obj to -1.
void set(HitInfo source); //which sets the data to be the values in source's data fields
class Intersection, which will be used to keep information about all the hits made by the current ray. This will be needed later for transparency, but will be much easier to implement then if we begin with it now. Intersection will contain the data:int num_hits; //how many hits recorded by this ray
HitInfo hit[50]; //list of hits; this could be a STL vectorand these methods:
A constructor, which initializes num_hits to 0.
void set(Intersection source); //sets num_hits to be source's value for num_hits; sets the list of of hits to be the value of source's list of hits
- class Sphere, which will basically just be used to call the appropriate method for determing the hit time with the ray. Sphere will contain no data fields, and only one method:
bool hit(int whichone, Ray3D itRay, Intersection &inter);
//Precondition: whichone is the index of the object; itRay is the "inverse
// transformed" ray to be tested.
//Postcondition: If the object has been hit by itRay, inter contains the record of
// the intersection and true has been returned; otherwise false has been returned.
Scene Description Language:
You may implement the scene description language anyway you want, but a simple language will be provided for you, growing as our scene becomes more complex. The first version is available in rt_2.cpp and is used for placing spheres in the scene and positioning the camera. The file looks something like this:
CAMERA
theta 60.0
N 5.0
pos 3.0 2.0 5.0
ENDCAMERA
BEGIN
sphere
scale 0.2 0.2 0.2
translate -1.0 0.0 0.0
color 1.0 0.0 0.0
#
sphere
scale 0.2 0.2 0.2
translate 1.0 0.0 0.0
color 1.0 0.0 0.0
#
sphere
scale 1.0 0.2 0.2
translate 0.0 0.0 0.0
color 1.0 0.0 0.0
#
sphere
scale 0.2 0.2 0.2
translate -1.0 0.0 0.0
rotate 90.0 0.0 0.0 1.0
color 1.0 1.0 0.0
#
sphere
scale 0.2 0.2 0.2
translate 1.0 0.0 0.0
rotate 90.0 0.0 0.0 1.0
color 1.0 1.0 0.0
#
sphere
scale 1.0 0.2 0.2
rotate 90.0 0.0 0.0 1.0
translate 0.0 0.0 0.0
color 1.0 1.0 0.0
#
sphere
scale 0.2 0.2 0.2
translate -1.0 0.0 0.0
rotate 90.0 0.0 1.0 0.0
color 0.0 0.0 1.0
#
sphere
scale 0.2 0.2 0.2
translate 1.0 0.0 0.0
rotate 90.0 0.0 1.0 0.0
color 0.0 0.0 1.0
#
sphere
scale 1.0 0.2 0.2
rotate 90.0 0.0 1.0 0.0
color 0.0 0.0 1.0
#
END
Driver Program:
Copy your driver program /classes/cs3114/Advanced_Graphics/files/rt_2.cpp. Notice that it now contains functions different from version 1.0. Complete the functions as necessary. Make a scene description file to fit the 2 spheres used in rt_1.cpp and the camera as defined in that scene. Then try more ambitious scenes with your program. The one given above is called jack.scn and is in the file directory.