CS-560, Assignment # 3
Due Date: 3-1-02

Part A

In this part of the assignment you are to write a Visual C++, OpenGL 
program that displays a pattern of straight lines on the window client 
area using the following line-drawing algorithms: your implementations 
of "Brute Force", "DDA", and "Bresenham" (discussed in class) and the 
OpenGL GL_LINES line-drawing function. In each case the pattern is to 
be a "sunburst" which occupies most or all of the window's client area 
(see  below). Each sunburst should be drawn in response to a menu item 
or some keyboard key. (The details of how this is done are up to you.) 
Each pattern should be displayed in a different color, and, after the 
pattern is drawn, the name of the algorithm should be displayed. (The 
MessageBox() function, for example, could be used.) 

Each sunburst pattern should appear as follows: lines drawn from the
center of the window client area to every fifth pixel in the top and
bottom rows of the window client area and lines from the center of 
the window client area to every fifth pixel in the left-most and 
right-most columns of the window client area. See diagram below. 
(This will include all  four Bresenham cases.) In each case, the 
parameters sent to the line-drawing routines should be the coordinates 
of the endpoints of the line. 

Since the assignment is to be done in OpenGL, you should set things up 
so that the viewing area is a rectangular box whose x-y dimension is 
approximately the size of the window's client area. You can, for 
example, use the OpenGL function glOrtho(-w,w,-h,h,-100,100) after 
OpenGL is initialized (in response to WM_CREATE). Here w is half the 
width of the window and h half its height. You could just use some 
number like 400 for the width and height or perhaps call GetClientRect() 
to get the size of the window's client area.

In the case of the OpenGL lines, you will have, inside the 
GL_Begin(GL_LINES) - GL_End() sandwich, pairs of calls to glVertex2i(x,y), 
where (x,y) will be endpoint coordinates of each line in the sunburst. In 
the case of DDA, Bresenhem and Brute Force, it is suggested that you write 
separate functions that implement the two line-drawing algorithms. The 
function prototypes might be something like: void linebres(int x1, int y1, 
int x2, int y2); linebruteforce(int x1, int y1, int x2, int y2); and
lineDDA(int x1, int y1, intx2, int y2). In  each of these functions the 
plotting of each pixel on the line would be done with a call to 
glVertex2i(x,y). In each case you would make the  appropriate calls to 
linebres(), line DDA, and linebruteforce() inside a  GL_Begin(GL_POINTS) - 
GL_End() sandwich in order do draw the sunburst pattern.

The output of Part A might look something like this. 

Part B

In this part of the assignment you are to write a Visual C++, OpenGL 
program that displays a pattern of circles on the window client area 
using the "midpoint circle" algorithm (discussed in class and in your 
book). The pattern is up to you, but it should have at least 10 circles of 
different sizes located at different positions on the window's client area. 
The circles should not be filled. Again, as in Part A, the the triggering 
of each pattern can be through either a menu or keyboard key presses. This 
part of the assignment could be implemented in the same program in which 
you did the Bresenham and Brute Force lines; in other words, just set up a 
function that draws a circle or radius r and whose center is at (h,k) in 
the OpenGL viewing area, and make appropiate calls to that routine inside
a GL_Begin(GL_POINTS) - glEnd() sandwich. As for the line-drawing 
algorithms your circle-drawing function will have to make calls to 
glVertex2i(x,y) to plot pixels on the arc of the circle.

The output of Part B might look something like this.
Part C
In this part of the assignment you are to devise and implement a
"midpoint parabola" algorithm that will scan convert and plot a simple
parabola efficiently by using the same approach as the midpoint circle
and midpoint ellipse algorithms discussed in class. The equation to be
scan converted is:
                       y = c * x

In this equation, c is a parameter that determines the shape of the
parabola. (In 640 X 480 graphics modes, a value of about 0.001 works
well.) You can hard-code the value of c, the starting x value, and the 
ending x value (all positive). The program should display the resulting 
parabola in the window client area. There should be no gaps in the curve, 
so your algorithm will have to step in the x direction for one section 
of the parabola and in the y direction for the rest of the curve. As in 
the midpoint ellipse algorithm discussed in class, an incremental 
calculation should be used to determine when the stepping changes 

You should also include in the program a "brute force" parabola
algorithm that plots the same parabola in some other color by direct
calculation instead of incrementally. (If your algorithms are correct,
the second parabola should overlay the first.)

You may implement this part of the assignment using either the Windows 
GDI (i.e., with the SetPixel() function) or with OpenGL (as in Parts A 
and B).

The output of Part C might look something like this. Here the GDI was
used to plot the parabolas and several different parabolas were
plotted (the value of the constant c was varied). The different colors 
illustrate the two midpoint algorithm "Regions" -- i.e., green where 
the slope is less than 1 and white where it's greater than 1. Note, 
that with GDI, the y-axis points downward and the origin is at the 
upper lefthand corner of the window.