Homework #1 for CAP4730 (Spring, 2009)

due: 01 Feb 2009

credits: 100


-Write an OpenGL program to implement a Spline Sketcher.

Part A: spline sketch

  1. [5] Draw a 500×500 window with black background. Set the title of the window to "grade_id / name". (See Fig.1)

  2. [10] Place six control points P0, P1, P2, P3, P4, P5 in the window as follows: control points P0, P1, P2, P3, P4, P5 equally distributed on the unit circle

    grade_id / name
       P2-----P1
      /        \
     /          \
    P3           P0
     \          /
      \        /
       P4-----P5

    Draw the control points Pi with the size of 5×5 pixels in green and connect them with white lines to form the control polygon.

  3. Plot the spline curves defined by the control polygon above. 

    1. [10] When the key '1' is pressed,

      for each i = 0, ..., 5, (suppose i = i mod 6)

       

      • ci1 := ( 2*Pi + Pi+1 ) / 3
      • ci2 := ( Pi + 2*Pi+1 ) / 3

      Determine ci0 and ci3 so that the polynomial pieces join C2. Write down the formula for ci0 and ci3 and put it into your readme file.

      Draw those points in red color with the size of 3×3 then connect them to form the piecewise linear curves.

      Use the function glMap1() to draw the cubic curves with their control points of ci0, ci1, ci2, ci3.(See Fig.1)

    2. [10] When the key '2' is pressed, iterate cubic uniform subdivision as defined in the following: 

      ck2i := ( ck-1i-1 + 6*ck-1i+ck-1i+1 ) / 8
      ck2i+1 := ( ck-1i + ck-1i+1 ) /2

    3. [10] When the key '3' is pressed, use a single gluNurbsCurve() function call to plot the cubic curve (See Fig.2). What is the number of knots, order and number of control points?  How do you make sure the curve is closed? Put the answer in the readme file.

    4. [10] Is the curve a circle? Can you choose the six control points so that the curve becomes a circle? What is the relationship between (a), (b) and (c)? Put the answer into readme. 

    Note:
    1. Pick different colors (as you like) to draw the curves.

    Fig.1 Fig.2 Fig.3


  4. Part B: spline interaction

  5. [15] Allow the position of control points to be interactively modified: when the left mouse button is clicked sufficiently near to a control point, that point will be picked and follow the motion of mouse cursor. If the SHIFT key is depressed,  picking and dragging  moves in the z-direction; if it is not depressed, picking and dragging in the x-y plane. Refresh the control polygon and the curve while the mouse is moving. Releasing the left button stops the motion.

  6. [20] When key '4' is pressed, create a side view of curves to see the picking and dragging in z-direction and have a box moving along the curve in both views (See Fig.3). You can use the control points from a. 

  7. [10] Allow the resizing of the window. Adjust the control points and the curve according to the size of the window. The picking and dragging of the control points should work as above regardless of the size of the window.

  8. Program exits when ESC key is pressed and gets reset when 'r' is pressed.


files to submit

You're supposed to submit the following files.


demo program

Here are executables for each platform. In the demo you can hide the curves by pressing space bar (this is not required in your implementation).


how to test your programs

I will test your program on one of the machines of lin313-0*.cise.ufl.edu by the following steps.

  1. Read your readme file.
  2. Execute the script file run (to compile and run your program, see sample).
  3. Switch between the ways of drawing the curve (by pressing "1" through "3" and '4')
  4. Click and drag some control points in the window.
  5. Repeat 3.
  6. Resize your window, and repeat step 4 and 5.
  7. Take a look at your source code.