Ray Tracing, Version 2.0
Day #4

Goal: Ray trace a scene where

  • the entire scene is on the negative-z side of the world origin,
  • the only objects in the scene are spheres
  • the spheres are generic spheres which may have been translated, scaled, and/or rotated with respect to an axis
  • the only other attribute of each sphere is an assigned (emissive) color
  • the camera is set up anywhere in the scene by giving its position, lookat point, up direction, angle of lens opening, and distance to the near plane.
  • the information describing the camera and objects in the scene is read in from a scene description file using a Scene Description Language.

Ray Tracing Tools:

Add the following classes to ray_tracing_tools, thoroughly testing each:

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_point

and 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

 

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.