Computer Science 155: Graphics 
Fall 2000 
Homework 1


This assignment is due by the start of class on Wed., Sept. 13.  Please put your name, name of program, and compiling instructions at the top of your files. In addition, describe the features you've implemented and comment each function (explaining briefly what it does and what its arguments are).  You should provide sufficient additional comments for the graders to understand the logic of the program.  A 90 on the homework is perfect but you can also garner 10
bonus points.

 The assignment is to implement a scan conversion and clipping program for line segments .  More specifically, you should write:
    1.  (20 points)  A routine called EasyLines(int x1, int y1, int xfirst, int xlast, int* yvals) that implements Bresenham's Algorithm for scan converting  line
           segments for the special case where the line begins at the origin and has slope between 0 and 1.  The routine arguments include  the second endpoint
           coordinates x1 and y1;  because of the slope constraint y1 <= x1.  To accomodate clipping, the routine also has arguments xfirst and xlast that
           specify the first and last columns of the line in the current viewport..  The routine returns a list of y-coordinates of the "on" pixels; i.e. integers
           yval1, yval2, ...., yvalk such that the on pixels are (xfirst, yval1), (xfirst+1, yval2), ..., (xlast,yvalk)  (so k=xlast-xfirst+1).

    2.  (35 points)  A routine called Lines(int x0, int y0, int x1, int y1, int xfirst, int yfirst, in xlast, int ylast) that scan converts (calling EasyLines) the portion of the line
         segment (x0,y0), (x1,y1) between the pixels (xfirst, yfirst) and (xlast,ylast).  Your routine should be consistent;  i.e. the same pixels should be turned on
         regardless of the order the enpoints are entered,

   3.  (10 points)  Dashed line mode in which every 3rd pixel in the scan-converted line is "off."  If you implement this feature you must make sure your
        scan conversion routine respects endpoint order.

    4.  (15 points)  Clipping to viewport boundaries.  Any implementation including scissoring suffices.

    5.  (10 points)  Using outcodes to make clipping more efficient.  You assign outcodes to each endpoint and check when the line can be trivially rejected
         or trivially accepted.  If the test fails then the clipping method of part 4 is invokes.
 
    6.  (10 points)  Iterative endpoint clipping as described in class.

You may use the hw1.cpp program on the web page to display your lines.  You should modify the "mouse" routine to handle entry of endpoints in line mode.  The
new version (now available from the course page) requires specification of a viewport.  You may want to disable this until you work on clipping.

Submission instructions will be given in class.

    Last modified Sept. 7, 2000 by Z.