Programming Assignment 2

Due Dates: Part 1 - Wed. 4/23/97, Part 2 - Mon. 5/5/97

This lab is designed to give you experience with 2D transformations, windowing, line/polygon clipping, and animation.

Part 1

Write an application program that uses the routines in lab2part1Routines.o and lab2part1OutputRoutines.o to demonstrate that you understand the concepts of 2D transformations, animation, and "windowing". Your application program should minimally do the following:

  1. Create a scene and display it.
  2. Use at least 3 different combinations of SetWindow and SetViewport with the scene from step 1 to create an image on a single screen.
  3. Create an object and animate it using rotation.
  4. Create an object and animate it using scaling.
  5. Create an object and animate it using translation.
  6. Create an animation using multiple images.
  7. Use ClearScreen in appropriate places.

NOTE 1: Examples of previous student work is available by running ~icss570/xdemo2.sgi or ~icss570/xdemo2.sparc. These are scripts containing two different sets of student work.

NOTE 2: All the file names that are referenced pretain to files provided in the /usr/local/pub/ncs/graphics/lab2 directory. The filenames will be referenced assuming this directory name as part of the filename, i.e., if the filename referenced is README, its absolute name is /usr/local/pub/ncs/graphics/lab2/README.

NOTE 3: lab2part1OutputRoutines.o and lab2part1Routines.o are available in the directories part1.sgi and part1.sparc compiled for the sgi's and sparc's, respectively.

NOTE 4: Sample makefiles for the sgi's and sparc's are provided in sgipart1makefile and sparcpart1makefile, respectively. Note that these makefiles are organized so that you do NOT need to copy lab2part1OutputRoutines.o, lab2part1Routines.o, nor any of the .h files needed for the lab.

NOTE 5: The routines you will use from lab2part1Routines.o are:

  1. AddRotation(float angle) where angle is the angle of rotaion in radians. This routine prepends the rotation matrix to the global composite transformation matrix, CM.
  2. AddScale(float sx, float sy) where sx and sy are the scale factors. This routine prepends the scale matrix to the global composite transformation matrix, CM.
  3. AddTranslation(float tx, float ty) where tx and ty are the translation factors in world coordinates. This routine prepends the translation matrix to the global composite transformation matrix, CM.
  4. ClearScreen( )
  5. InitializeCompositeMatrix( ) initializes the global composite transformation matrix, CM, to the identity matrix.
  6. mySRGP_begin(char *name, int w, int h, int planes, boolean trace) - Initializes global variables and calls SRGP_begin. Parameters are identical to SRGP_begin.
  7. SetWindow(rectangle View_Window_rectangle) where View_Window_rectangle is a rectangle that specifies the rectangular area of the world to be shown on the screen.
  8. SetViewport(rectangle Viewport_rectangle) where Viewport_rectangle is a rectangle specifying the rectangular area of the screen where the View_Window_rectangle is to be displayed. If the specified Viewport_rectangle goes outside the screen boundary, an error message is printed and the screen boundaries will be used instead, if possible.

NOTE 6: lab2Externs.h contains the interface specifications.

NOTE 7: lab2part1OutputRoutines.o contains "mySRGP" output routines similar to those that you implemented in lab 1. In all cases though the current composite matrix CM and then the viewing transformation defined by the Window and Viewport specifications are applied to all of the vertices before the SRGP output primitives are executed. The routines available are mySRGP_line, mySRGP_polyLine, mySRGP_rectangle, mySRGP_polygon, mySRGP_fillRectangle and mySRGP_fillPolygon. (See lab2OutputExterns.h for the "mySRGP" interface specifications - same as for SRGP.)

NOTE 8: A lab2Ellipses.h and lab2Ellipses.o are also provided for filled and unfilled ellipses. These may be used for both part 1 and part 2. (PLEASE NOTE THAT ELLIPSE ROTATION WILL FAIL!!!) If you chose to use them you will need to modify your makefile for part 2 to reflect linking to the appropriate directory from part 1, i.e., part1.sgi or part1.sparc.

NOTE 9: 15 percent of the grade for part 1 will be based (subjectively) on the how interesting/complex your design is.

Part 2

For part 2, you will implement the routines used in part 1. lab2Externs.h and lab2OutputExterns.h are available for your use as are template files for the lab2OutputRoutines.c and lab2Routines.c.

