BU CLA CS 480: Introduction to Computer Graphics

Spring 1995

Programming Assignment 2---due Friday, February 27


This programming assignment will help to deepen your understanding of 2-D transformations and clipping. In addition, you may learn about some basic concepts in computer animation. You will write a few subroutines in C, and then link them with some other routines and a main program that are provided. The resulting program will be a animation tool that allows your to apply 2-D transforms to polylines, and to clip them to a viewing rectangle.

Copy Some Files

Some basic graphics utilities and the animation tool's main program are provided for you. So, before you begin programming, you will need to copy seven files from the directory /usr3/faculty/sclaroff/program2 on the CGL cluster. These are:

Like the last assignment, you are expected to complete the program by providing two missing subroutines using the code templates.

Run the Example Animation Tool

In the same directory, you will also find an example of a fully functioning animation program. You may run this to see how your program should work. To run the program, type

animate_example filename.poly

where you specify a polyline file as input. There are two polyline files provided in the assignment directory: box.poly and figure.poly . These are text files and have a straight-forward format.

The user interface to the animation tool is through a seperate user interface window. This window has sliders and buttons. The sliders control the transformation parameters for: rotation, translation, scaling, shearing, and bending. Beside each slider there is a small button that you can push to reset it's value to the default values.

There are also three buttons on this menu:

The Code You Write

You are expected to write two new routines based on the templates provided in the files transform.c and clip.c :

  1. Write a polyline transformation routine. This routine uses nine transform parameters to define the appropriate transformation and then applies it to each of the polyline's points. These nine transform parameters are:

    When transforming the points, do the non-rigid transforms first, then scaling, rotation, and translation. Also be sure to rotate around the polyline's center point, which is stored in the polyline structure.

  2. Write a line clipping routine based on the parametric line clipping algorithm described in Section 3.9.4 in the text.

em There are comments in the two template files that will help guide you in writing your own subroutines.

Test Cases

There are no test cases provided in this assignment. You should instead make sure that you final program can correctly clip and transform the polylines.

Grading

Demo

As in the previous assignment, part of your grade for this programming assignment will be based on your giving a 4 minute demo in the CGL cluster. You will be expected to talk about how your animation tool works, and we will test it on a few examples. Demos will be scheduled for Monday Feb. 27, from 1:00 to 5:00. You will be asked to sign up for a slot by next Wednesday. Write-up

You will also be graded on a very brief write-up that is to be turned in at the beginning of class on Moday, Feb. 27. Basically, this write-up should include a paragraph describing what design choices you made in writing your subroutines, and hard copy of all your code. The code should be commented so that it is easily understood.

Extra Credit

For extra credit, create your own animation with the animation tool. Modify the subroutine playCB to play your animation. You may also want to define your own polyline files, or you may want to modify the program to handle multiple polylines.

Start programming early. Late assignments will not be graded.

Utilities provided

The file draw.c contains utilities for opening and managing windows:

  • open_window opens a window and initializes the device event handling
  • close_window closes a window

    There are also polyline and clipping frame management routines:

  • create_polyline allocates and initializes a polyline data structure
  • free_polyline frees a polyline
  • read_polyline_file reads in a polyline data structure form a file
  • create_frame allocates a clipping frame data structure
  • free_frame frees a frame

    There are also routines for drawing:

  • redraw redraws both the frame and the polyline to the window
  • draw_line draws a line using GL
  • draw_frame draws a clipping frame
  • clip_draw_polyline calls the line clipper for each polyline segment

    The file menu.c contains routines that manage the user interface widgets. You don't need to look at these unless you want to.

    Finally, animate.c contains some routines that are called whenever the user moves something on the user interface menu. These routines are called ``call back'' routines, because the user interface calls back to them when an interaction event occurs. These routines are:

  • quitCB frees up memory, closes window, and then quits
  • playCB plays the animation
  • setup_sliders initializes the transform parameter sliders
  • reset_slidersCB resets the transform sliders to default values
  • reset_sliderCB resets a particular transform slider

    You will notice that there are some global variables declared in animate.c . These are needed to support the user interface's call-back routine structure.


    Stan Sclaroff
    Created: January 17, 1995