0% found this document useful (0 votes)
72 views

Computer Graphics: Lecture 10 - Computer Animation and Viewing Transformation

Computer animation involves generating a sequence of images to display motion. It can depict changes in position, color, size, transparency or texture over time. There are two main methods: real-time animation renders each frame as it is created, while frame-by-frame pre-renders each frame and stores it. Animation design involves storyboarding, defining objects, keyframes that mark state changes, and generating in-between frames. Viewing transformations in 3D graphics include modeling transforms that position objects, viewing transforms that position the camera, projection transforms that adjust perspective, and viewport transforms that scale the final image.

Uploaded by

Marium Fayyaz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Computer Graphics: Lecture 10 - Computer Animation and Viewing Transformation

Computer animation involves generating a sequence of images to display motion. It can depict changes in position, color, size, transparency or texture over time. There are two main methods: real-time animation renders each frame as it is created, while frame-by-frame pre-renders each frame and stores it. Animation design involves storyboarding, defining objects, keyframes that mark state changes, and generating in-between frames. Viewing transformations in 3D graphics include modeling transforms that position objects, viewing transforms that position the camera, projection transforms that adjust perspective, and viewport transforms that scale the final image.

Uploaded by

Marium Fayyaz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

COMPUTER

GRAPHICS
LECTURE 10_ COMPUTER ANIMATION AND VIEWING TRANSFORMATION
COMPUTER ANIMATION

• Any time sequence of visual changes in an image is referred to as


computer animation
• In addition to changing objects position using translation, rotations
computer animation could display time variations in objects color, size,
transparency or surface texture.
• Two basic methods for constructing a motion sequence are
• Real time animation – Each state of the sequence is viewed as it is created,
thus the generation rate needs to comply with the refresh rate of display
device
• Frame by frame animation – Each frame of the motion is separately
generated and stored.
DESIGN OF
ANIMATION Storyboard Layout
SEQUENCES
Object Definition
Designing animation
sequences consists of the
following development
stages: Key-Frame
Specifications

Generation of In-
Between Frames
STORYBOARD LAYOUT

• Storyboard is an outline of
actions. It defines the motion
sequence as a set of basic
events that are to take place.
• Storyboard could consist of
rough sketches along with
descriptions of the motions
OBJECT DEFINITION

• For each participant in the


action an object definition is
given. Objects are defined in
terms of the basic shapes, such
as polygons or spline surfaces.
• Description is often given for
the movements that are to be
performed by the character or
object in the story
KEY FRAME

• A detailed drawing of the scene at a certain time in the sequence of


animation sequence. Within each keyframe, each object is positioned
according to the time for that frame.
• More keyframes are often specified for intricate motions than for
simple, slowly variating motions.
IN-BETWEENS

• Intermediate frames between the key frames


• Keyframes + In-betweens are determined by the display media that is
to be used.
• Films require 24 frames per second, and graphics terminals are refreshed at
the rate of 60 or more frames per second.

One frame extracted from movies. These films are


designed using key-frame animation system and
cartoon animation techniques
Keyframes are used to
indicate the change in
certain parameter of video
for example when audio
either fades down or up to
a level.

In hand-drawn animation,
a keyframe is a specific
frame within the animated
movement that the
animator uses as a guide
to building the rest of his
work around.
Computer Graphics by Hearn & Baker
TRADITIONAL Squash and Stretch
ANIMATION
TECHNIQUES Timing

Anticipation

Follow- through actions

Staging
ANIMATION SYSTEMS

Key Frame systems

Parameterized systems

Scripting systems
KEY FRAME SYSTEMS

• Originally designed as a set of animation routines to create the in-


betweens from the user specified key frames
• Now they are a component of a more general animation package
• Idea:
• Each object is defined as a set of rigid bodies connected at the joints and
with a limited number of degrees of freedom. Example of a single robot
arm

• Motion paths can be given with a kinematic description as a set of


spline curves or the motions can be physically based by specifying the
forces acting on objects to be animated.
KEY FRAME SYSTEMS

• Morphing is often done within keyframes; which includes modifying the


shape of object from one keyframe to the next
• Simulating Accelerations allows to specify animation paths between
keyframes.
PARAMETERIZED SYSTEMS

• These allow object motion characteristics to be specified as part of the


object definition.
• The adjustable parameters control such object characteristics as
degrees of freedom, motion limitations and allowable shape changes.
SCRIPTING SYSTEMS

