CG Module-5
CG Module-5
CG Module-5
Interaction
5.1.1 INTERACTION
In the field of computer graphics, interaction refers to the manner in
which the application program communicates with input and output
devices of the system.
For e.g. Image varying in response to the input from the user.
OpenGL doesn‟t directly support interaction in order to maintain
portability. However, OpenGL provides the GLUT library. This library
supports interaction with the keyboard, mouse etc and hence enables
interaction. The GLUT library is compatible with many operating systems
such as X windows, Current Windows, Mac OS etc and hence indirectly
ensures the portability of OpenGL.
1
Module 5 Input and Interaction
keyboard etc. These are used to provide character input like letters,
numbers, symbols etc.
Pointing devices like mouse, track ball, light pen etc. These are used to
specify the position on the computer screen.
2
Module 5 Input and Interaction
The values passed by the pointing devices can be considered as positions and
converted to a 2-D location in either screen or world co-ordinates. Thus, as a
mouse moves across a surface, the integrals of the velocities yield x,y values
that can be converted to indicate the position for a cursor on the screen as
shown below:
These devices are relative positioning devices because changes in the position of
the ball yield a position in the user program.
3
Module 5 Input and Interaction
The major disadvantage is that it has the difficulty in obtaining a position that
corresponds to a dark area of the screen
4
Module 5 Input and Interaction
Stick doesn‟t move rather pressure sensors in the ball measure the forces applied by the
user. The space ball can measure not only three direct forces (up-down, front-back,
left-right) but also three independent twists. So totally device measures six
independent values and thus has six degree of freedom.
5
Module 5 Input and Interaction
These are logical functions that are defined by how they handle input oroutput
character strings from the perspective of C program.
From logical devices perspective inputs are from inside the application
program. The two major characteristics describe the logical behavior of input devices
are as follows:
The measurements that the device returns to the user program
The time when the device returns those measurements
API defines six classes of logical input devices which are given below:
✓ STRING: A string device is a logical device that provides the ASCII values
of input characters to the user program. This logical device is usually
implemented by means of physical keyboard.
✓ LOCATOR: A locator device provides a position in world coordinates to
the user program. It is usually implemented by means of pointing devices such
as mouse or track ball.
✓ PICK: A pick device returns the identifier of an object on the display to
the user program. It is usually implemented with the same physical device as
the locator but has a separate software interface to the user program. In
OpenGL, we can use a process of selection to accomplish picking.
✓ CHOICE: A choice device allows the user to select one of a discrete
number of options. In OpenGL, we can use various widgets provided by the
window system. A widget is a graphical interactive component provided by the
window system or a toolkit. The Widgets include menus, scrollbars and
6
Module 5 Input and Interaction
INPUT MODES
Input devices can provide input to an application program in terms of two
entities:
✓ Measure of a device is what the device returns to the application
program.
✓ Trigger of a device is a physical input on the device with which the user
can send signal to the computer
Example 1: The measure of a keyboard is a single character or array of
characters where as the trigger is the enter key.
Example 2: The measure of a mouse is the position of the cursor whereas the
trigger is when the mouse button is pressed.
The application program can obtain the measure and trigger in three distinct
modes:
✓ REQUEST MODE: In this mode, measure of the device is not returned to
the program until the device is triggered.
For example, consider a typical C program which reads a character input
using scanf(). When the program needs the input, it halts when it
encounters the scanf() statement and waits while user type characters at
the terminal. The data is placed in a keyboard buffer (measure) whose
contents are returned to the program only after enter key (trigger) is
pressed.
Another example, consider a logical device such as locator, we can move
out pointing device to the desired location and then trigger the device
with its button, the trigger will cause the location to be returned to the
application program.
7
Module 5 Input and Interaction
Both request and sample modes are useful for the situation if and only if there
is a single input device from which the input is to be taken. However, in case of
flight simulators or computer games variety of input devices are used and these
mode cannot be used. Thus, event mode is used.
❖ EVENT MODE: This mode can handle the multiple interactions. Suppose
that we are in an environment with multiple input devices, each with its
own trigger and each running a measure process.
event occurs. If there is an event in a queue, the program can look at the
first event type and then decide what to do.
8
Module 5 Input and Interaction
within a single system. Today most of the computing is done in the form
of distributed based and network based as shown below:
Most popular examples of servers are print servers – which allow using
high speed printer devices among multiple users. File servers – allow
users to share files and programs.
Users or clients will make use of these services with the help of user
programs or client programs. The OpenGL application programs are the client
programs that use the services provided by the graphics server.
Even if we have single user isolated system, the interaction would be
configured as client-server model.
9
Module 5 Input and Interaction
At that time, the disadvantage is that system was slow and expensive.
Therefore, a special purpose computer is build which is known as “display
processor”.
The user program is processed by the host computer which results a compiled
list of instruction that was then sent to the display processor, where the
instruction are stored in a display memory called as “display file” or “display list”.
Display processor executes its display list contents repeatedly at a sufficient high
rate to produce flicker-free image.
There are two modes in which objects can be drawn on the screen:
10
Module 5 Input and Interaction
✓ RETAINED MODE: This mode is offered by the display lists. The object is
defined once and its description is stored in a display list which is at the server
side and redisplay of the object can be done by a simple function call issued by
the client to the server.
NOTE: The main disadvantage of using display list is it requires memory at the
server architecture and server efficiency decreases if the data is changing
regularly.
11
Module 5 Input and Interaction
Each time if the client wishes to redraw the box on the
display, it need not resend the entire description. Rather, it can call the
following
function:
glCallList(Box)
glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix();
We can retrieve these values by popping them from the stack, usually the below
function calls are placed at the end of the display list,
glPopAttrib();
glPopMatrix();
We can create multiple lists with consecutive identifiers more easily
using:
glGenLists (number)
We can display multiple display lists by using single funciton
call: glCallLists()
12
Module 5 Input and Interaction
From the above figure we can observe to draw letter „I‟ is fairly simple,whereas
drawing „O‟ requires many line segments to get sufficiently smooth.
For the character „O‟ the code sequence is of the form as shown below:
13
Module 5 Input and Interaction
The glCallLists has three arguments: (1) indicates number of lists tobe
executed (2) indicates the type (3) is a pointer to an array of a type given
by second argument.
FONTS IN GLUT
GLUT provides raster and stroke fonts; they do not make use of display
lists.
14
Module 5 Input and Interaction
Each face has two identical eyes, two identical ears, one nose, one mouth
& an outline. We can specify these parts through display lists which is
given below:
15
Module 5 Input and Interaction
16
Module 5 Input and Interaction
The above code ensures whenever the left mouse button is pressed down,
execution of the program gets terminated.
Write an OpenGL program to display square when a left button is pressed and to
exit the program if right button is pressed.
#include<stdio.h>
#include<stdlib.h>
#include<GL/glut.h>
int wh=500, ww=500;
float siz=3;
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glViewPort(0,0,w,h)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,(GLdouble) ww, 0, (GLdouble) wh);
glMatrixMode(GL_MODELVIEW);
glColor3f(1,0,0);
}
17
Module 5 Input and Interaction
glVertex2f(x-siz, y+siz);
glVertex2f(x-siz, y-siz);
glVertex2f(x+siz, y-siz);
glEnd();
glFlush();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
}
18
Module 5 Input and Interaction
KEYBOARD EVENTS
Keyboard devices are input devices which return the ASCII value to
theuser program. Keyboard events are generated when the mouse is in the window and one
of the keys is pressed or released.
GLUT supports following two functions:
glutKeyboardFunc() is the callback for events generated by pressing a key
glutKeyboardUpFunc() is the callback for events generated by releasing a
key.
The information returned to the program includes ASCII value of the key
pressed and the position (x,y) of the cursor when the key was pressed.
Programming keyboard event involves two steps:
The above code ensures when „Q‟ or „q‟ key is pressed, the execution of
the program gets terminated.
19
Module 5 Input and Interaction
WINDOW EVENTS
A window event is occurred when the corner of the window is dragged to new position or
size of window is minimized or maximized by using mouse.
The information returned to the program includes the height and width
of newly resized window. Programming the window event involves two
steps:
20
Module 5 Input and Interaction
WINDOW MANAGEMENT
GLUT also supports multiple windows of a given window. We can create a
second top-level window as follows:
id = glutCreateWindow(“second window”);
The returned integer value allows us to select this window as the current
window.
i.e., glutSetWindow(id);
NOTE: The second window can have different properties from other window by
invoking the glutInitDisplayMode before glutCreateWindow.
5.1.7 MENUS
Menus are an important feature of any application program. OpenGL
provides a feature called “Pop-up-menus” using which sophisticated
interactive applications can be created.
Menu creation involves the following steps:
h) Define the actions corresponding to each entry in the menu.
i) Link the menu to a corresponding mouse button.
j) Register a callback function for each entry in the menu.
21
Module 5 Input and Interaction
5.1.8 PICKING
Picking is the logical input operation that allows the user to identify an object on the
display.
The action of picking uses pointing device but the information returned
to the application program is the identifier of an object not a position.
22
Module 5 Input and Interaction
Picking can be performed in four steps that are initiated by user defined
pick function in the application:
23
Module 5 Input and Interaction
➔ We draw the objects into back buffer with the pick colors.
➔ We get the position of the mouse using the mouse callback.
24
Module 5 Input and Interaction
❖ There is a normal window and image on the display. We also see the
cursor with small box around it indicating the area in which primitive is
rendered.
❖ It shows window and display after the window has been changed by
gluPickMatrix.
#include<glut.h>
25
Module 5 Input and Interaction
26
Module 5 Input and Interaction
void myReshape()
{
glViewPort(0,0,w,h)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,(GLdouble) w, 0, (GLdouble) h);
glMatrixMode(GL_MODELVIEW);
}
27
Module 5 Input and Interaction
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(“picking”);
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMouseFunc(Mouse);
glClearColor(0.0,0.0,0.0,0.0);
glutMainLoop();
}
28
Module 5 Input and Interaction
Now suppose that the user has indicated through a menu that he wishes to eliminate an
object and use the mouse to locate the object.
O The program can now search the instance table till it finds the
object as specified in the bounding box and then set its type to 0.
O Hence, next time when the display process goes through the
instance table, the object would not be displayed and thereby it
appears that object has been deleted.
Although the above strategy works fine, a better data structure to
implement the instance table is using linked lists instead of arrays.
Programs in which objects are not static rather they appear to be moving
or changing is considered as “Interactive programs”.
Consider the following diagram:
29
Module 5 Input and Interaction
Consider a 2D point p(x,y) such that x = cos , y= sin . This point would lie
on a unit circle regardless of the value of . Thus, if we connect the above
given four points we get a square which has its center as the
origin. The above square can be displayed as shown below:
30
Module 5 Input and Interaction
The above mouse callback function starts the rotation of the cube when
the left mouse button and when the middle button is pressed it will halt
the rotation.
The above mouse callback function must be registered in the main
function as follow:
glutMouseFunc(mouse);
DOUBLE BUFFERING:
Double buffering is a must in such animations where the primitives,
attributes and viewing conditions are changing continuously.
Double buffer consists of two buffers: front buffers and back buffers.
31
Module 5 Input and Interaction
USING TIMER:
To understand the usage of timer, consider cube rotation program and
its execution is done by using fast GPU (modern GPUs can render tens of
millions of primitives per second) then cube will be rendered thousands
of time per second and we will see the blur on the display.
Therefore, GLUT provides the following timer function:
Execution of this function starts timer in the event loop that delays for
delay milliseconds. When timer has counted down, timer_func is executed the
value parameter allow user to pass variable into the timer call back.
A smooth display, showing neither flicker nor any artifacts of the refresh
process.
A variety of interactive devices on the display
A variety of methods for entering and displaying information
An easy to use interface that does not require substantial effort to learn
Feedback to the user
Tolerance for user errors
32
Module 5 Input and Interaction
x10 pixels then 100 blue pixels are copied into the color buffer, replacing
100 black pixels. Therefore, this mode is called as “copy or replacement
mode”.
Consider the below model, where we are writing single pixel into color
buffer.
33
Module 5 Input and Interaction
Again mouse is used to get second point and draw a line segment in XOR
mode.
34
Module 5 Input and Interaction
Here in the above code, copy mode is used to switch back in order to
draw other objects in normal mode.
If we enter another point with mouse, we first draw line in XOR mode
from 1st point to 2nd point and draw second line using 1st point to
current point is as follows:
In this example, we draw rectangle using same concept and the code for
callback function are given below:
35
Module 5 Input and Interaction
36
Module 5 Input and Interaction
After that each time that we get vertex, we first erase the existing
rectangle by redrawing new rectangle using new vertex.
Although XOR mode simplifies the process, it requires the system to read
present destination pixels before computing new destination pixels.
37
Module 5 Input and Interaction
Therefore, typical color buffer may have 8 bits for each Red, green and blue and
one red, one green and one blue overlay plane. i.e., each color will be having its
own overlay plane then those values will be updated to color buffer.
38
Module 5 Input and Interaction
39
Module 5 Curves
5.2 Curves:
5.2.1 Curved surfaces
5.2.2 Quadric surfaces
5.2.3 OpenGL quadric surfaces and cubic surface functions
5.2.4 Bezier spline curves
5.2.5 Bezier surfaces
5.2.6 Opengl curve functions
5.2.7 Corresponding opengl functions
1
Module 5 Curves
9) Sphere
A spherical surface with radius r centered on the coordinate origin
is defined as the set of points (x, y, z) that satisfy the equation
2 2 2 2
x +y +z =r
We can also describe the spherical surface in parametric form, using latitude and
longitude angles as shown in figure
= r cos φ cos θ, − π/2 ≤ φ ≤ π/2
= r cos φ sin θ, − π ≤ θ ≤ π
= r sin φ
2. Ellipsoid
An ellipsoidal surface can be described as an extension of a spherical surface where the
radii in three mutually perpendicular directions can have different values
2
Module 5 Curves
The Cartesian representation for points over the surface of an ellipsoid centered on the
origin is
And a parametric representation for the ellipsoid in terms of the latitude angle φ and the
longitude angle θ
x = rx cos φ cos θ, − π/2 ≤ φ ≤ π/2
y = ry cos φ sin θ, − π ≤ θ ≤ π
z = rz sin φ
Torus
A torus is a doughnut-shaped object, as shown in fig. below.
3
Module 5 Curves
Rotating this circle about the z axis produces the torus whose surface
positions are described with the Cartesian equation
The corresponding parametric equations for the torus with a circular cross-section are
= (raxial + r cos φ) cos θ, − π ≤ φ ≤ π
= (raxial + r cos φ) sin θ, − π ≤ θ ≤ π
= r sin φ
We could also generate a torus by rotating an ellipse, instead of a circle, about the z
axsi.we can write the ellipse equation as
where raxial is the distance along the y axis from the rotation z axis to the ellipse
center. This generates a torus that can be described with the Cartesian equation
4
Module 5 Curves
Sphere
Function:
glutWireSphere (r, nLongitudes, nLatitudes);
or
glutSolidSphere (r, nLongitudes, nLatitudes);
where,
r is sphere radius which is double precision point.
nLongitudes and nLatitudes is number of longitude and latitude lines used to
approximatethe sphere.
Cone
Function:
glutWireCone (rBase, height, nLongitudes, nLatitudes);
or
glutSolidCone (rBase, height, nLongitudes, nLatitudes);
where,
rBase is the radius of cone base which is double precision point.
height is the height of cone which is double precision point.
nLongitudes and nLatitudes are assigned integer values that specify the
number oforthogonal surface lines for the quadrilateral mesh approximation.
Torus
Function:
glutWireTorus (rCrossSection, rAxial, nConcentrics, nRadialSlices);
or
glutSolidTorus (rCrossSection, rAxial, nConcentrics, nRadialSlices);
where,
rCrossSection radius about the coplanar z axis
5
Module 5 Curves
where,
sphere1 is the name of the object
6
Module 5 Curves
the quadric renderer is activated with the gluNewQuadric function, and then the
displaymode GLU_LINE is selected for sphere1 with the gluQuadricDrawStyle
command
Parameter r is assigned a double-precision value for the sphere radius
nLongitudes and nLatitudes. number of longitude lines and latitude lines
A flat, circular ring or solid disk is displayed in the xy plane (z=0) and centered on
h
teworld-coordinate origin with
gluDisk (ringName, rInner, rOuter, nRadii, nRings);
We set double-precision values for an inner radius and an outer radius with
parameters rInner and rOuter. If rInner = 0, the disk is solid.
Otherwise, it is displayed with a concentric hole in the center of the disk.
The disk surface is divided into a set of facets with integer parameters nRadii and
nRings
7
Module 5 Curves
Allocated memory for any GLU quadric surface can be reclaimed and the surface
eliminated with
gluDeleteQuadric (quadricName);
Also, we can define the front and back directions for any quadric surface with the
following orientation function:
gluQuadricOrientation (quadricName, normalVectorDirection);
Where,
Parameter normalVectorDirection is assigned either GLU_OUTSIDE or
GLU_ INSIDE
8
Module 5 Curves
When other lighting and shading conditions are to be applied, we use the constant
GLU_SMOOTH, which generates a normal vector for each surface vertex
position.
We can designate a function that is to be invoked if an error occurs during the generation
of a quadric surface:
gluQuadricCallback (quadricName, GLU_ERROR, function);
9
Module 5 Curves
10
Module 5 Curves
A set of three parametric equations for the individual curve coordinates can be
represented as
11
Module 5 Curves
Below Figure demonstrates the appearance of some Bézier curves for various selections
of control points in the xy plane (z = 0).
for n ≥ k. Also, the Bézier blending functions satisfy the recursive relationship
BEZk,n(u) = (1 − u)BEZk,n−1(u) + u BEZk−1,n−1(u), n > k ≥ 1 (27)
with BEZk,k = uk and BEZ0,k = (1 − u)k .
Program
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
/* Set initial size of the display window. */
GLsizei winWidth = 600, winHeight = 600;
12
Module 5 Curves
GLint k, j;
for (k = 0; k <= n; k++) {
/* Compute n!/(k!(n - k)!). */
C [k] = 1;
for (j = n; j >= k + 1; j--)
C [k] *= j;
for (j = n - k; j >= 2; j--)
C [k] /= j;
}
}
13
Module 5 Curves
void computeBezPt (GLfloat u, wcPt3D * bezPt, GLint nCtrlPts, wcPt3D * ctrlPts, GLint * C)
{
GLint k, n = nCtrlPts - 1;
GLfloat bezBlendFcn;
bezPt->x = bezPt->y = bezPt->z = 0.0;
/* Compute blending functions and blend control points. */
for (k = 0; k < nCtrlPts; k++) {
bezBlendFcn = C [k] * pow (u, k) * pow (1 - u, n - k);
bezPt->x += ctrlPts [k].x * bezBlendFcn; bezPt->y
+= ctrlPts [k].y * bezBlendFcn;
bezPt->z += ctrlPts [k].z * bezBlendFcn;
}
}
void bezier (wcPt3D * ctrlPts, GLint nCtrlPts, GLint nBezCurvePts)
{
wcPt3D bezCurvePt;
GLfloat u;
GLint *C, k;
/* Allocate space for binomial coefficients */
C = new GLint [nCtrlPts];
binomialCoeffs (nCtrlPts - 1, C);
for (k = 0; k <= nBezCurvePts; k++) {
u = GLfloat (k) / GLfloat (nBezCurvePts);
computeBezPt (u, &bezCurvePt, nCtrlPts, ctrlPts,
C); plotPoint (bezCurvePt);
}
delete [ ] C;
}
void displayFcn (void)
{
/* Set example number of control points and number of
14
Module 5 Curves
glutDisplayFunc (displayFcn);
glutReshapeFunc (winReshapeFcn);
glutMainLoop ( );
}
15
Module 5 Curves
Property1:
A very useful property of a Bézier curve is that the curve connects the first and last
control points.
Thus, a basic characteristic of any Bézier curve is that
P(0) = p0
P(1) = pn
Values for the parametric first derivatives of a Bézier curve at the endpoints can be
calculated from control-point coordinates as
The parametric second derivatives of a Bézier curve at the endpoints are calculated as
Property 2:
Another important property of any Bézier curve is that it lies within the convex hull
(convex polygon boundary) of the control points.
This follows from the fact that the Bézier blending functions are all positive and their
sum is always 1:
Other Properties:
The basic functions are real.
The degree of the polynomial defining the curve segment is one less than the number of
defining points.
The curve generally follows the shape of the defining polygon,
The tangent vectors at the ends of the curve have the same direction as the first and last
polygon spans respectively.
16
Module 5 Curves
If the first curve section has n control points and the next curve section has n’
controlpoints, then we match curve tangents by placing control point p1’ at the position
17
Module 5 Curves
Plots of the four cubic Bézier blending functions are given in Figure
At the end positions of the cubic Bézier curve, the parametric first derivatives (slopes) are
Bézier surfaces have the same properties as Bézier curves, and they provide a
convenientmethod for interactive design applications.
To specify the threedimensional coordinate positions for the control points, we
could firstconstruct a rectangular grid in the xy “ground” plane.
19
Module 5 Curves
We then choose elevations above the ground plane at the grid intersections as thez-
coordinate values for the control points.
Figure above illustrates various polyline displays that could be used for a circle segment.
A third alternative is to write our own curve-generation functions based on the
algorithmswith respect to line drawing and circle drawing.
20
Module 5 Curves
21
Module 5 Curves
A spline curve is generated with evenly spaced parameter values, and OpenGL provides
the following functions, which we can use to produce a set of uniformly spaced parameter
values:
glMapGrid1* (n, u1, u2);
glEvalMesh1 (mode, n1, n2);
Where,
The suffix code for glMapGrid1 can be either f or d.
Parameter n specifies the integer number of equal subdivisions over the range from u1 to
u2.
Parameters n1 and n2 specify an integer range corresponding to u1 and u2.
Parameter mode is assigned either GL POINT or GL LINE, depending on whether we
want to display the curve using discrete points (a dotted curve) or using straight-line
segments
In other words, with mode = GL LINE, the preceding OpenGL commands are
equivalent to
glBegin (GL_LINE_STRIP);
for (k = n1; k <= n2; k++)
glEvalCoord1f (u1 + k * (u2 - u1) / n);
glEnd ( );
22
Module 5 Curves
which maps each of uValue and vValue to the interval from 0 to 1.0
degParam,
GL_MAP1_VERTEX_3); gluEndCurve (curveName);
We eliminate a defined B-spline with
gluDeleteNurbsRenderer (curveName);
23
Module 5 Curves
However, a variety of B-spline rendering options can also be selected with repeated cals
to the following GLU function:
gluNurbsProperty (splineName, property, value);
24
Module 5 Curves
25
Module 5 Curves
26
Module 5 Curves
27
Module 5 Computer Animation
5.3 Animation
5.3.1 Raster methods of computer animation
5.3.2 Design of animation sequences
5.3.3 Traditional animation techniques
5.3.4 General computer animation function
5.3.5 OpenGL animation procedures
5.3.6 Questions
Introduction:
To 'animate' is literally 'to give life to'.
'Animating' is moving something which can't move itself.
Animation adds to graphics the dimension of time which vastly increases the amount of
information which can be transmitted.
1
Module 5 Computer Animation
Double Buffering
One method for producing a real-time animation with a raster system is to
employtwo refresh buffers.
We create a frame for the animation in one of the buffers.
Then, while the screen is being refreshed from that buffer, we
construct thenext frame in the other buffer.
When that frame is complete, we switch the roles of the two
buffers sothatthe refresh routines use the second buffer during the process of creating the
next frame in the first buffer.
When a call is made to switch two refresh buffers, the
interchange could be performed at various times.
The most straight forward implementation is to switch
the two bufersat the end of the current refresh cycle, during the vertical retrace of the
electron beam.
If a program can complete the construction of a frame
within the time of a refresh cycle, say 1/60 of a second, each motion sequence is
displayed in synchronization with the screen refresh rate.
If the time to construct a frame is longer than the refresh time,
the curentframe is displayed for two or more refresh cycles while the next animation
frame is being generated.
2
Module 5 Computer Animation
Storyboard layout
Object definitions.
Key-frame specifications
Generation of in-between frames.
This approach of carrying out animations is applied to any other applications as
wel,although some applications are exceptional cases and do not follow this sequence.
For frame-by-frame animation, every frame of the display or scene is generated
separately and stored. Later, the frame recording can be done and they might be displayed
consecutively in terms of movie.
The outline of the action is storyboard. This explains the motion sequence. The
storyboard consists of a set of rough structures or it could be a list of the basic ideas for
the motion.
For each participant in the action, an object definition is given. Objects are described ni
terms of basic shapes the examples of which are splines or polygons. The related
movement associated with the objects are specified along with the shapes.
A key frame in animation can be defined as a detailed drawing of the scene at a certain
time in the animation sequence. Each object is positioned according to the time for that
frame, within each key frame.
Some key frames are selected at extreme positions and the others are placed so that
thetime interval between two consecutive key frames is not large. Greater number of key
frames are specified for smooth motions than for slow and varying motion.
And the intermediate frames between the key frames are In-betweens. And the
Media thatwe use determines the number of In-betweens which are required to display
the animation. A Film needs 24 frames per second, and graphics terminals are refreshed at
the rate of 30 to 60 frames per second.
Depending on the speed specified for the motion, some key frames are duplicated. Fora
one minutes film sequence with no duplication, we would require 288 key frames. We
place the key frames a bit distant if the motion is not too complicated.
A number of other tasks may be carried out depending upon the application
requirementfor example synchronization of a sound track.
4
Module 5 Computer Animation
5
Module 5 Computer Animation
6
Module 5 Computer Animation
Example Program
#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>
class scrPt {
public:
GLint x, y;
};
static void init (void)
{
scrPt hexVertex;
GLdouble hexTheta;
GLint k;
glClearColor (1.0, 1.0, 1.0, 0.0);
/* Set up a display list for a red regular hexagon.
9. Vertices for the hexagon are six equally spaced
10. points around the circumference of a circle.
*/
regHex = glGenLists (1);
glNewList (regHex, GL_COMPILE);
glColor3f (1.0, 0.0, 0.0);
glBegin (GL_POLYGON);
for (k = 0; k < 6; k++) {
hexTheta = TWO_PI * k / 6;
7
Module 5 Computer Animation
8
Module 5 Computer Animation
glLoadIdentity ( );
glClear (GL_COLOR_BUFFER_BIT);
}
void mouseFcn (GLint button, GLint action, GLint x, GLint y)
{
switch (button) {
case GLUT_MIDDLE_BUTTON: // Start the rotation.
if (action == GLUT_DOWN)
glutIdleFunc (rotateHex);
break;
case GLUT_RIGHT_BUTTON: // Stop the rotation.
if (action == GLUT_DOWN)
glutIdleFunc (NULL);
break;
default:
break;
}
}
void main(int argc, char ** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE |
GLUT_RGB); glutInitWindowPosition (150, 150);
glutInitWindowSize (winWidth, winHeight);
glutCreateWindow ("Animation Example"); init ( );
glutDisplayFunc (displayHex);
glutReshapeFunc (winReshapeFcn);
glutMouseFunc (mouseFcn);
glutMainLoop ( );
}
9
5.3.6 QUESTIONS