For this MP, you will be implementing a drawing routine for Cubic Periodic B-Splines using Forward Differences. Your program will take input from the mouse for the control points of a spline, and you will draw the B-spline defined by the control points, the control points themselves, and line segments connecting the control points.
Since you will be implementing your own spline drawing routine, you may not use the built in OpenGL evaluator functions, nor the GLU NURBS functions. See the Restrictions section below for specifics.
Upon completion of this MP, you should be able to do the following things:
Read Chapter 10, sections 6 through 13, in the required text for this class - ``Computer Graphics, C Version, 2nd Edition'' by Hearn & Baker. It discusses various splines, forward differences, and basic concepts you will need for this MP.
For this MP, you will need to use two mouse buttons. Their functionality is described below. You can use the code from previous MPs to get mouse coordinates. Get your program working with just entering the control points and drawing the connecting line segments. Worry about drawing the spline later.
You are to write a program that allows the user to enter control points for a spline. Your program then uses these control points to plot a Cubic Periodic B-Spline, using Forward Differences to do the actual plotting of the B-spline. You must implement the following inputs to the mouse and the keyboard.
The Left Mouse Button is used to enter control points for the B-Spline. Each button press adds one more control point. As the user enters control points, your program should draw each control point as a large square POINT, and connect the control points with LINE SEGMENTS. You should allow a maximum of 50 control points. Follow these conventions when drawing the control points and the connecting line segments:
In this MP, you do not connect the first and last control point with a line segment. The user can enter up to 50 control points. If the user tries to enter more than 50 control points, simply ignore those mouse clicks. You do not need to print an error message.
When four or more control points have been entered, your program should also draw the B-spline defined by these control points. As the user enters more control points, the B-spline will become longer. See below for specifics about drawing the spline.
The Spacebar is used to clear all control points. In essence, typing a space character clears the screen, and allows the user to enter new control points for the spline.
The Backspace key is used to clear the most recently entered control point. For example, if there are four control points and the user types the <Backspace> key, the fourth control point is ``deleted'' and the user is left with three control points. If there are no control points on the screen, the <Backspace> key has no effect.
Be sure to redraw the spline when the user deletes a control point to reflect the spline formed by the remaining control points. Hint: To test for the <Backspace> key in C, check for '\b' in your callback function specified by glutKeyboardFunc.
When the user types the letter ``q'' or ``Q'', the program should exit.
Once the user has entered at least 4 control points, your program should draw the Cubic Periodic B-Spline defined by these control points. (For a description of Cubic Periodic B-Splines, see pp. 339-341 in the textbook.) Follow these conventions when drawing the B-Spline:
To draw the B-spline, you must use Forward Difference calculations as described on pp. 351-353 of the textbook. You may not use Horner's Rule or Subdivision to draw the curve. When drawing the curve, use a precision of at least 20, but no more than 50. (The ``precision'' is the number of line segments used in drawing the curve.) So, when computing the forward differences, a precision of 20 results in a ``delta'' of 1/20 = 0.05.
This section lists restrictions that are placed on your program. Please read this section carefully, or you may lose points by implementing something incorrectly.
Remember that you are not restricted to using just the required textbook for this class. There is a large selection of graphics books on reserve in Grainger Library. In them, you should be able to find additional information on splines and forward differences.
Those graduate students enrolled for 1 unit of credit, and undergrad students registered for honors credit, must also implement the following additional functionality.
Your program will also use the Right Mouse Button to allow the user to move control points after they have been entered.
When the user clicks with the Right Mouse Button, your program should check to see if the click was ``sufficiently close to'' an existing control point. As in previous MPs, ``sufficiently close'' is defined as: within 3 pixels (in either the X or Y direction) of an existing control point. If there is such a control point, then draw that control point in WHITE (glColor3f(1.0,1.0,1.0)), and wait for the user to click again with the Right Mouse Button. The next click of the Right Mouse Button sets the new position for that control point. Draw the control point there (in BLUE) and redraw the connecting line segments and the B-spline.
When the user has selected a control point for moving, be sure the user then clicks again with the Right Mouse Button to designate a new location for that control point. In other words, if there is a control point selected for moving, do not allow the user to enter new control points (by clicking with the Left Mouse Button) or clear the existing control points (by typing the <Spacebar> key or the <Backspace> key).
For this and future MPs, we will be using the electronic handin program. Once you have completed your program, logon or telnet to one of the Sun Sparc machines (``handin'' does not work on the WindowsNT machines) and hand in your source code by typing ``handin cs318 mp4 mp4.c''. (For more information on handing in your code, consult the class web page at http://www-courses.cs.uiuc.edu/~cs318/handin.html.) This will send your program to the class directory for grading.
Do not submit your executable program. Also, put all your source code in one file. You must hand in your source code file before 10:00am of the due date, as handin will not accept late assignments. Make sure your name, login, MP#, and date appear at the top of your code listing. See the class web page for a sample file header.
If your program does not run as required, you will be given at most 50% of the total points for the MP. You are responsible for making sure your program compiles on the WindowsNT machines using the makewin batch file.
Late assignments will not be accepted. If you are having problems beyond your control, you must let a TA know at least 24 hours before the due date to arrange for a possible extension. There will be no exceptions!