"...ut in omnibus glorificetur Deus."
(...that in all things God may be glorified.)
Rule of St. Benedict (RB 57:9)

      CS 251-Computer Graphics

Homework 2


 
Due: Friday, October 3 Points: 140 points

Written Problems (30 points)

  1. Windows and Viewports (2 points each)
    1. Do practice exercise 3.2.1 in the book (p. 86)
    2. What is the aspect ratio of the world window in exercise 3.2.1?
    3. What will happen to images in the world window if this world window is placed in a viewport with a smaller aspect ratio?
    4. If we wanted to zoom in and double the image size, what new dimensions should we give the viewport?
  2. Clipping lines (5 points each)
    1. Do practice exercise 3.3.1 (#3,4).  Show your work.
  3. Drawing curves (5 points each)
    1. Write a function that draws a parabola (see p. 123), given the center coordinates and the size a.
    2. Write a function that draws rose curves (see p. 126) given the center coordinates, a number of petals and the size (theta).

Programming Project (110 points)

    Write a Drawing program with the following properties:
  1. Your programs should use a class hierarchy with Shape as the base and derived classes for polygons, rectangles, polylines and circles.
  2. The program should use the mouse to draw polygons, rectangles, polylines and circles [default: rectangle].
      RECTANGLES (15 points)
    1. A rectangle should be constructed by clicking once in one corner and releasing in the opposite corner.
    2. The user should be able to select rectangle-drawing by pressing the 'r' key.
      POLYGONS (15 points)
    1. polygons may be constructed by successive left clicks with the mouse. The polygon is completed by a right-click.
    2. The user should be able to select polygon-drawing by pressing the 'p' key.
      CIRCLES (15 points)
    1. A circle should be constructed by clicking once in the center of the circles and then releasing at the outer edge of the circle.
    2. The user should be able to select polygon-drawing by pressing the 'c' key.
      POLYLINES (15 points)
    1. polylines may be constructed by successive left clicks with the mouse. The polyline is completed by a right-click.
    2. The user should be able to select polygon-drawing by pressing the 'y' key.
  3. The program should allow the user to change colors and should save the colors with the shapes [default: black]: (5 points)
    1. '0' should be white
    2. '1' should be red
    3. '2' should be green
    4. '3' should be blue
    5. '4' should be black
  4. (20 points) There should be an option to fill each shape, that can be toggled with 'f' key [default: unfilled].  For polygons, your fill routine need only work correctly with convex polygons.  You may not use openGL's built-in fill routines and so you should add the following to your initialization:    
    glPolygonMode(GL_FRONT, GL_LINE); // set polygon to not fill
    glPolygonMode(GL_BACK, GL_LINE); // set polygon to not fill
  5. All of your shapes should be saved in a Drawing class.  The Drawing class should have the following functionality:
    1. a function to draw all the shapes
  6. (15 points) OPTIONS: (choose one of the following)
    1. Allow the user to save/load images by writing the data to or reading the data from a file named "picture.txt".
    2. Draw each shape as it is being constructed (i.e., while the button is held down for a rectangle, you should see the rectangle that will be drawn once you release the button).  You need not fill the shape in progress, but may show just the outline.  For example, for polygons and polylines, the new vertex is only registered when the left button is released so that the new line is drawn in progress so long as the button is held down, but only permanently added to the polygon once the button is released.  (NOTE: this is different from the extra credit on HW#1.  You need to use the glutMotionFunc routine to do this correctly.)
    3. Add two of the following complex shapes (parameterized house (see exercise 2.3.4 on p.61), teardrops (p.119), rounded rectangles (p.118),  arcs (p. 116), cardioids (p. 126)).
    4. Add functionality to zoom in/out (careful: this must work with your fill routines).
    5. Fill all (including non-convex, holes, etc.) polygons
  7. EXTRA CREDIT: (only acceptable if all other parts are completed) (up to 20 points)
    1. Add a class for ellipses (5 points) or superellipses (10 points).
    2. Do an animation by creating an array of Drawing objects and displaying one after the other. (use double-buffering for this). (5 points)
    3. Allow the user to fill shapes by pressing 'f' and then clicking anywhere inside the shape, after it has been drawn. (10 points).
    4. Do a second OPTION (10 points)
  8. Miscellaneous NOTES:
    1. The display callback function should be very simple, just calling your Drawing::draw() routine which, in turn calls each object's draw routine.  At the end, there must be a glFlush() (see example 5: polylines.cpp)
    2. Your program must be well documented, following the example of the example programs passed out in class. (10 points are given for this)

Turning in your Assignment:

    Hardcopy:
  1. Turn in a sheet with the answers to the written problems.
  2. Do not turn in a print-out of your code.
  3. Softcopy:
  4. Make a directory called "hw2" in your cs251 homework directory.
  5. Place all necessary ".h" and ".cpp" files, as well as the project and workspace files into this directory before class begins (12:30pm).
  6. Create a README file to tell me what OPTION (and Extra credit, if applicable) you chose and what keys/mouse-clicks, etc. are required to make it/them work.