Homework 9
22C:151 Introduction to Computer Graphics
Due Thursday, December 11, 2003
(20 points)
Write a program that allows mouse-based interactive editing
and display of 2D interpolating cubic, Bezier, and B-spline curves
based on four control points.
You may use either 1 or 3 OpenGL windows. If you use 1 window, divide it
into three regions, one for each curve (draw a solid line or something, so that
the regions are clear). If you want to use 3 windows and can't figure it
out from the book, let me know; it's not difficult.
Each region (or window) should show the same arrangement of control points; there are
simply 3 "copies" of the same set of control points. In
one region you should draw an interpolating curve through the control points.
The other two regions will display Bezier and B splines for the same control points.
Thus, at all times you'll be able to see the three different curves corresponding
to the given control points.
You may initialize your program so that three copies of an
initial set of four control points are displayed when the program
starts (in other words, it is not required that you interactively enter the initial
locations of the control points).
Requirements:
- At all times you should display, either one per region in one window, or
in three separate windows, the three spline curves corresponding to the control points.
The control points should be clearly drawn as well (e.g. using large dots/small
circles of a different color). It should also be possible
to toggle on and off line segments that connect the control
points in order.
- It must be possible to select, with the mouse, any
control point and interactively move it. The curves
should be redrawn during movement. When you select a control point,
the two "copies" of it in the other regions (windows) should move in
the same way as the one you select.
- You must implement 3 different methods of drawing the curve. Each
will be a Bezier curve drawing method. To use these drawing methods to
draw interpolating or B-spline curves, you will first have to transform
the given interpolating or B-spline control points into Bezier control points
(you don't draw these control points on the screen - you just use them as
input to the curve drawing routines).
- implement a function that, given control points, P0, P1, P2, P3,
and a paramter value s (0 <= s <= 1), returns the 2D point at parameter value
s on the Bezier curve defined by those control points. Then draw the curve by
writing you own loop to create a GL_LINE_STRIP using a set of points evenly
distributed along the Bezier curve. It must be possible to control (e.g. by use of
+/- keys) the number of points used to draw the curve.
- let OpenGL do the Bezier point evaluation for you. To do
this, learn how to use the glMap1f function. If you properly pass
your four control points to the glMap1f function. Then you can
draw the curve a little more simply than in method 1. To draw the
same GL_LINE_STRIP of method 1, you'll just need to call glEvalCoord1f
many times instead of needing to call both your own Bezier curve evaluation
function and glVertex (glEvalCoord1f does the evaluation and glVertex for you).
As in method 1, it must be possible to interactively control the number of points
used to draw the curve.
- implement the recursive subdivision method covered in class. It must
be possible to control (e.g. by use of +/- keys) the strictness of the
flatness test used to terminate the recursion. E.g. if the user hits '-'
several times, we expect that the recursion will terminate sooner and
the curve will be coarser, drawn with fewer points.
Submitting your program
Submit your assignment according to the guidelines on the class WWW home page. For the
on-line part of the submission, respond 'hw9' to the ``Location:''
request.