CE325: 3D Computer Graphics

Laboratory Session 3

The purposes of the lab session are:

You should work through the following steps.

  1. If your machine isn't already running Linux, re-boot it to do so and log in.

  2. Save the compiled test harness into a file called harness.o (as in the first lab session, it has to be stored with a different name for the campus web-server to allow you to download it). Ensure that its name ends in ".o" and not ".c" — it is a compiled file ("object code" or "relocatable binary"), so you won't be able to look at its contents. This is deliberate as test-driven development works best when the person writing the code has no knowledge of the detail of the tests.

  3. In the harness, a vector is represented as a float array of length n, equivalent to

      float v[n];
    

    Each of the routines you have to write (see below) is passed one or more vectors declared in this way.

  4. Cut and paste the following code into a file called vectors.h:

    //-----------------------------------------------------------------------------
    // v e c t o r s . h   --   header file for vector manipulation routines
    //-----------------------------------------------------------------------------
    
    float vec_length (const float *v, int n);
    void vec_add (float *v1, const float *v2, int n);   // v1 = v1 + v2
    void vec_copy (float *v1, const float *v2, int n);  // v1 = v2
    void vec_negate (float *v1, int n);                 // v1 = -v1
    void vec_print (const float *v, int n);
    float vec_scalar_product (const float *v1, const float *v2, int n);
    void vec_vector_product (float *result, const float *v1, const float *v2,
    			 int n);
    
    //-----------------------------------------------------------------------------
    // End of vectors.h
    //-----------------------------------------------------------------------------
    
    These show you the parameters of the seven small modules that you are to write. The purposes of the routines will hopefully be clear from their names — if they are not, clarify them with a demonstrator.
  5. Write your versions of the seven routines in a file called vectors.c in the same directory (folder) as harness.o and vectors.h.

  6. Compile your routines with the harness using the command:

    gcc -Wall -o harness harness.o vectors.c -lm
    
  7. If your code is correct, it will pass all 25 tests when you run harness. If it does not, keep correcting your routines (and re-compiling) until they do pass all the tests.

These routines should prove useful for your first assignment, which will start shortly.


© Adrian F. Clark 2010-11