Lab 10: class object_t and class plane_t

Objectives:

To implement and exercise the object_t and plane_t objects

Assignment

  1. Following the class notes, define the object_t class in the object.h interface, providing the following class data members:
      int         cookie;
      NSString   *type;     // e.g., plane, sphere, etc.
      NSString   *name;     // e.g., left_wall, center_sphere, etc.
    
      material_t *mat;      // material
    
      vec_t      *last_hit; // last hit point
      vec_t      *last_N;   // normal at last hit point
    	
    and member functions:
    // - instance methods
      // constructors (overloaded)
    - (id) init;
    
      // accessor/mutator
    - (NSString *) settype: (NSString *)_type;
    - (NSString *) setname: (NSString *)_name;
    - (NSString *) getname;
    - (NSString *) gettype;
    
      // operators
    
      // members
    - (bool) matches: (NSString *) _name;
    - (void) read: (FILE *) _in: (list_t *)mats;
    - (void) write: (FILE *) _file;
    	
  2. The virtual member function (a.k.a. method) hits() is implemented along with the @protocol intersecting protocol defined in object.h
  3. Note the hits() function prototype:
    - (double) hits: (vec_t *) _pos: (vec_t *) _dir: (vec_t **) _hit: (vec_t **) _N
    	
    Notice the pass-by-reference pointers-to-pointers!
  4. For this lab, you can leave the hits() function as an empty stub to be filled in later
  5. Note that the object_t must also implement a hits() function, but in this case a warning should be generated stating that the virtual object cannot be intersected
  6. Following the class notes, define the plane_t object in the plane_t.h interface, providing the following class member functions:
      vec_t  *normal;
      vec_t  *point;
      double  ndotq;
    	
  7. Note that the object plane_t adheres to the intersecting protocol and so must implement the hits() function in the plane_t implementation plane.m
  8. Your code should be such that the following main() routine works unaltered:
            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
      
            list_t          *mats = [(list_t *)[list_t alloc] init];
            list_t          *objs = [(list_t *)[list_t alloc] init];
            material_t      *mat = nil;
            object_t        *obj = nil;
    
            char             token[16];
    
            NSMutableString *str = nil;
    
      NSLog(@"main start");
      NSLog(@"reading stdin");
    
      // input should consist of only material definitions but
      // there can be any number of them in the file
      while(fscanf(stdin,"%s",token)==1) {
    
        if(!strcmp(token,"material")) {
          mat = [(material_t *)[material_t alloc] init];
          [mat read: stdin];
          [mats add: mat];
        }
    
        if(!strcmp(token,"plane")) {
          obj = [(plane_t *)[plane_t alloc] init];
          str = [[NSMutableString alloc] initWithUTF8String: token];
          [obj settype: str];
          [obj read: stdin: mats];
          [objs add: obj];
        }
      }
    
      NSLog(@"done reading stdin");
    
      [mats write: stdout];
      [objs write: stdout];
    
      [str release];
    
      [pool drain];
    
      return 0;
    	
  9. Sample input:
    material green
    {
       ambient 0 5 0
    }
    
    material brown
    {
       ambient 3 3 0
    }
    
    plane wall
    {
       material green
       normal 0 0 1
       point  0 0 -7
    }
    
    plane floor
    {
       material brown
       normal 0 1 1
       point  0 0 -7
    }
    	
  10. Sample output (note that the timestamps will differ):
    2013-01-17 13:15:24.619 main[65286:903] main start
    2013-01-17 13:15:24.621 main[65286:903] reading stdin
    2013-01-17 13:15:24.622 main[65286:903] done reading stdin
    material green
    {
       ambient 0 5 0
    }
    
    material brown
    {
       ambient 3 3 0
    }
    
    plane wall
    {
       material green
       normal 0 0 1
       point 0 0 -7
    }
    
    plane floor
    {
       material brown
       normal 0 1 1
       point 0 0 -7
    }
    	

Turn in

Turn in all of your code, in one tar.gz archive of your lab10/ 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 .c source)
  4. object code (do a make clean before tar)

How to hand in

See submit notes.