Computer Science 102

Lab 3

In this lab you will begin the implementation of the plane.c module.

Components that are provided for you include: main.c, ray.h, rayfuns.h, rayhdrs.h, and a makefile. You must provide your own vector.h camera.c (the cam_getdir) function and will build plane.c.

A makefile for the multi-module program:

a.out: main.o plane.o vector.h ray.h rayfuns.h rayhdrs.h

gcc -Wall -g *.o -lm

.c.o: $<

-gcc -c -Wall -c -g $< 2> $(@:.o=.err)

cat $*.err

The plane hits function

double plane_hits(

vec_t *base, /* ray base (the viewpoint) */

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

object_t *obj) /* the plane object */

This function must:

Determine if the ray hits the plane in negative z-space

If so, it must

store the location of the hit point in the object_t struct and

store a unit normal in the object_t structure

return the distance from the viewpoint to the hit point

If not, it must

return(-1);

Creating compressed tar archives

To save disk space and to facilitate transferring archives by e-mail it is common to compress tar archives. In the Linux version of tar the use of the z flag will cause tar to automagically perform compression when an archive is created and decompression when files are extracted.

tar czvf ../plane.tar.gz

tar tzvf ../plane.tar.gz

tar xzvf ../plane.tar.gz

Other versions of tar (such as SUN's) don't support the z flag. In these you must explicitly invoke the gzip and gunzip compression and decompression tools. To create a compressed tar archive:

tar cvf - * | gzip -c > ../plane.tar.gz

In the above command the – following the cvf tells tar to write the output archive to the standard output. The | symbol connects the standard output of tar to the standard input of gzip and the -c flag tells gzip read from the standard input. Note that – must precede c in the gzip but that – may not precede cvf in the tar command. Unix is wonderfully inconsistent in this way.

To uncompress and untar

gunzip -c ../plane.tar.gz | tar xvf -

use care here because tar will overwrite any existing files with the same names as files in the archive with no warning.

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

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

Since this is lab3 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 3 plane.tar.gz

Mike Westall

2007-01-17T09:19:32

Mike Westall