Computer Science 102

Lab 4

In this lab you will implement the find_closest_object() function. It should live in object.c.

Components that are provided for you include: main.c, ray.h, rayfuns.h, rayhdrs.h, model.c and a makefile. You must provide your own vector.h, and plane.c. You do not need camera.c or material.c. You MUST NOT supply your own model.c For this lab to work you must a have a functional plane_hits() function. If yours is not yet working, see your TA by e-mail or in person before lab so that it will be working by lab time.

The find_closest_object() function

object_t *find_closest_object(

list_t *list, /* Object list */

vec_t *base, /* Base of ray (viewpoint) */

vec_t *dir, /* unit direction of ray */

object_t *last_hit, /* object last hit (ignore) */

double *retdist) /* return dist to hit point here */

{

object_t *minobj = NULL;

double mindist = -1.0;

:

:

:

return(minobj);

}

Algorithm:

For each object in the object list

if the ray hits the object at a smaller distance than any	previous hit

remember the object

remember the distance

When done, store mindist in *ret_dist and return minobj;

Remember the nesting rules!! A maximum nesting of a single if within a single loop is permitted. The if may have a compound condition though.

In this lab you will submit a compressed tar file named object.tar.gz containing all the components needed to build your program.

sendlab.102.labsection# lab# object.tar.gz

Since this is lab4 and if you are in section 1 the command you should use is (remember to cd .. because that is where you put your tarfile!)

sendlab.102.1 4 object.tar.gz

Mike Westall

2007-01-17T09:19:32