class object_t and class plane_tobject_t and plane_t objects
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;
hits() is implemented along with the
@protocol intersecting protocol
defined in object.h
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!
hits() function as an
empty stub to be filled in later
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
plane_t
object in the plane_t.h interface, providing
the following class member functions:
vec_t *normal;
vec_t *point;
double ndotq;
plane_t adheres to the
intersecting protocol and so must implement the
hits() function in the plane_t
implementation plane.m
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;
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
}
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
}
tar.gz
archive of your lab10/ directory, including:
README file containing
Makefile
.h headers and .c source)
make clean before tar)
submit notes.