CPSC 102 Computer Science II
(Advanced C Programming)

Assignment 7

Objectives:

To implement a simple ray caster; this is a redo of the basic ray caster implemented in C re-written in Objective-C.

Description:

  1. Using the find_closest function implement a simple (one-hit) ray tracer (known as a ray caster) to process the model file given below.
  2. See the notes (pp.20-23 in particular).
  3. You can use the timer_t object to time how long it takes to ray trace the scene.
  4. Sample input:
    camera cam1
    {
       pixeldim 640 480
       worlddim 8   6
       viewpoint 4 3 6
    }
    
    material green
    {
       ambient 0 5 0
    }
    
    material yellow
    {
       ambient  5 4 0
       diffuse  4 4 0
      specular  1 1 1
    }
    
    plane leftwall
    {
       material green
       normal 3 0 1
       point  0 0 0
    }
    
    plane rightwall
    {
       material yellow
       normal -3 0 1
       point   8 0 0
    }
    
    material gray
    {
       ambient 2 2 2
    }
    
    plane floor
    {
       material gray
       normal 0 1 0
       point  0 -0.2 0
    }
    	
  5. Sample output:

  6. Changing the left and right wall normals' z-components to 0.1, i.e.,
    plane leftwall
    {
       material green
       normal 3 0 0.1
       point  0 0 0
    }
    
    plane rightwall
    {
       material yellow
       normal -3 0 0.1
       point   8 0 0
    }
    	
    and re-running the code produces the image below:

  7. Using the following cbox.txt model:
    camera cam
    {
       pixeldim 512 384
       worlddim  5.12 3.84
       viewpoint 2.56 2 5
    }
    
    light top
    {
       location 2.56 3.80 -1.5
       emissivity 1 1 1
    }
    
    material gray
    {
       ambient 3 3 3
       diffuse  .9 .9 .9
    }
    
    material green
    {
       ambient 0 5 0
       diffuse 0 .5 0
    }
    
    material salamander
    {
       ambient 3 2 2
       diffuse  .9 .9 .9
    }
    
    material slate
    {
       ambient 2 1.8 3
       diffuse  .9 .9 .9
    }
    
    material transparent
    {
       ambient  3 3 3
       diffuse  .1 .1 .1
      specular  .9 .9 .9
        alpha  .9
          ior  1.83
    }
    
    material chrome
    {
       ambient  3 3 3
       diffuse  .1 .1 .1
      specular  .9 .9 .9
    }
    
    plane backwall
    {
       material gray
       normal 0 0 1
       point  0 0 -5
    }
    
    plane leftwall
    {
       material salamander
       normal 1 0 0
       point  0 0 0
    }
    
    plane rightwall
    {
       material slate
       normal -1 0 0
       point   5.12 0 0
    }
    
    plane ceiling
    {
       material gray
       normal  0 -1 0
       point   0 3.84 0
    }
    
    plane floor
    {
       material gray
       normal 0 1 0
       point  0 -0.2 0
    }
    
    sphere left
    {
       material chrome
       center 1.25 .75 -4
       radius .9
    }
    
    sphere right
    {
       material transparent
       center 3.7 .7 -2.3
       radius .9
    }
    	
    and re-running the code produces the image below:

What to hand in:

A tar.gz archive of your asg7/ directory, including:
  1. A README file containing
    1. Course id--section no
    2. Name
    3. Assignment 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 .c source)
  4. object code (do a make clean before tar)

How to hand in:

See submit notes.