• These allow object specifications and animation sequences to be


defined with a user-input script. From the script a library of various
objects and motions can be constructed
MOTION SPECIFICATION

• Direct Motion Specification


• Define geometric transformation parameters; explicitly set the values of rotation angles and
translation vectors

• Goal Oriented Systems


• Specify motions in general terms that abstractly define the actions in terms of final results.

• Kinematics and Dynamics


• Kinematics; We specify the animation by giving motion parameters (position, velocity and
acceleration) without reference to the causes or goals of the motion.
• Dynamics; We specify the forces that produce the velocities and accelerations. These forces
affecting motion include electromagnetic, gravitational, frictional, and other mechanical forces.
COMPUTER
Viewing Transformations
GRAPHICS
TRANSFORMATIONS AND CAMERA ANALOGY

Viewing transformation

• Positioning and aiming camera in the world.

Modeling transformation

• Positioning and moving the model.

Projection transformation

• Adjusting the lens of the camera.

Viewport transformation

• Enlarging or reducing the physical photograph.


Projection Transformations
Projections Transformations are the transformations
done in order to change the lense of the camera.

There are two types of Projection transformations


1)Orthographic
2)Perspective
PROJECTION IN OPENGL

1)Orthographic Projection(glOrtho)
Functions
glOrtho2D(left,right,bottom,top)
gluOrtho(left,right,bottom,top,near,far)

2)Perspective Projection
Functions
glFrustum(left,right,bottom,top,near,far)
gluPerspective(fovy,aspect,near,far)
Orthographic projection

• glOrtho( left, right, bottom, top, zNear, zFar )


y

top

z left
right
Bottom

Near-plane: zNear Far-plane: zFar


x
• gluOrtho2D( left, right, bottom, top ) Viewing volume

It is the same as the glOrtho(), except zNear = -1.0, and zFar = 1.0
Perspective projection
1)glFrustum( left, right, bottom, top, zNear, zFar )
Creates a matrix for a perspective viewing frustum
and multiplies the current matrix by it.

top left

right
bottom

Near-plane: zNear
Specify the points on the near clipping
plane that are mapped to the lower left Viewing volume
and upper right corners of the window,
respectively, assuming that the eye is
located at (0, 0, 0).
GLUPERSPECTIVE( FOVY, ASPECT, ZNEAR, ZFAR)

y
aspect ratio = w /h

w h
z

fovy
x N ear-plane: zN ear Far-plane: zN ear

V iew ing volum e

The fovy parameter stands for the “field of view y-axis” and is the
vertical angle of the camera’s lens. Common values for fovy range
from 30 to 60 degrees. The aspect ratio parameter is the width
divided by the height of the canvas window.
DEMO TO
UNDERSTAND THE
PERSPECTIVE
PROJECTION
PARAMETERS

HTTP://LEARNWEBGL.BRO
WN37.NET/08_PROJECTION
S/CREATE_PERSPECTIVE/C
REATE_PERSPECTIVE.HTML
3D GRAPHICS PIPELINE REVIEW
WORLD SCENE/OBJECT
Modelling coordinates:
- world coordinate system, MODELLING
- object coordinate system
VIEWING

CLIPPING

Camera coordinates
PROJECTION

Screen coordinates
RASTERIZATION

Device coordinates
PIXEL DISPLAY
3D VIEWING
• Inherently more complex than 2D process
• Part of the difficulty lies in trying to display three dimensional
objects on a 2D display
• Different views on the same object eventually lead to different 2D
representations at the projection stage
• the projected 2D image of a 3D object is viewer dependent
DIFFERENT VIEWS
Viewing a 3D world

Model View direction

View position (eyepoint)


CAMERA ANALOGY

View is described in terms of:


 camera location: position in world co-ordinate system
 direction in which we are aiming the camera: viewing direction
 orientation of the camera: usually defined by the up vector

Camera
Camera Model
Orientation
Up Vector Camera
Direction
Camera
Position
CAMERA VIEWING

Scene 1 Consider the scene to the left. We


usually assume the viewer positioned
at the origin looking down the
negative z axis

In terms of the final image this


would be equivalent to the scene
on the right… which is a lot easier
to work with
Scene 2
If we use OpenGL
Look-At Function

gluLookAt (eyex, eyey, eyez, atx, aty, atz, upx, upy, upz )

