CS633
Spring, 2008
Programming Assignment 1 (40 points)
Due: February 22 (Friday)
----------------------------
Animating a 2D rolling ball
----------------------------
1. Problem Description
In this assignment you are required to modify the given OpenGL program
so that a user can roll a ball along a closed 2D curve utilizing
ease-in/ease-out motions. Initially, the program should display a layout
as follows on your screen:
_____________________________________________________
| _______ ________ _______ ________ |
| |Input| |Input | |Start| |Stop | |
| |Curve| |Radius| | | | | |
| ------- -------- ------- -------- |
|_____________________________________________________|
| |
| |
| |
| |
| |
| A |
| |
| |
| |
| |
| |
| |
|_____________________________________________________|
| |
| B |
|_____________________________________________________|
The four small rectangular areas (with different labels) are supposed
to act as menu items. By clicking in the first rectangular area (the
one labeled with "Input Curve"), a user can generate a closed, uniform
cubic B-spline space curve that interpolates a set of data points input
by the user in the region (A) below. The user inputs the data points
by clicking (the left button) at a set of points in this region. The
input phase is terminated by clicking the middle button of the mouse.
By clicking in the second small rectangular area (labeled with "Input
Radius"), the user can input the radius of a 2D ball by clicking (the
left button) at two points of A. By clicking in the third small
rectangular area (the one labeled with "Start"), the user starts the
animation process and by clicking in the fourth area (the one labeled
with "Stop"), the user terminates the animation. The user should be
allowed to perform the animation as many times as possible.
Region B is for your program to show the information input by the user
(such as data points, radius of the circle) and current status of the
animation.
2. Implementation Details
In the space curve input process, each data point input by the user should
be clearly identified by the program (such as marking it with a small cross)
with its coordinates shown in Region B. The program should use the lower-
left corner of Region A as the origin (0,0) of the coordinate system.
The user should be allowed to delete a most recently input data point by
clicking the right most button of the mouse. When the middle button is
clicked, the program should first remove all the symbols used to identify
the input data points and then generate a closed uniform cubic B-spline
curve to interpolate the input data points. The curve should be constructed
USING THE FIRST APPROACH INTRODUCED IN CLASS with its control points shown
in Region B. The space curve should have at least two local minima and
should not intersect itself. Coordinates of the local minima should also
be shown in Region B.
In the radius input process, the user should again be allowed to delete an
input point by clicking the right most button of the mouse. The two input
points will be used to determine the radius of the ball (2D circle) only
when the middle button is clicked by the user. When that is done, the
program should first remove the symbols used to identify the two input
points and then show a 2D circle with the specified radius at the highest
point of the closed space curve. (The circle should be tangent to the
curve, i.e., intersecting the curve at only one point, but below the curve)
An arrow pointing from the center of the circle to the north pole of the
circle should also be shown with the circle. THE ARROW SHOULD BE PAINTED
IN A COLOR DIFFERENT FROM THAT OF THE CIRCLE. The radius of the circle
should be shown in Region B.
When the third small rectangular area is clicked by the user, the program
should ROLL the circle (and the ARROW) along the space curve in CLOCKWISE
DIRECTION. The speed of the circle should be increased GRADUALLY until it
reaches a local minimum and then decreased gradually until it reaches a
local maximum. When the circle returns to the start point, its speed should
be almost ZERO but not completely zero so it could start rolling again once
it passes the start point. The program should display proper information in
Region B when the ball reaches a local minimum or a local maximum. You need
to be able to differentiate between PLAYBACK RATE and SAMPLING RATE and
control them properly so the motion of the ball looks smooth.
***************************
Tip on Implementation
***************************
The following function is needed in the implementation of this work:
glutIdleFunc(idle)
This function registers a callback function 'idle' for timeouts and
when the program is "idling". The function 'idle' will be called
whenever there is nothing else to do (no other events are pending).
If each time 'idle' is called the program renders a new scene, the
window is continuously animated. Event processing happens between
calls to the function 'idle', so be careful not to spend too much
time in your idle function or you risk compromising your program's
interactivity. Only one idle function can be registered at a time.
If you call 'glutIdleFunc()' with a NULL, the idle function is
disabled. Idle callbacks are very much like X Toolkit work procedure.
Here is an example idle callback for animating a scene:
void idle( void ) {
advanceSceneStateOneFrame();
glutPostRedisplay();
}
Notice that the 'idle' routine does not actually render using OpenGL.
'idle' calls the 'advanceSceneStateOneFrame()' routine to update the
program's state variables determining how the scene should be rendered.
The 'glutPostRedisplay()' tells GLUT that the window's display callback
should be triggered; that is, a redisplay is necessary. This ensures
that the window is re-rendered. The display callback will redisplay the
scene based on the state variables updated by
'advanceSceneStateOneFrame()'.
A few sample programs showing you how to use these functions and
related stuff (such as putting labels in the menu buttons) are posted
on my webpage. (See the link above the first programming assignment.)
3. What to Turn In
Mail a modified copy of the program, a list of the changes that you made
(such as, how the Arc Length Table is redesigned and rebuilt, ...)
and a makefile to "cheng@cs.uky.edu" on or before the due date. If I can
not test run your program on my machine, then you need to come in to do
a demo on your own machine between 2/22/2008 and 2/29/2008.