Assuming that Matrix defines a 2X3 floating point array (specified in lab2types.h), implement the following routines:

  1. AddRotation(float angle) where angle is the angle of rotaion in radians. This routine should prepend the rotation matrix to the global composite transformation matrix, CM.
  2. AddScale(float sx, float sy) where sx and sy are the scale factors. This routine should prepend the scale matrix to the global composite transformation matrix, CM.
  3. AddTranslation(float tx, float ty) where tx and ty are the translation factors in world coordinates. This routine should prepend the translation matrix to the global composite transformation matrix, CM.
  4. ApplyCompositeMatrix(int numberIn, point *vertices, point *outVertices) where numberIn is the number of vertices and vertices contains the vertices themselves to be transformed by the composite matrix and outVertices contains the transformed points to be supplied to the mySRGP output primitive. This routine will apply the composite matrix, CM, to vertices before they are passed onto the appropriate SRGP output primitive.
  5. ApplyViewingTransform(int numberIn, point *vertices, int *numberOut, point *outVertices) where numberIn is the number of vertices and vertices contains the vertices themselves supplied to the mySRGP output primitive; numberOut and outVertices are similar values, respectively, that result from applying the window to viewport viewing transformation, including clipping to the input vertices. This routine will use your implementation of the Sutherland-Hodgman clipping algorithm.
  6. ClearScreen( )
  7. InitializeCompositeMatrix( ) initializes the global composite transformation matrix, CM, (specified in lab2globals.h) to the identity matrix.
  8. mySRGP_begin(char *name, int w, int h, int planes, boolean trace) - Initializes global variables and calls SRGP_begin.
  9. SetViewport(rectangle Viewport_rectangle) - This routine should just change the global variable, Viewport, (specified in lab2globals.h) to be used by ApplyViewingTransform. Initial values should be the screen size as specified in SRGP_begin. If the specified viewport goes outside screen boundary, print an error message and use the screen boundaries instead.
  10. SetWindow(rectangle View_Window_rectangle) - This routine should just change the global variable, ViewWindow, (specified in lab2globals.h) to be used by ApplyViewingTransform. Initial values should be the screen size as specified in SRGP_begin.

NOTE 1: You may also need to modify your lab2Outputroutines.c to utilize both the composite matrix, the viewing transformation matrix and the clipping that is implicit in the latter. (I believe the template_lab2OutputRoutines.c already does this, but if, for instance, you want to use ellipses in your application program, you may need to make modifications to it.)

NOTE 2: The directory lab2testdir contains a sample makefile (testmakefile) and testcases to help you debug part 2. Executables are also provided for both the sgi's and the sparc's in lab2testdir/exec.sgi and lab2testdir/exec.sparc, respectively. See the README file for details.

What to submit:

For Part 1, you are to submit a directory called lab2dir using the following command:

submit -v paw-grd lab2part1 lab2dir

where lab2dir contains your application program (BE SURE TO NAME IT lab2.c), a READ_ME file (please include a hardcopy in the front of your lab folder), stating what your application program is showing in each frame, and a makefile. (No .o files or executables, please)

The makefile should include a target lab2, i.e., I should be able to type

make lab2

which should compile your application program and create the executable file lab2.lib. This is to be created by linking your application program with lab2part1OutputRoutines.o and lab2part1Routines.o.

For Part 2, you are to submit a directory called lab2dir using the following command

submit -v paw-grd lab2part2 lab2dir

where lab2dir contains the files lab2Routines.c, lab2OutputRoutines.c and your application program from part 1 (no .o files or executables please.)

The makefile should include a target lab2, i.e., I should be able to type

make lab2.

This should compile the source files and create the executable file lab2.yours, which is to be created by linking your application program with your implementation routines.

Grading:

Your overall lab grade will be based on the following: the implementation of required routines, the demonstration of the required routines, the complexity (how interesting) of graphical output, internal documentation, and program design.

When the grader begins grading your program, if there are any problems with the submittal, the grader will send you e-mail and you must then resubmit within 24 hours. Incorrect submittals are subject to penalties!

Hardcopy:

Hardcopy of all files including all of your .h and .c files, the makefile and the READ_ME file should be submitted on the day following the due date for each part.


January 6, 1997 at 12:33 PM