gluLookAt creates a viewing matrix derived from an eye point, a reference point indicating the center
of the scene, and an UP vector.
Where I am and Looking at

View-up vector
Loot at y
(upx, upy, upz)
y
(atx, aty, atz)

x x
Model
z z
Eyepoint
(eyex, eyey, eyez)
SETTING THE OPENGL CAMERA

void gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ,
 GLdouble centerX, GLdouble centerY, GLdouble centerZ,
 GLdouble upX, GLdouble upY, GLdouble upZ);

eyeX, eyeY, eyeZ (Position of the camera)


centerX, centerY, centerZ(Line of sight, point we’re looking at )
upX, upY, upZ (up vector or indicates the how the camera is placed)
Object position
(0,0,0)

Camera position
(0,0,2)

gluLookAt(0,0,2, 0,0,0, 0,1,0)

Position Direction Up Vector


CAMERA FUNCTION EXAMPLES

gluLookAt(x, y, z, x,y,z, 0,1,0);

Camera Camera Up Vector


Position Direction Orientation

• gluLookAt(x, y, z, x,y,z, 1,0,0);(leaning toward +x only)


• gluLookAt(x, y, z, x,y,z, 1,1,0);(leaning towards +x and +y)
• gluLookAt(x, y, z, x,y,z, 0,1,0);(leaning towards +y only)
UP VECTOR VALUES(UPX, UPY, UPZ )

Default values (0,1,0) (x, y, z)=(-1,0,0)

(x, y, z)=(0,-1,0)

(x, y, z)= (-1,1,0)


Camera Movement in X-Z Direction

-z

-x +x

+z
If you want to move in upward
and downward direction then y
axis is included
CAMERA MOVEMENT IN X-Z DIRECTION

gluLookAt( x, 1.0f, z, x+lx,1.0f, z+lz, 0.0f, 1.0f, 0.0f);

Position Direction Up Vector


float x=0.0f,z=5.0f, lx=0.0f,lz=-1.0f;
Direction
Look At Point = Line Of Sight + Camera Position
Look At Point X = lx+x
Look At Point z = lz+z
FUNCTIONS TO COMPUTE POSITION AND DIRECTION

void computePos(float deltaMove) //compute camera position


{
  position=(current angle*old direction)+(oldposition)
x += deltaMove * lx * 0.1f;
z += deltaMove * lz * 0.1f;
}
 
void computeDir(float deltaAngle)//compute camera direction
{
 
angle += deltaAngle;
lx = sin(angle);
lz = -cos(angle);
}
KEYBOARD FUNCTIONS USED TO MOVE CAMERA

void pressKey(int key, int xx, int yy) {


  deltaAngle=Angle used
switch (key) {
case GLUT_KEY_LEFT : deltaAngle = -0.01f; break;
to compute new camera
case GLUT_KEY_RIGHT : deltaAngle = 0.01f; break; direction
case GLUT_KEY_UP : deltaMove = 0.5f; break;
case GLUT_KEY_DOWN : deltaMove = -0.5f; break;
}
}
deltaMove=Angle used
void releaseKey(int key, int x, int y) { to compute the camera
switch (key) {
case GLUT_KEY_LEFT :
position
case GLUT_KEY_RIGHT : deltaAngle = 0.0f;break;
case GLUT_KEY_UP :
case GLUT_KEY_DOWN : deltaMove = 0;break;
}
}
void display(void) {
 
if (deltaMove)//if position has changed
computePos(deltaMove);//to compute current camera position
if (deltaAngle)//if direction has changed
computeDir(deltaAngle);//compute currrent camera direction
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// Set the camera
gluLookAt(x, 1.0f, z, x+lx , 1.0f, z+lz,0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 0.9f, 0.0f);
glBegin(GL_QUADS);//green grass
glVertex3f(-100.0f, 0.0f, -100.0f);
glVertex3f(-100.0f, 0.0f, 100.0f);
glVertex3f( 100.0f, 0.0f, 100.0f);
glVertex3f( 100.0f, 0.0f, -100.0f);
glEnd(); 
for(int i = -3; i < 3; i++)
for(int j=-3; j < 3; j++) //Drawing multiple Snowman at different points
{
glPushMatrix();
glTranslatef(i*10.0,0,j * 10.0);//translated at minus z axis
drawSnowMan();
glPopMatrix();

glutSwapBuffers();
}
THANKS
!

You might also like