UNIT I
2D PRIMITIVES
Line and Curve Drawing
Algorithms
Line Drawing
y = m . x + b
m = (y
end
– y
0
) / (x
end
– x
0
)
b = y
0
– m . x
0
x
0
y
0
x
end
y
end
DDA Algorithm
if m<1
x
k+1
= x
k
+ 1
y
k+1
= y
k
+ m
if m>1
y
k+1
= y
k
+ 1
x
k+1
= x
k
+ 1/m
x
0
y
0
x
end
y
end
x
0
y
0
x
end
y
end
DDA Algorithm
#include <stdlib.h>
#include <math.h>
inline int round (const float a) { return int (a + 0.5); }
void lineDDA (int x0, int y0, int xEnd, int yEnd)
{
int dx = xEnd  x0, dy = yEnd  y0, steps, k;
float xIncrement, yIncrement, x = x0, y = y0;
if (fabs (dx) > fabs (dy))
steps = fabs (dx); /* m<1 */
else
steps = fabs (dy); /* m>=1 */
xIncrement = float (dx) / float (steps);
yIncrement = float (dy) / float (steps);
setPixel (round (x), round (y));
for (k = 0; k < steps; k++) {
x += xIncrement;
y += yIncrement;
setPixel (round (x), round (y));
}
}
Bresenham’s Line Algorithm
x
k
y
k
x
k+1
y
k+1
y
d
u
d
l
x
k
x
k+1
y
k
y
k+1
Bresenham’s Line Algorithm
#include <stdlib.h>
#include <math.h>
/* Bresenham linedrawing procedure for m<1.0 */
void lineBres (int x0, int y0, int xEnd, int yEnd)
{
int dx = fabs(xEnd  x0),
dy = fabs(yEnd  y0);
int p = 2 * dy  dx;
int twoDy = 2 * dy,
twoDyMinusDx = 2 * (dy  dx);
int x, y;
/* Determine which endpoint to use as start
position. */
if (x0 > xEnd) {
x = xEnd;
y = yEnd;
xEnd = x0;
}
else {
x = x0;
y = y0;
}
setPixel (x, y);
while (x < xEnd) {
x++;
if (p < 0)
p += twoDy;
else {
y++;
p += twoDyMinusDx;
}
setPixel (x, y);
}
}
Circle Drawing
Pythagorean Theorem:
x
2
+ y
2
= r
2
(xx
c
)
2
+ (yy
c
)
2
= r
2
(x
c
r) ≤ x ≤ (x
c
+r)
y = y
c
± √r
2
 (xx
c
)
2
x
c
y
c
r
(x, y)
Circle Drawing
change x
change y
Circle Drawing
using polar coordinates
x = x
c
+ r . cos θ
y = y
c
+ r . sin θ
change θ with step
size 1/r
r
(x, y)
(x
c
, y
c
)
θ
Circle Drawing
using polar coordinates
x = x
c
+ r . cos θ
y = y
c
+ r . sin θ
change θ with step
size 1/r
use symmetry if θ>45
0
r
(x, y)
(x
c
, y
c
)
θ
(x, y)
(x
c
, y
c
)
45
0
(y, x) (y, x)
(x, y)
Midpoint Circle Algorithm
f(x,y) = x
2
+ y
2
 r
2
<0 if (x,y) is inside circle
f(x,y) =0 if (x,y) is on the circle
<0 if (x,y) is outside circle
use symmetry if x>y
x
k
x
k+1
y
k
1
y
k
y
k
1/2
Midpoint Circle Algorithm
#include <GL/glut.h>
class scrPt {
public:
GLint x, y;
};
void setPixel (GLint x, GLint y)
{
glBegin (GL_POINTS);
glVertex2i (x, y);
glEnd ( );
}
void circleMidpoint (scrPt circCtr, GLint radius)
{
scrPt circPt;
GLint p = 1  radius;
circPt.x = 0;
circPt.y = radius;
void circlePlotPoints (scrPt, scrPt);
/* Plot the initial point in each circle quadrant. */
circlePlotPoints (circCtr, circPt);
/* Calculate next points and plot in each octant. */
while (circPt.x < circPt.y) {
circPt.x++;
if (p < 0)
p += 2 * circPt.x + 1;
else {
circPt.y;
p += 2 * (circPt.x  circPt.y) + 1;
}
circlePlotPoints (circCtr, circPt);
}
}
void circlePlotPoints (scrPt circCtr, scrPt circPt);
{
setPixel (circCtr.x + circPt.x, circCtr.y + circPt.y);
setPixel (circCtr.x  circPt.x, circCtr.y + circPt.y);
setPixel (circCtr.x + circPt.x, circCtr.y  circPt.y);
setPixel (circCtr.x  circPt.x, circCtr.y  circPt.y);
setPixel (circCtr.x + circPt.y, circCtr.y + circPt.x);
setPixel (circCtr.x  circPt.y, circCtr.y + circPt.x);
setPixel (circCtr.x + circPt.y, circCtr.y  circPt.x);
setPixel (circCtr.x  circPt.y, circCtr.y  circPt.x);
}
OpenGL
#include <GL/glut.h> // (or others, depending on the system in use)
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0); // Set displaywindow color to white.
glMatrixMode (GL_PROJECTION); // Set projection parameters.
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
}
void lineSegment (void)
{
glClear (GL_COLOR_BUFFER_BIT); // Clear display window.
glColor3f (0.0, 0.0, 1.0); // Set line segment color to red.
glBegin (GL_LINES);
glVertex2i (180, 15); // Specify linesegment geometry.
glVertex2i (10, 145);
glEnd ( );
glFlush ( ); // Process all OpenGL routines as quickly as possible.
}
void main (int argc, char** argv)
{
glutInit (&argc, argv); // Initialize GLUT.
glutInitDisplayMode (GLUT_SINGLE  GLUT_RGB); // Set display mode.
glutInitWindowPosition (50, 100); // Set topleft displaywindow position.
glutInitWindowSize (400, 300); // Set displaywindow width and height.
glutCreateWindow ("An Example OpenGL Program"); // Create display window.
init ( ); // Execute initialization procedure.
glutDisplayFunc (lineSegment); // Send graphics to display window.
glutMainLoop ( ); // Display everything and wait.
}
OpenGL
Point Functions
• glVertex*( );
* : 2, 3, 4
i (integer)
s (short)
f (float)
d (double)
Ex:
glBegin(GL_POINTS);
glVertex2i(50, 100);
glEnd();
int p1[ ]={50, 100};
glBegin(GL_POINTS);
glVertex2iv(p1);
glEnd();
OpenGL
Line Functions
• GL_LINES
• GL_LINE_STRIP
• GL_LINE_LOOP
Ex:
glBegin(GL_LINES);
glVertex2iv(p1);
glVertex2iv(p2);
glEnd();
OpenGL
glBegin(GL_LINES); GL_LINES GL_LINE_STRIP
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glVertex2iv(p4);
glVertex2iv(p5);
glEnd();
GL_LINE_LOOP
p1
p1
p1
p2
p3
p2
p2
p4
p3
p3
p5
p4
p4
p5
Antialiasing
Supersampling
Count the
number of
subpixels
that overlap
the line path.
Set the intensity
proportional
to this count.
Antialiasing
Area Sampling
Line is treated as a rectangle.
Calculate the overlap areas
for pixels.
Set intensity proportional to
the overlap areas.
80% 25%
Antialiasing
Pixel Sampling
Micropositioning
Electron beam is shifted 1/2,
1/4, 3/4 of a pixel diameter.
Line Intensity differences
Change the line drawing
algorithm:
For horizontal and
vertical lines use the
lowest intensity
For 45
o
lines use the
highest intensity
2D Transformations
with Matrices
Matrices
(
(
(
¸
(
¸
=
3 , 3 2 , 3 1 , 3
3 , 2 2 , 2 1 , 2
3 , 1 2 , 1 1 , 1
a a a
a a a
a a a
A
A matrix is a rectangular array of numbers.
A general matrix will be represented by an uppercase italicised
letter.
The element on the ith row and jth column is denoted by a
i,j
. Note
that we start indexing at 1, whereas C indexes arrays from 0.
Given two matrices A and B if we want to add B to A (that is
form A+B) then if A is (n×m), B must be (n×m), Otherwise,
A+B is not defined.
The addition produces a result, C = A+B, with elements:
Matrices – Addition
j i j i j i
B A C
, , ,
+ =
(
¸
(
¸
=
(
¸
(
¸
+ +
+ +
=
(
¸
(
¸
+
(
¸
(
¸
12 10
8 6
8 4 7 3
6 2 5 1
8 7
6 5
4 3
2 1
Given two matrices A and B if we want to multiply B by A (that
is form AB) then if A is (n×m), B must be (m×p), i.e., the
number of columns in A must be equal to the number of rows
in B. Otherwise, AB is not defined.
The multiplication produces a result, C = AB, with elements:
(Basically we multiply the first row of A with the first column of
B and put this in the c
1,1
element of C. And so on…).
Matrices – Multiplication
¿
=
=
m
k
kj ik j i
b a C
1
,
(
(
(
¸
(
¸
=
(
(
(
¸
(
¸
×
(
(
(
¸
(
¸
96 66
95 55
76 44
6 2
3 3
8 6
3 2 9
8 5 4
7 6 2
Matrices – Multiplication (Examples)
2×6+ 6×3+ 7×2=44
(
(
(
¸
(
¸
×
(
¸
(
¸
6 2
3 3
8 6
5 4
6 2
Undefined!
2x2 x 3x2 2!=3
2x2 x 2x4 x 4x4 is allowed. Result is 2x4 matrix
Unlike scalar multiplication, AB ≠ BA
Matrix multiplication distributes over addition:
A(B+C) = AB + AC
Identity matrix for multiplication is defined as I.
The transpose of a matrix, A, is either denoted A
T
or A‟ is
obtained by swapping the rows and columns of A:
Matrices  Basics
(
(
(
¸
(
¸
= ¬
(
¸
(
¸
=
3 , 2 3 , 1
2 , 2 2 , 1
1 , 2 1 , 1
3 , 2 2 , 2 1 , 2
3 , 1 2 , 1 1 , 1
'
a a
a a
a a
A
a a a
a a a
A
2D Geometrical Transformations
Translate
Rotate
Scale
Shear
Translate Points
Recall.. We can translate points in the (x, y) plane to new positions
by adding translation amounts to the coordinates of the points. For
each point P(x, y) to be moved by d
x
units parallel to the x axis and by d
y
units parallel to the y axis, to the new point P’(x’, y’ ). The translation has
the following form:
y
x
d y y
d x x
+ =
+ =
'
'
P(x,y)
P’(x’,y’)
d
x
d
y
In matrix format:
(
¸
(
¸
+
(
¸
(
¸
=
(
¸
(
¸
y
x
d
d
y
x
y
x
'
'
If we define the translation matrix , then we have P’ =P + T.
(
¸
(
¸
=
y
x
d
d
T
Scale Points
Points can be scaled (stretched) by s
x
along the x axis and by s
y
along the y axis into the new points by the multiplications:
We can specify how much bigger or smaller by means of a “scale factor”
To double the size of an object we use a scale factor of 2, to half the size of
an obejct we use a scale factor of 0.5
y s y
x s x
y
x
=
=
'
'
P(x,y)
P’(x’,y’)
x s
x
 x
s
y
 y
y
(
¸
(
¸
(
¸
(
¸
=
(
¸
(
¸
y
x
s
s
y
x
y
x
0
0
'
'
If we define , then we have P’ =SP
(
¸
(
¸
=
y
x
s
s
S
0
0
Rotate Points (cont.)
Points can be rotated through an angle u about the origin:
u u
u o u o
u o u o
u u
u o u o
u o u o
cos sin
cos sin sin cos
) sin( ) sin(  '  '
sin cos
sin sin cos cos
) cos( ) cos(  '  '
   ' 
y x
l l
l OP y
y x
l l
l OP x
l OP OP
+ =
+ =
+ = + =
÷ =
÷ =
+ = + =
= =
P(x,y)
P’(x’,y’)
x x’
y’
y
u
o
l
O
(
¸
(
¸
(
¸
(
¸
÷
=
(
¸
(
¸
y
x
y
x
u u
u u
cos sin
sin cos
'
'
P’ =RP
Review…
Translate: P‟ = P+T
Scale: P‟ = SP
Rotate: P‟ = RP
Spot the odd one out…
• Multiplying versus adding matrix…
• Ideally, all transformations would be the same..
• easier to code
Solution: Homogeneous Coordinates
Homogeneous Coordinates
For a given 2D coordinates (x, y), we introduce a third dimension:
[x, y, 1]
In general, a homogeneous coordinates for a 2D point has the form:
[x, y, W]
Two homogeneous coordinates [x, y, W] and [x’, y’, W’] are said to be of the
same (or equivalent) if
x = kx’ eg: [2, 3, 6] = [4, 6, 12]
y = ky’ for some k ≠ 0 where k=2
W = kW’
Therefore any [x, y, W] can be normalised by dividing each element by W:
[x/W, y/W, 1]
Homogeneous Transformations
Now, redefine the translation by using homogeneous coordinates:
Similarly, we have:
(
¸
(
¸
+
(
¸
(
¸
=
(
¸
(
¸
y
x
d
d
y
x
y
x
'
'
(
(
(
¸
(
¸
(
(
(
¸
(
¸
=
(
(
(
¸
(
¸
1 1 0 0
1 0
0 1
1
'
'
y
x
d
d
y
x
y
x
P T P × = '
(
(
(
¸
(
¸
(
(
(
¸
(
¸
=
(
(
(
¸
(
¸
1 1 0 0
0 0
0 0
1
'
'
y
x
s
s
y
x
y
x
(
(
(
¸
(
¸
(
(
(
¸
(
¸
÷
=
(
(
(
¸
(
¸
1 1 0 0
0 cos sin
0 sin cos
1
'
'
y
x
y
x
u u
u u
Scaling Rotation
P’ = S × P P’ = R × P
Composition of 2D Transformations
1. Additivity of successive translations
We want to translate a point P to P’ by T(d
x1
, d
y1
) and then to P’’ by
another T(d
x2
, d
y2
)
On the other hand, we can define T
21
= T(d
x1
, d
y1
) T(d
x2
, d
y2
) first, then
apply T
21
to P:
where
] ) , ( )[ , ( ' ) , ( ' '
1 1 2 2 2 2
P d d T d d T P d d T P
y x y x y x
= =
P T P
21
' ' =
(
(
(
¸
(
¸
+
+
=
(
(
(
¸
(
¸
(
(
(
¸
(
¸
=
=
1 0 0
1 0
0 1
1 0 0
1 0
0 1
1 0 0
1 0
0 1
) , ( ) , (
2 1
2 1
1
1
2
2
1 1 2 2 21
y y
x x
y
x
y
x
y x y x
d d
d d
d
d
d
d
d d T d d T T
T(1,2) T(1,1)
(2,1)
(1,3)
(2,2)
(
(
(
¸
(
¸
=
(
(
(
¸
(
¸
÷
(
(
(
¸
(
¸
÷ =
1 0 0
1 1 0
0 0 1
1 0 0
2 1 0
1 0 1
1 0 0
1 1 0
1 0 1
21
T
Examples of Composite 2D Transformations
Composition of 2D Transformations (cont.)
2. Multiplicativity of successive scalings
where
P S
P s s S s s S
P s s S s s S P
y x y x
y x y x
21
1 1 2 2
1 1 2 2
)] , ( ) , ( [
] ) , ( )[ , ( ' '
=
=
=
(
(
(
¸
(
¸
=
(
(
(
¸
(
¸
(
(
(
¸
(
¸
=
=
1 0 0
0 * 0
0 0 *
1 0 0
0 0
0 0
1 0 0
0 0
0 0
) , ( ) , (
1 2
1 2
1
1
2
2
1 1 2 2 21
y y
x x
y
x
y
x
y x y x
s s
s s
s
s
s
s
s s S s s S S
Composition of 2D Transformations (cont.)
3. Additivity of successive rotations
where
P R
P R R
P R R P
21
1 2
1 2
)] ( ) ( [
] ) ( )[ ( ' '
=
=
=
u u
u u
(
(
(
¸
(
¸
+ +
+ ÷ +
=
(
(
(
¸
(
¸
÷
(
(
(
¸
(
¸
÷
=
=
1 0 0
0 ) cos( ) sin(
0 ) sin( ) cos(
1 0 0
0 cos sin
0 sin cos
1 0 0
0 cos sin
0 sin cos
) ( ) (
1 2 1 2
1 2 1 2
1 1
1 1
2 2
2 2
1 2 21
u u u u
u u u u
u u
u u
u u
u u
u u R R R
Composition of 2D Transformations (cont.)
4. Different types of elementary transformations discussed above
can be concatenated as well.
where
MP
P d d T R
P d d T R P
y x
y x
=
=
=
)] , ( ) ( [
] ) , ( )[ ( '
u
u
) , ( ) (
y x
d d T R M u =
Consider the following two questions:
1) translate a line segment P
1
P
2
, say, by 1 units in the x direction
and 2 units in the y direction.
2). Rotate a line segment P
1
P
2
, say by u degrees counter clockwise,
about P
1
.
P
1
(1,2)
P
2
(3,3)
P’
2
P’
1
P
1
(1,2)
P
2
(3,3)
P’
2
P’
1
u
Other Than Point Transformations…
Translate Lines: translate both endpoints, then join them.
Scale or Rotate Lines: More complex. For example, consider to
rotate an arbitrary line about a point P
1
,
three steps are needed:
1). Translate such that P
1
is at the origin;
2). Rotate;
3). Translate such that the point at the origin
returns to P
1
.
T(1,2) R(u)
P
1
(1,2)
P
2
(3,3)
P
2
(2,1)
T(1,2)
P
2
P
2
P
1
P
1
P
1
u
Another Example.
Scale
Translate
Rotate
Translate
Order Matters!
As we said, the order for composition of 2D geometrical transformations matters,
because, in general, matrix multiplication is not commutative. However, it is easy to
show that, in the following four cases, commutativity holds:
1). Translation + Translation
2). Scaling + Scaling
3). Rotation + Rotation
4). Scaling (with s
x
= s
y
) + Rotation
just to verify case 4:
if s
x
= s
y
, M
1
= M
2
.
(
(
(
¸
(
¸
÷
=
(
(
(
¸
(
¸
÷
(
(
(
¸
(
¸
=
=
1 0 0
0 cos * sin *
0 sin * cos *
1 0 0
0 cos sin
0 sin cos
1 0 0
0 0
0 0
) ( ) , (
1
u u
u u
u u
u u
u
y y
x x
y
x
y x
s s
s s
s
s
R s s S M
(
(
(
¸
(
¸
÷
=
(
(
(
¸
(
¸
(
(
(
¸
(
¸
÷
=
=
1 0 0
0 cos * sin *
0 sin * cos *
1 0 0
0 0
0 0
1 0 0
0 cos sin
0 sin cos
) , ( ) (
2
u u
u u
u u
u u
u
y x
y x
y
x
y x
s s
s s
s
s
s s S R M
RigidBody vs. Affine Transformations
A transformation matrix of the form
where the upper 2×2 submatrix is orthogonal, preserves angles and
lengths. Such transforms are called rigidbody transformations,
because the body or object being transformed is not distorted in any
way. An arbitrary sequence of rotation and translation matrices
creates a matrix of this form.
The product of an arbitrary sequence of rotation, translations, and
scale matrices will cause an affine transformation, which have the
property of preserving parallelism of lines, but not of lengths and
angles.
(
(
(
¸
(
¸
1 0 0
22 21
12 11
y
x
t r r
t r r
RigidBody vs. Affine Transformations (cont.)
Shear transformation is also affine.
Unit cube
45º
Scale in x, not in y
Rigid body
Transformation
Affine
Transformation
Shear in the x direction Shear in the y direction
(
(
(
¸
(
¸
=
1 0 0
0 1 0
0 1 a
SH
x
(
(
(
¸
(
¸
=
1 0 0
0 1
0 0 1
b SH
y
2D Output Primitives
Points
Lines
Circles
Ellipses
Other curves
Filling areas
Text
Patterns
Polymarkers
Filling area
Polygons are considered!
1) ScanLine Filling (between edges)
2) Interactive Filling (using an interior
starting point)
1) ScanLine Filling (scan
conversion)
Problem: Given the vertices or edges of a
polygon, which are the pixels to be
included in the area filling?
ScanLine filling, cont’d
Main idea:
locate the intersections between the
scanlines and the edges of the polygon
sort the intersection points on each
scanline on increasing xcoordinates
generate framebuffer positions along
the current scanline between pairwise
intersection points
Main idea
ScanLine filling, cont’d
Problems with intersection points that are
vertices:
Basic rule: count them as if each vertex is
being two points (one to each of the two joining
edges in the vertex)
Exception: if the two edges joining in the
vertex are on opposite sides of the scanline,
then count the vertex only once (require some
additional processing)
Vertex problem
ScanLine filling, cont’d
Timeconsuming to locate the intersection points!
If an edge is crossed by a scanline, most
probably also the next scanline will cross it
(the use of coherence properties)
ScanLine filling, cont’d
Each edge is well described by an edge
record:
y
max
x
0
(initially the x related to y
min
)
Ax/Ay (inverse of the slope)
(possibly also Ax and Ay)
Ax/Ay is used for incremental calculations
of the intersection points
Edge Records
ScanLine filling, cont’d
The intersection point (x
n
,y
n
) between an edge
and scanline y
n
follows from the line equation
of the edge:
y
n
= Ay/Ax
.
x
n
+ b (cp. y = m
.
x + b)
The intersection between the same edge and the
next scanline y
n+1
is then given from the
following:
y
n+1
= Ay/Ax
.
x
n+1
+ b
and also
y
n+1
= y
n
+ 1 = Ay/Ax
.
x
n
+ b +1
ScanLine filling, cont’d
This gives us:
x
n+1
= x
n
+ Ax/Ay , n = 0, 1, 2, …..
i.e. the new value of x on the next scan
line is given by adding the inverse of the
slope to the current value of x
ScanLine filling, cont’d
An active list of edge records intersecting
with the current scanline is sorted on
increasing xcoordinates
The polygon pixels that are written in the
frame buffer are those which are
calculated to be on the current scanline
between pairwise xcoordinates
according to the active list
ScanLine filling, cont’d
When changing from one scanline to the next,
the active edge list is updated:
a record with y
max
< ”the next scanline” is
removed
in the remaining records, x
0
is incremented and
rounded to the nearest integer
an edge with y
min
= ”the next scanline” is
included in the list
ScanLine Filling Example
2) Interactive Filling
Given the boundaries of a closed surface.
By choosing an arbitrary interior point,
the complete interior of the surface will
be filled with the color of the user‟s
choice.
Interactive Filling, cont’d
Definition: An area or a boundary is said to be 4
connected if from an arbitrary point all other
pixels within the area or on the boundary can
be reached by only moving in horizontal or
vertical steps.
Furthermore, if it is also allowed to take
diagonal steps, the surface or the boundary is
said to be 8connected.
4/8connected
Interactive Filling, cont’d
A recursive procedure for filling a 4
connected (8connected) surface can
easily be defined.
Assume that the surface shall have the
same color as the boundary (can easily
be modified!).
The first interior position (pixel) is choosen
by the user.
Interactive Filling, algorithm
void fill(int x, int y, int fillColor) {
int interiorColor;
interiorColor = getPixel(x,y);
if (interiorColor != fillColor) {
setPixel(x, y, fillColor);
fill(x + 1, y, fillColor);
fill(x, y + 1, fillColor);
fill(x  1, y, fillColor);
fill(x, y  1, fillColor); } }
InsideOutside test
When is a point an interior point?
OddEven Rule
Draw conceptually a line from a specified point to
a distant point outside the coordinate space;
count the number of polygon edges that are
crossed
if odd => interior
if even => exterior
Note! The vertices!
Text
Representation:
* bitmapped (raster)
+ fast
 more storage
 less good for
styles/sizes
* outlined (lines and
curves)
+ less storage
+ good for styles/sizes
 slower
Other output primitives
* pattern (to fill an area)
normally, an n x m rectangular
color pixel array with a specified
reference point
* polymarker (marker symbol)
a character representing a point
* (polyline)
a connected sequence of line segments
Attributes
Influence the way a primitive is displayed
Two main ways of introducing attributes:
1) added to primitive‟s parameter list
e.g. setPixel(x, y, color)
2) a list of current attributes (to be
updated when changed)
e.g setColor(color); setPixel(x, y);
Attributes for lines
Lines (and curves) are normally infinitely thin
type
• dashed, dotted, solid, dotdashed, …
• pixel mask, e.g. 11100110011
width
• problem with the joins; line caps are used to adjust
shape
pen/brush shape
color (intensity)
Lines with width
Line caps
Joins
Attributes for area fill
fill style
• hollow, solid, pattern, hatch fill, …
color
pattern
• tiling
Tiling
Tiling = filling surfaces (polygons) with a
rectangular pattern
Attributes for characters/strings
style
font (typeface)
color
size (width/height)
orientation
path
spacing
alignment
Text attributes
Text attributes, cont’d
Text attributes, cont’d
Text attributes, cont’d
Color as attribute
Each color has a numerical value, or intensity,
based on some color model.
A color model typically consists of three primary
colors, in the case of displays Red, Green and
Blue (RGB)
For each primary color an intensity can be given,
either 0255 (integer) or 01 (float) yielding the
final color
256 different levels of each primary color means
3x8=24 bits of information to store
Color representations
Two different ways of storing a color value:
1) a direct color value storage/pixel
2) indirectly via a color lookup table
index/pixel (typically 256 or 512
different colors in the table)
Color Lookup Table
Antialiasing
Aliasing ≈ the fact that exact points are
approximated by fixed pixel positions
Antialiasing = a technique that
compensates for this (more than one
intensity level/pixel is required)
Antialiasing, a method
A polygon will be studied (as an example).
Area sampling (prefiltering): a pixel that is only
partly included in the exact polygon, will be
given an intensity that is proportional to the
extent of the pixel area that is covered by the
true polygon
Area sampling
P = polygon intensity
B = background intensity
f = the extent of the pixel
area covered by the true
polygon
¬ pixel intensity =
P*f + B*(1  f)
Note! Time consuming to
calculate f
Topics
Clipping
CohenSutherland Line Clipping Algorithm
Clipping
Why clipping?
• Not everything defined in the world
coordinates is inside the world window
Where does clipping take place?
OpenGL does it for you
• BUT, as a CS major, you should know how it
is done.
Model
Viewport
Transformation
Clipping
…
Line Clipping
int clipSegment(p1, p2, window)
• Input parameters: p1, p2, window
p1, p2: 2D endpoints that define a line
window: aligned rectangle
• Returned value:
1, if part of the line is inside the window
0, otherwise
• Output parameters: p1, p2
p1 and/or p2‟s value might be changed so
that both p1 and p2 are inside the window
Line Clipping
Example
• Line RetVal Output
AB
BC
CD
DE
EA
o P1
o P2
o P3
o P4
o P1
o P2
o P3
o P4
CohenSutherland Line Clipping
Algorithm
Trivial accept and trivial reject
• If both endpoints within window ¬ trivial accept
• If both endpoints outside of same boundary of
window ¬ trivial reject
Otherwise
• Clip against each edge in turn
Throw away “clipped off” part of line each time
How can we do it efficiently (elegantly)?
CohenSutherland Line Clipping
Algorithm
Examples:
• trivial accept?
• trivial reject?
window
L1
L2
L3
L4
L5
L6
CohenSutherland Line Clipping
Algorithm
Use “region outcode”
CohenSutherland Line Clipping
Algorithm
outcode[1] ÷ (x < Window.left)
outcode[2] ÷ (y > Window.top)
outcode[3] ÷ (x > Window.right)
outcode[4] ÷ (y < Window.bottom)
CohenSutherland Line Clipping
Algorithm
Both outcodes are FFFF
• Trivial accept
Logical AND of two outcodes = FFFF
• Trivial reject
Logical AND of two outcodes = FFFF
• Can‟t tell
• Clip against each edge in turn
Throw away “clipped off” part of line each time
CohenSutherland Line Clipping
Algorithm
Examples:
• outcodes?
• trivial accept?
• trivial reject?
window
L1
L2
L3
L4
L5
L6
CohenSutherland Line Clipping
Algorithm
int clipSegment(Point2& p1, Point2& p2, RealRect W)
do
if(trivial accept) return 1;
else if(trivial reject) return 0;
else
if(p1 is inside) swap(p1, p2)
if(p1 is to the left) chop against the left
else if(p1 is to the right) chop against the right
else if(p1 is below) chop against the bottom
else if(p1 is above) chop against the top
while(1);
CohenSutherland Line Clipping
Algorithm
A segment that requires 4 clips
CohenSutherland Line Clipping
Algorithm
How do we chop against each boundary?
÷ Given P1 (outside) and P2, (A.x,A.y)=?
CohenSutherland Line Clipping
Algorithm
Let dx = p1.x  p2.x dy = p1.y  p2.y
A.x = w.r d = p1.y  A.y e = p1.x  w.r
d/dy = e/dx
¬ p1.y  A.y = (dy/dx)(p1.x  w.r)
¬ A.y = p1.y  (dy/dx)(p1.x  w.r)
= p1.y + (dy/dx)(w.r  p1.x)
As A is the new P1
¬ p1.y += (dy/dx)(w.r  p1.x)
p1.x = w.r
Q: Will we have
dividedbyzero
problem?
UNITII
THREE
DIMENSIONAL
CONCEPTS
3D VIEWING
3D Viewingcontents
•Viewing pipeline
•Viewing coordinates
•Projections
•View volumes and general projection
transformations
•clipping
3D Viewing
World coordinate system(where the
objects are modeled and defined)
Viewing coordinate system(viewing objects
with respect to another user defined coordinate
system)
Scene coordinate system(a viewing
coordinate system chosen to be at the centre
of a scene)
Object coordinate system(a coordinate
system specific to an object.)
3D viewing
Simple camera analogy is adopted
3D viewingpipeline
3D viewing
Defining the viewing coordinate system and
specifying the view plane
3D viewing
First pick up a world coordinate position
called the view reference point. This is the origin
of the VC system
Pick up the +ve direction for the Z
v
axis
and the orientation of the view plane by
specifying the view plane normal vector „N‟.
Choose a world coordinate position and
this point establishes the direction for N relative
to either the world or VC origin. The view plane
normal vector is the directed line segment.
steps to establish a Viewing coordinate system or view reference
coordinate system and the view plane
3D viewing
steps to establish a Viewing coordinate system or view reference coordinate
system and the view plane
Some packages allow us to choose a look at
point relative to the view reference point.
Or set up a Left handed viewing system and
take the N and the +ve Z
v
axis from the viewing
origin to the look at point.
3D viewing
steps to establish a Viewing coordinate system or view reference
coordinate system and the view plane
We now choose the view up vector V. It can
be specified as a twist angle O about Z
v
axis.
Using N,V U can be specified.
Generally graphics packages allow users to
choose a position of the view plane along the Z
v
axis
by specifying the view plane distance from the
viewing origin.
The view plane is always parallel to the X
v
Y
v
plane.
3D viewing
To obtain a series of views of a scene we
can keep the view reference point fixed and change
the direction of N or we can fix N direction and move
the view reference point around the scene.
3D viewing
(a)
Invert Viewing
z Axis
(b)
Translate Viewing
Origin to World Origin
(c)
Rotate About World x Axis
to Bring Viewing z Axis into
the xz Plane of the World System
(d)
Rotate About the World
y Axis to Align
the Two z Axes
(e)
Rotate About the World
z Axis to Align the Two
Viewing Systems
w
x
w
y
w
z
w
x
w
y
w
z
w
x
w
y
w
z
w
x
w
y
w
z
w
x
w
y
w
z
v
x
v
y
v
z
v
z
v
y
v
x
v
x
v
y
v
z
v
z
v
x
v
y
v
z
v
y
v
x
Transformation from world to viewing coordinate system
M
wc,vc
=R
z
R
y
R
x
.T
What Are Projections?
Picture Plane
Objects in
World Space
Our 3D scenes are all specified in 3D world coordinates
To display these we need to generate a 2D image  project objects
onto a picture plane
Converting From 3D To 2D
Projection is just one part of the process of converting from 3D
world coordinates to a 2D image
Clip against
view volume
Project onto
projection
plane
Transform to
2D device
coordinates
3D world
coordinate
output
primitives
2D device
coordinates
Types Of Projections
There are two broad classes of
projection:
Parallel: Typically used for architectural and engineering
drawings
Perspective: Realistic looking and used in computer graphics
Perspective Projection
Parallel Projection
Taxonomy Of Projections
Types Of Projections
There are two broad classes of projection:
• Parallel:
preserves relative proportions of objects
accurate views of various sides of an object can be obtained
does not give realistic representations of the appearance of a
3D objective.
• Perspective:
produce realistic views but does not preserve relative
proportions
projections of distant objects are smaller than the projections
of objects of the same size that are closer to the projection
plane.
Parallel Projections
Some examples of parallel projections
Orthographic Projection(axonometric)
Orthographic
oblique
Parallel Projections
Some examples of parallel projections
Isometric projection for a cube
The projection
plane is aligned so that it
intersects each coordinate
axes in which the object is
defined (principal axes) at
the same distance from the
origin.
All the principal
axes are foreshortened
equally.
Parallel Projections
Transformation equations for an orthographic parallel projections is simple
Any point (x,y,z) in viewing coordinates is transformed to projection
coordinates as
Xp=X Yp=Y
Parallel Projections
Transformation equations for oblique projections is as below.
Oblique projections
(
(
(
(
¸
(
¸
(
(
(
(
¸
(
¸
=
(
(
(
(
(
¸
(
¸
1 1 0 0 0
0 0 0 0
0 sin 1 0
0 cos 0 1
1
1
z
y
x
L
L
w
z
y
x
p
p
p
p


Parallel Projections
Transformation equations for oblique projections is as below.
Oblique projections
(
(
(
(
¸
(
¸
(
(
(
(
¸
(
¸
=
(
(
(
(
(
¸
(
¸
1 1 0 0 0
0 0 0 0
0 sin 1 0
0 cos 0 1
1
1
z
y
x
L
L
w
z
y
x
p
p
p
p


An orthographic projection is
obtained when L1=0.
In fact the effect of the projection
matrix is to shear planes of
constant Z and project them on to
the view plane.
•Two common oblique parallel projections:
–Cavalier and Cabinet
Parallel Projections
Oblique projections
•2 common oblique parallel projections:
Cavalier projection
° =
=
45
1 tan
o
o
Cabinet projection
° =
=
4 . 63
2 tan
o
o
All lines perpendicular to the projection
plane are projected with no change in
length.
They are more realistic than cavaliar
Lines perpendicular to the viewing
surface are projected at onehalf their
length.
Perspective Projections
visual effect is similar to human visual system...
has 'perspective foreshortening„
size of object varies inversely with distance from the center of projection.
angles only remain intact for faces parallel to projection plane.
Perspective Projections
Where u varies from o to 1
Perspective Projections
Perspective Projections
If the view plane is the UV plane itself then Zvp=0.
The projection coordinates become
Xp=X(Zprp/(ZprpZ))=X(1/(1Z/Zprp))
Yp=Y(Zprp/(ZprpZ))=Y(1/(1Z/Zprp))
If the PRP is selected at
the viewing cooridinate
origin then Zprp=0
The projection coordinates
become
Xp=X(Zvp/Z)
Yp=Y(Zvp/Z)
Perspective Projections
There are a number of different kinds of perspective views
The most common are onepoint and two point perspectives
Onepoint perspective
projection
Twopoint perspective
projection
Coordinate description
Perspective Projections
Parallel lines that are parallel to the view plane are
projected as parallel lines. The point at which a set of projected
parallel lines appear to converge is called a vanishing point.
If a set of lines are parallel to one of the three principle
axes, the vanishing point is called an principal vanishing point.
There are at most 3 such points, corresponding to the number of
axes cut by the projection plane.
View volume
View volume
Perspective projection
Parallel projection
The size of the view volume depends on the size of the window but the
shape depends on the type of projection to be used.
Both near and far planes must be on the same side of the reference
point.
View volume
Often the view plane is positioned at the view reference point or on the
front clipping plane while generating parallel projection.
Perspective effects depend on the positioning of the projection
reference point relative to the view plane
VPN
B
F
Front
Clipping
Plane
View
Plane
Back
Clipping
Plane
Direction of
Propagation
VPN
Front
Clipping
Plane
View
Plane
Back
Clipping
Plane
B
F
VRP
VRP
Direction of
Propagation
VPN
Front
Clipping
Plane
View
Plane
Back
Clipping
Plane
B F
VRP
View volume  PHIGS
View volume
In an animation sequence, we can
place the projection reference point at the
viewing coordinate origin and put the view
plane in front of the scene.
We set the field of view by
adjusting the size of the window relative to
the distance of the view plane from the
PRP.
We move through the scene by
moving the viewing reference frame and
the PRP will move with the view reference
point.
N
Direction of
Projection
N
Near
Plane
Far
Plane
Window
(a)
Original Orientation
(b)
After Shearing
Direction of
Projection
Window
Near
Plane
Far
Plane
View
Volume
View
Volume
Parallel
General parallel projection
transformation
General parallel projection
transformation
) , 0 , 0 ( : ) , , ( : c c b a ¬
c
b
b b c b
c
a
a a c a
c c
b
a
b
a
÷ = ¬ = · +
÷ = ¬ = · +
(
(
(
(
¸
(
¸
=
(
(
(
(
¸
(
¸
(
(
(
(
¸
(
¸
1 1
1 1
1
1
0
0
0
0
0
0 1 0 0 0
0 1 0 0
0 1 0
0 0 1
Shearing
Let V
p
=(a,b,c) be the projection
vector in viewing coordinates.
The shear transformation can
be expressed as
V‟
p
=M
parallel
.V
p
Where M
parallel
is
For an orthographic parallel
projection M
parallel
becomes the
identity matrix since a
1
=b
1
=0
Parallel
Perspective
N
N
View
Volume
View
Volume
Far
Near
Window
Far
Near
Window
Center of
Projection
Center of
Projection
(a)
Original Orientation
(b)
After Transformation
Shearing
Regularization of Clipping
(View) Volume (Cont‟)
General perspective projection
transformation
General perspective projection
transformation
Perspective
Steps
1. Shear the view volume so that the
centerline of the frustum is
perpendicular to the view plane
2. Scale the view volume with a
scaling factor that depends on 1/z.
A shear operation is to align a general
perspective view volume with the
projection window.
The transformation involves a
combination of zaxis shear and a
translation.
M
perspective
=M
scale
.M
shear
Clipping
View volume clipping boundaries are planes whose
orientations depend on the type of projection, the projection
window and the position of the projection reference point
The process of finding the intersection of a line with one
of the view volume boundaries is simplified if we convert the view
volume before clipping to a rectangular parallelepiped.
i.e we first perform the projection transformation which
converts coordinate values in the view volume to orthographic
parallel coordinates.
Oblique projection view volumes are converted to a
rectangular parallelepiped by the shearing operation and
perspective view volumes are converted with a combination of
shear and scale transformations.
Clippingnormalized view
volumes
The normalized view volume is a region defined by the planes
X=0, x=1, y=0, y=1, z=0, z=1
Clippingnormalized view
volumes
There are several advantages to clipping against the
unit cube
1. The normalized view volume provides a standard
shape for representing any sized view volume.
2. Clipping procedures are simplified and standardized
with unit clipping planes or the viewport planes.
3. Depth cueing and visiblesurface determination are
simplified, since Zaxis always points towards the
viewer.
Unit cube
3D viewport
Mapping positions within a rectangular
view volume to a threedimensional
rectangular viewport is accomplished
with a combination of scaling and
translation.
Clippingnormalized view
volumes
Unit cube
3D viewport
Mapping positions within a
rectangular view volume to a
threedimensional rectangular
viewport is accomplished with a
combination of scaling and
translation.
Dx 0 0 Kx
0 Dy 0 Ky
0 0 Dz Kz
0 0 0 1
Where
D
x
=(xv
max
xv
min
)/(xw
max
xw
min
) and K
x
= xv
min
 xw
min
D
x
D
y
= (yv
max
yv
min
)/(yw
max
yw
min
) and K
y
= yv
min
 yw
min
D
y
D
z
= (zv
max
zv
min
)/(zw
max
zw
min
) and K
z
= zv
min
 zw
min
D
z
Viewport clipping
For a line endpoint at position
(x,y,z) we assign the bit positions
in the region code from right to left
as
Bit 1 = 1 if x< xv
min
(left)
Bit 1 = 1 if x< xv
max
(right)
Bit 1 = 1 if y< yv
min
(below)
Bit 1 = 1 if y< yv
max
(above)
Bit 1 = 1 if z< zv
min
(front)
Bit 1 = 1 if z< zv
max
(back)
Viewport clipping
For a line segment with endpoints
P1(x1,y1,z1) and P2(x2,y2,z2) the
parametric equations can be
X=x1+(x2x1)u
Y=y1+(y2y1)u
Z=z1+(z2z1)u
Hardware implementations
WORLDCOORDINATE
Object descriptions
Transformation Operations
Clipping Operations
Conversion to Device Coordinates
3D Transformations
2D coordinates 3D coordinates
x
y
x
y
z
x
z
y
Righthanded coordinate system:
3D Transformations (cont.)
1. Translation in 3D is a simple extension from that in 2D:
2. Scaling is similarly extended:
(
(
(
(
¸
(
¸
=
1 0 0 0
1 0 0
0 1 0
0 0 1
) , , (
z
y
x
z y x
d
d
d
d d d T
(
(
(
(
¸
(
¸
=
1 0 0 0
0 0 0
0 0 0
0 0 0
) , , (
z
y
x
z y x
s
s
s
s s s S
3D Transformations (cont.)
3. The 2D rotation introduced previously is just a 3D rotation about
the z axis.
similarly we have:
X
Y
Z
(
(
(
(
¸
(
¸
÷
=
1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin cos
) (
u u
u u
u
z
R
(
(
(
(
¸
(
¸
÷
=
1 0 0 0
0 cos sin 0
0 sin cos 0
0 0 0 1
) (
u u
u u
u
x
R
(
(
(
(
¸
(
¸
÷
=
1 0 0 0
0 cos 0 sin
0 0 1 0
0 sin 0 cos
) (
u u
u u
u
y
R
Composition of 3D Rotations
In 3D transformations, the order of a sequence of rotations matters!
(
(
(
(
¸
(
¸
÷
÷
=
(
(
(
(
¸
(
¸
÷
(
(
(
(
¸
(
¸
÷
=
1 0 0 0
0 cos 0 sin
0 sin sin cos cos sin
0 sin cos sin cos cos
1 0 0 0
0 cos 0 sin
0 0 1 0
0 sin 0 cos
1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin cos
) ( ) (
 
 o o  o
 o o  o
 
 
o o
o o
 o
y z
R R
(
(
(
(
¸
(
¸
÷
÷
=
(
(
(
(
¸
(
¸
÷
(
(
(
(
¸
(
¸
÷
=
1 0 0 0
0 cos sin sin cos sin
0 0 cos sin
0 sin cos sin cos cos
1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin cos
1 0 0 0
0 cos 0 sin
0 0 1 0
0 sin 0 cos
) ( ) (
 o  o 
o o
  o  o
o o
o o
 
 
o 
z y
R R
) ( ) ( ) ( ) (  o o 
y z z y
R R R R =
More Rotations
We have shown how to rotate about one of the principle axes, i.e. the
axes constituting the coordinate system. There are more we can do,
for example, to perform a rotation about an arbitrary axis:
X
Y
Z
P
2
(x
2
, y
2
, z
2
)
P
1
(x
1
, y
1
, z
1
)
We want to rotate an object about an
axis in space passing through (x
1
, y
1
, z
1
)
and (x
2
, y
2
, z
2
).
Rotating About An Arbitrary Axis
Y
Z
P
2
P
1
1). Translate the object by (x
1
, 
y
1
, z
1
): T(x
1
, y
1
, z
1
)
X
Y
Z
P
2
P
1
2). Rotate the axis about x so
that it lies on the xz plane: R
x
(o)
X
X
Y
Z
P
2
P
1
3). Rotate the axis about y so
that it lies on z: R
y
()
X
Y
Z
P
2
P
1
4). Rotate object about z by u: R
z
(u)

o
Rotating About An Arbitrary Axis (cont.)
After all the efforts, don‟t forget to undo the rotations and the translation!
Therefore, the mixed matrix that will perform the required task of rotating an
object about an arbitrary axis is given by:
M = T(x
1
,y
1
,z
1
) Rx(o)R
y
() R
z
(u) R
y
() R
x
(o)T(x
1
,y
1
,z
1
)
Finding  is trivial, but what about o?
The angle between the z axis and the
projection of P
1
P
2
on yz plane is o.
X
Y
Z
P
2
o
P
1
Composite 3D
Transformations
Example of Composite 3D Transformations
Try to transform the line segments P
1
P
2
and P
1
P
3
from their start position in (a)
to their ending position in (b).
The first solution is to compose the primitive transformations T, R
x
, R
y
, and R
z
.
This approach is easier to illustrate and does offer help on building an
understanding. The 2
nd
, more abstract approach is to use the properties of
special orthogonal matrices.
y
x
z
y
x
z
P
1
P
2
P
3
P
1
P
2
P
3
(a) (b)
Composition of 3D Transformations
Breaking a difficult problem into simpler subproblems:
1.Translate P
1
to the origin.
2. Rotate about the y axis such that P
1
P
2
lies in the (y, z) plane.
3. Rotate about the x axis such that P
1
P
2
lies on the z axis.
4. Rotate about the z axis such that P
1
P
3
lies in the (y, z) plane.
y
x
z
y
x
z
y
x
z
P
1
P
2
P
3
P
1
P
2
P
3
y
x
z
P
1
P
2
P
3
y
x
z
P
1
P
2
P
3
P
3
P
2
P
1
1
2
3 4
Composition of 3D Transformations
1.
2.
(
(
(
(
¸
(
¸
÷
÷
÷
=
÷ ÷ ÷
1 0 0 0
1 0 0
0 1 0
0 0 1
) , , (
1
1
1
1 1 1
z
y
x
z y x T
(
(
(
(
¸
(
¸
÷
=
÷ ÷
1 0 0 0
0 sin 0 cos
0 0 1 0
0 cos 0 sin
) ) 90 ( (
u u
u u
u
y
R
T
T
T
z z y y x x P z y x T P
z z y y x x P z y x T P
P z y x T P
] 1 [ ) , , (
] 1 [ ) , , (
] 1 0 0 0 [ ) , , (
1 3 1 3 1 3 3 1 1 1
'
3
1 2 1 2 1 2 2 1 1 1
'
2
1 1 1 1
'
1
÷ ÷ ÷ =  ÷ ÷ ÷ =
÷ ÷ ÷ =  ÷ ÷ ÷ =
=  ÷ ÷ ÷ =
y
x
z
P'
1
P'
2
P'
3
u D
1
Composition of 3D Transformations
3
4.
(
(
(
(
¸
(
¸
÷
=
1 0 0 0
0 cos sin 0
0 sin cos 0
0 0 0 1
) (
 
 

x
R
y
x
z
P''
1
P''
2

D
2
y
x
z
P'''
1
P'''
2
o
D
3
P'''
3
) (o
z
R
T R z y x T R R R
y x z
· = ÷ ÷ ÷ · ÷ · · ) , , ( ) 90 ( ) ( ) (
1 1 1
u  o
Finally, we have the composite matrix:
Vector Rotation
x
u
y
x
y
Rotate the vector
(
¸
(
¸
0
1
u
(
¸
(
¸
=
(
¸
(
¸
(
¸
(
¸
÷
=
u
u
u u
u u
sin
cos
0
1
cos sin
sin cos
u
The unit vector along the x axis is [1, 0]
T
. After rotating about the origin by
u, the resulting vector is
x
Vector Rotation (cont.)
y
Rotate the vector
(
¸
(
¸
1
0
(
¸
(
¸
÷
=
(
¸
(
¸
(
¸
(
¸
÷
=
u
u
u u
u u
cos
sin
1
0
cos sin
sin cos
v
x
y
u v
The above results states that if we try to rotate a vector, originally pointing the
direction of the x (or y) axis, toward a new direction, u (or v), the rotation matrix,
R, could be simply written as [u  v] without the need of any explicit knowledge
of u, the actual rotation angle.
Similarly, the unit vector along the y axis is [0, 1]
T
. After rotating about the
origin by u, the resulting vector is
Vector Rotation (cont.)
The reversed operation of the above rotation is to rotate a vector that is not
originally pointing the x (or y) direction into the direction of the positive x or y
axis. The rotation matrix in this case is R(u ), expressed by R
1
(u )
where T denotes the transpose.
) (
cos sin
sin cos
) cos( ) sin(
) sin( ) cos(
) (
1
u
u u
u u
u u
u u
u
T
T
T
R
v
u
R =
(
¸
(
¸
=
(
¸
(
¸
÷
=
(
¸
(
¸
÷ ÷
÷ ÷ ÷
=
÷
x
x
u
y
y
Rotate the vector
u
u
Example
what is the rotation matrix if one wants the vector T in the left figure to be
rotated to the direction of u.
T
(2, 3)
 
T
T
u
u
(
¸
(
¸
=
+
=
13
3
13
2
3 2
3 2
 
2 2
 
(
(
(
(
¸
(
¸
÷
= =
13
2
13
3
13
3
13
2
 v u R
If, on the other hand, one wants the vector u to be rotated to the direction of
the positive x axis, the rotation matrix should be
(
(
(
(
¸
(
¸
÷
=
(
¸
(
¸
=
13
2
13
3
13
3
13
2
T
T
v
u
R
Rotation Matrices
Rotation matrix is orthonormal:
• Each row is a unit vector
• Each row is perpendicular to the other, i.e. their dot product is zero.
• Each vector will be rotated by R(u) to lie on the positive x and y axes,
respectively. The two column vectors are those into which vectors
along the positive x and y axes are rotated.
• For orthonormal matrices, we have
1 sin cos
1 ) sin ( cos
cos sin
sin cos
2 2
2 2
= +
= ÷ +
(
¸
(
¸
÷
=
u u
u u
u u
u u
R
0 ) sin ( cos sin cos = ÷ × + × u u u u
) ( ) (
1
u u
T
R R =
÷
Cross Product
• The cross product or vector product of two vectors, v
1
and v
2
, is
another vector:
• The cross product of two vectors is orthogonal to both
• Righthand rule dictates direction of cross product.
(
(
(
¸
(
¸
÷
÷ ÷
÷
= ×
1 2 2 1
1 2 2 1
1 2 2 1
2 1
) (
y x y x
z x z x
z y z y
v v
v
1
v
2
v
1
× v
2
u
2
Extension to 3D Cases
The above examples can be extended to 3D cases….
In 2D, we need to know u, which will be
rotated to the direction of the positive x axis.
u
v
x
y
z
u
1
v=u
1
×u
2
In 3D, however, we need to know more than
one vector. See in the left figure, for example,
two vectors, u
1
and u
2
are given. If after
rotation, u
1
is aligned to the positive z axis, this
will only give us the third column in the rotation
matrix. What about the other two columns?
3D Rotation
In many cases in 3D, only one vector will be aligned to one of the
coordinate axes, and the others are often not explicitly given. Let‟s see the
example:
y
x
z
y
x
z
P
1
P
2
P
3
P
1
P
2
P
3
Note, in this example, vector P
1
P
2
will be
rotated to the positive z direction. Hence the
fist column vector in the rotation matrix is the
normalised P
1
P
2
. But what about the other
two columns? After all, P
1
P
3
is not perpendi
cular to P
1
P
2
. Well, we can find it by taking
the cross product of P
1
P
2
and P
1
P
3
. Since
P
1
P
2
× P
1
P
3
is perpendicular to both P
1
P
2
and P
1
P
3
, it will be aligned into the direction
of the positive x axis.
And the third direction is decide by the cross
product of the other two directions, which is
P
1
P
2
×(P
1
P
2
×P
1
P
2
).
Therefore, the rotation matrix should be
3D Rotation (cont.)
u
y
x
z
P
1
P
2
P
3
v
w
(
(
(
(
(
(
(
¸
(
¸
× ×
× ×
×
×
=
2 1
2 1
3 1 2 1 2 1
3 1 2 1 2 1
3 1 2 1
3 1 2 1
) (
) (
P P
P P
P P P P P P
P P P P P P
P P P P
P P P P
R
y
x
z
P
1
P
2
P
3
u
v
Yaw, Pitch, and Roll
Imagine three lines running through an airplane and intersecting at
right angles at the airplane‟s centre of gravity.
Roll: rotation around the
fronttoback axis.
Roll: rotation around the
sidetoside axis.
Roll: rotation around the
vertical axis.
An Example of the Airplane
Consider the following example. An airplane is oriented such that its nose is
pointing in the positive z direction, its right wing is pointing in the positive x
direction, its cockpit is pointing in the positive y direction. We want to
transform the airplane so that it heads in the direction given by the vector
DOF (direction of flight), is centre at P, and is not banked.
Solution to the Airplane Example
First we are to rotate the positive z
p
direction into the direction of DOF,
which gives us the third column of the rotation matrix: DOF / DOF. The x
p
axis must be transformed into a horizontal vector perpendicular to DOF –
that is in the direction of y×DOF. The y
p
direction is then given by x
p
× z
p
=
DOF ×(y × DOF).
(
(
¸
(
¸
× ×
× ×
×
×
=
DOF
DOF
DOF y DOF
DOF y DOF
DOF y
DOF y
R
) (
) (
Inverses of (2D and) 3D Transformations
1. Translation:
2. Scaling:
3. Rotation:
4. Shear:
) , , ( ) , , (
1
z y x z y x
d d d T d d d T ÷ ÷ ÷ =
÷
)
1
,
1
,
1
( ) , , (
1
z y x
z y x
s s s
S s s s S =
÷
) ( ) ( ) (
1
u u u
T
R R R = ÷ =
÷
) , ( ) , (
1
y x y x
sh sh SH sh sh SH ÷ ÷ =
÷
GRAPHICS
PROGRAMMING
Color Models
Color models,cont’d
Different meanings of color:
painting
wavelength of visible light
human eye perception
Physical properties of light
Visible light is part of the electromagnetic radiation (380
750 nm)
1 nm (nanometer) = 10
10
m (=10
7
cm)
1 Å (angstrom) = 10 nm
Radiation can be expressed in wavelength (ì) or
frequency (f), c=ìf, where c=3
.
10
10
cm/sec
Physical properties of light
White light consists of
a spectrum of all
visible colors
Physical properties of light
All kinds of light can be
described by the
energy of each
wavelength
The distribution
showing the relation
between energy and
wavelength (or
frequency) is called
energy spectrum
Physical properties of light
This distribution may indicate:
1) a dominant wavelength (or frequency)
which is the color of the light (hue), cp.
E
D
2) brightness (luminance), intensity of the
light (value), cp. the area A
3) purity (saturation), cp. E
D
 E
W
Physical properties of light
Energy spectrum for a light source with a
dominant frequency near the red color
Material properties
The color of an object depends on the so
called spectral curves for transparency
and reflection of the material
The spectral curves describe how light of
different wavelengths are refracted and
reflected (cp. the material coefficients
introduced in the illumination models)
Properties of reflected light
Incident white light upon an object is for
some wavelengths absorbed, for others
reflected
E.g. if all light is absorbed => black
If all wavelengths but one are absorbed =>
the one color is observed as the color of
the object by the reflection
Color definitions
Complementary colors  two colors
combine to produce white light
Primary colors  (two or) three colors used
for describing other colors
Two main principles for mixing colors:
additive mixing
subtractive mixing
Additive mixing
pure colors are put close to each other => a mix on the
retina of the human eye (cp. RGB)
overlapping gives yellow, cyan, magenta and white
the typical technique on color displays
Subtractive mixing
color pigments are mixed directly in some
liquid, e.g. ink
each color in the mixture absorbs its specific
part of the incident light
the color of the mixture is determined by
subtraction of colored light, e.g. yellow absorbs
blue => only red and green, i.e. yellow, will
reach the eye (yellow because of addition)
Subtractive mixing,cont’d
primary colors: cyan, magenta and
yellow, i.e. CMY
the typical technique in printers/plotters
connection between additive and
subtractive primary colors (cp. the color
models RGB and CMY)
Additive/subtractive mixing
Human color seeing
The retina of the human eye consists of cones
(78M),”tappar”, and rods (100120M), ”stavar”,
which are connected with nerve fibres to the
brain
Human color seeing,cont’d
Theory: the cones consist of various light
absorbing material
The light sensitivity of the cones and rods varies
with the wavelength, and between persons
The ”sum” of
the energy spectrum of the light
the reflection spectrum of the object
the response spectrum of the eye
decides the color perception for a person
Overview of color models
The human eye can perceive about 382000(!)
different colors
Necessary with some kind of classification sys
tem; all using three coordinates as a basis:
1) CIE standard
2) RGB color model
3) CMY color model (also, CMYK)
4) HSV color model
5) HLS color model
CIE standard
Commission
Internationale de
L‟Eclairage (1931)
not a computer
model
each color = a
weighted sum of
three imaginary
primary colors
RGB model
all colors are
generated from the
three primaries
various colors are
obtained by
changing the amount
of each primary
additive mixing
(r,g,b), 0≤r,g,b≤1
RGB model,cont’d
the RGB cube
1 bit/primary => 8 colors, 8 bits/primary => 16M colors
CMY model
cyan, magenta and
yellow are comple
mentary colors of
red,green and blue,
respectively
subtractive mixing
the typical printer
technique
CMY model,cont’d
almost the same
cube as with RGB;
only black<> white
the various colors
are obtained by
reducing light, e.g. if
red is absorbed =>
green and blue are
added, i.e cyan
RGB vs CMY
If the intensities are represented as 0≤r,g,b≤1
and 0≤c,m,y≤1 (also coordinates 0255 can be
used), then the relation between RGB and
CMY can be described as:
\

c
m
y
.




=
\

1
1
1
.




÷
\

r
g
b
.




CMYK model
For printing and graphics art industry, CMY
is not enough; a fourth primary, K which
stands for black, is added.
Conversions between RGB and CMYK are
possible, although they require some
extra processing.
HSV model
HSV stands for HueSaturationValue
described by a hexcone derived from the RGB
cube
HSV model,cont’d
Hue (0360°); ”the
color”, cp. the
dominant wave
length (128)
Saturation (01); ”the
amount of white”
(130)
Value (01); ”the
amount of black” (23)
HSV model,cont’d
The numbers given after each ”primary” are
estimates of how many levels a human being
is capable to distinguish between, which (in
theory) gives the total number of color
nuances:
128*130*23 = 382720
In Computer Graphics, usually enough with:
128*8*15 = 16384
HLS model
Another model similar
to HSV
L stands for Lightness
Color models
Some more facts about colors:
The distance between two colors in the
color cube is not a measure of how far
apart the colors are perceptionally!
Humans are more sensitive to shifts in
blue (and green?) than, for instance, in
yellow
COMPUTER
ANIMATIONS
Computer Animations
Any time sequence of visual changes in a scene.
Size, color, transparency, shape, surface texture, rotation,
translation, scaling, lighting effects, morphing, changing camera
parameters(position, orientation, and focal length), particle animation.
Design of animation sequences:
Storyboard layout
Object definitions
Keyframe specifications
generation of inbetween frames
Computer Animations
Frame by frame animation
Each frame is separately generated.
Object defintion
Objects are defined interms of basic shapes, such as
polygons or splines. In addition the associated movements for
each object are specified along with the shape.
Storyboard
It is an outline of the action
Keyframe
Detailed drawing of the scene at a particular instance
Computer Animations
Inbetweens
Intermediate frames (3 to 5 inbetweens for each two key
frames)
Motions can be generated using 2D or 3D transformation
Object parameters are stored in database
Rendering algorithms are used finally
Raster animations:
Uses raster operations.
Ex: we can animate objects along 2D motion paths using
the color table transformations. Here we predefine the object at
successive positions along the motion path, and set the
successive blocks of pixel values to color table entries
Computer Animations
Computer animation languages:
A typical task in animation specification is
Scene description – includes position of objects and light
sources, defining the photometric parameters and setting the
camera parameters.
Action specification – this involves layout of motion paths for the
objects and camera. We need viewing and perspective
transformations, geometric transformations, visible surface
detection, surface rendering, kinematics etc.,
Keyframe systems – designed simply to generate the in
betweens from the user specified key frames.
Computer Animations
Computer animation languages:
A typical task in animation specification is
Parameterized systems – allow object motion characteristics to be
specified as part of the object definitions. The adjustable
parameters control such object charateristics as degrees of
freedom, motion limitations and allowable shape changes.
Scripting systems –
allow object specifications and
animation sequences to be
defined with a userinput script.
From the script a library of various
objects and motions can be constructed.
Computer Animations
Interpolation techniques Linear
Computer Animations
Interpolation techniques
Nonlinear
Key frame systems
Morphing – Transformation of object shapes from one form to another is
called morphing.
Given two keyframes for an object transformation, we first adjust the
object specification in one of the frames so that number of polygon edges
or vertices is the same for the two frames.
Let L
k
,L
k+1
denote the number of line segments in two different frames
K,K+1
Let us define
L
max
=max(L
k
,L
k+1
)
L
min
=min(L
k
,L
k+1
)
N
e
= L
max
mod L
min
N
s
= int(L
max
/ L
min
)
Computer Animations
1
2
3‟
2‟
1‟
Key frame K
Key frame K+1
Steps
1. Dividing N
e
edges of keyframe
min
into N
s
+1 sections
2. Dividing the remaining lines of keyframe
min
into N
s
sections
Computer Animations
1
2
3‟
2‟
1‟
Key frame K
Key frame K+1
Key frame systems
Morphing – Transformation of object shapes from one form to another is
called morphing.
If we equalize the vertex count, then the similar analysis follows
Let V
k
,V
k+1
denote the number of vertices in two different frames K,K+1
Let us define
V
max
=max(L
k
,L
k+1
)
V
min
=min(L
k
,L
k+1
)
N
ls
= (V
max
–1)mod (V
min
–1)
N
p
= int((V
max
–1)
/ (V
min
–1)
Steps
1. adding N
p
points to N
ls
line sections of keyframe
min
sections
2. Adding N
p
1 points to the remaining edges of keyframe
min
Computer Animations
Simulating accelerations
Curve fitting techniques are often used to specify the animation paths
between keyframes.
To simulate accelerations we can adjust the time spacing for the in
betweens. For constant speed we use equal interval time spacing for the
inbetweens.
suppose we want „n‟ inbetweens for keyframes at times t1 and t2.
The time intervals between key frames is then divided into n+1 sub
intervals, yielding an inbetween spacing of
o t = t2t1/(n+1)
We can calculate the time for inbetweens as
tBj=t1+j o t for j=1,2,…….,n
Computer Animations
o t
Simulating accelerations
To model increase or decrease in speeds we use trignometric functions.
To model increasing speed, we want the time spacing between frames to
increase so that greater changes in position occur as the object moves faster.
We can obtain increase in interval size with the function
1cosu, 0< u<H/2
For ninbetweens the time for the jth inbetween would then be calculated as
tBj=t1+ot(1cosj H/2(n+1))
j=1,2,…….,n
For j=1
tB1=t1+ot(1cos H/2(n+1))
For j=1
tB2=t1+ot(1cos 2H/2(n+1))
where ot is the time difference
between any two key frames.
Computer Animations
Simulating deccelerations
To model increase or decrease in speeds we use trignometric functions.
To model decreasing speed, we want the time spacing between
frames to decrease. We can obtain increase in interval size with the
function
sinu, 0< u<H/2
For ninbetweens the
time for the jth inbetween would
then be calculated as
tBj=t1+ot.sinj H/2(n+1))
j=1,2,…….,n
Computer Animations
Simulating both accelerations and deccelerations
To model increase or decrease in speeds we use trignometric functions.
A combination of increasing and decreasing
speeds can be modeled using
½(1cosu) 0< u<H/2
The time for the jth inbetween is calculated as
tBj=t1+ot 1cos j[H(n+1)/2)
j=1,2,…….,n
Computer Animations
Motion specifications
Direct motion specifications
Here we explicitly give the rotation angles and translation vectors.
Then the geometric transformation matrices are applied to transform
coordinate positions.
A bouncing ball can be approximated by a sine curve
y(x)=AI(sin(ex+u
0
)Ie
kx
A is the initial amplitude
e is the angular frequency
u
0
is the phase angle
K is the damping constant
Computer Animations
Motion specifications
Goal directed systems
We can specify the motions that are to take place in general terms
that abstractly describe the actions, because they determine specific
motion paramters given the goals of the animation.
Computer Animations
Motion specifications
Kinematics
Kinematic specification
of of a motion can also be
given by simply describing
the motion path which is
often done using splines.
In inverse kinematics
we specify the intital and
final positions of objects at
specified times and the
motion parameters are
computed by the system.
Computer Animations
Motion specifications
dynamics
specification of the forces that produce the velocities and
accelerations. Descriptions of object behavior under the influence of
forces are generally referred to as a Physically based modeling (.rigid
body systems and non rigid systems such as cloth or plastic)
Ex: magnetic, gravitational, frictional etc
We can also use inverse dynamics to obtain the forces, given the initial
and final position of objects and the type of motion.
Computer Animations
Computer Animations
•Ideally suited for:
•Large volumes of objects – wind effects, liquids,
•Cloth animation/draping
•Underlying mechanisms are usually:
•Particle systems
•Massspring systems
Physics based animations
Computer Animations
Physics based animations
Computer Animations
Physics based animations
Computer Animations
Some more animation
techniques………….
Anticipation and Staging
Computer Animations
Some more animation
techniques………….
Secondary Motion
Computer Animations
Some more animation
techniques………….
Motion Capture
Computer Graphics
using OpenGL
Initial Steps in Drawing Figures
Using OpenGL
Files: .h, .lib, .dll
• The entire folder gl is placed in the Include
directory of Visual C++
• The individual lib files are placed in the lib
directory of Visual C++
• The individual dll files are placed in
C:\Windows\System32
Using OpenGL (2)
Includes:
• <windows.h>
• <gl/gl.h>
• <gl/glu.h>
• <gl/glut.h>
• <gl/glui.h> (if used)
Include in order given. If you use capital
letters for any file or directory, use them
in your include statement also.
Using OpenGL (3)
Changing project settings: Visual C++
6.0
• Project menu, Settings entry
• In Object/library modules move to the end of
the line and add glui32.lib glut32.lib glu32.lib
opengl32.lib (separated by spaces from last
entry and each other)
• In Project Options, scroll down to end of box
and add same set of .lib files
• Close Project menu and save workspace
Using OpenGL (3)
Changing Project Settings: Visual C++
.NET 2003
• Project, Properties, Linker, Command Line
• In the white space at the bottom, add
glui32.lib glut32.lib glu32.lib opengl32.lib
• Close Project menu and save your solution
Getting Started Making Pictures
Graphics display: Entire screen (a);
windows system (b); [both have usual
screen coordinates, with yaxis down];
windows system [inverted coordinates]
(c)
Basic System Drawing Commands
setPixel(x, y, color)
• Pixel at location (x, y) gets color specified by
color
• Other names: putPixel(), SetPixel(), or
drawPoint()
line(x1, y1, x2, y2)
• Draws a line between (x1, y1) and (x2, y2)
• Other names: drawLine() or Line().
Alternative Basic Drawing
current position (cp), specifies where
the system is drawing now.
moveTo(x,y) moves the pen invisibly to
the location (x, y) and then updates the
current position to this position.
lineTo(x,y) draws a straight line from the
current position to (x, y) and then
updates the cp to (x, y).
Example: A Square
moveTo(4, 4);
//move to starting
corner
lineTo(2, 4);
lineTo(2, 2);
lineTo(4, 2);
lineTo(4, 4);
//close the
square
Device Independent Graphics and
OpenGL
Allows same graphics program to be run
on many different machine types with
nearly identical output.
• .dll files must be with program
OpenGL is an API: it controls whatever
hardware you are using, and you use its
functions instead of controlling the
hardware directly.
OpenGL is open source (free).
Eventdriven Programs
Respond to events, such as mouse click
or move, key press, or window reshape
or resize. System manages event queue.
Programmer provides “callback”
functions to handle each event.
Callback functions must be registered
with OpenGL to let it know which
function handles which event.
Registering function does *not* call it!
Skeleton Eventdriven Program
// include OpenGL libraries
void main()
{
glutDisplayFunc(myDisplay); // register the redraw function
glutReshapeFunc(myReshape); // register the reshape
function
glutMouseFunc(myMouse); // register the mouse action
function
glutMotionFunc(myMotionFunc); // register the mouse motion
function
glutKeyboardFunc(myKeyboard); // register the keyboard
action function
…perhaps initialize other things…
glutMainLoop(); // enter the unending main loop
}
…all of the callback functions are defined here
Callback Functions
glutDisplayFunc(myDisplay);
• (Re)draws screen when window opened or another
window moved off it.
glutReshapeFunc(myReshape);
• Reports new window width and height for reshaped
window. (Moving a window does not produce a
reshape event.)
glutIdleFunc(myIdle);
• when nothing else is going on, simply redraws display
using void myIdle() {glutPostRedisplay();}
Callback Functions (2)
glutMouseFunc(myMouse);
• Handles mouse button presses. Knows
mouse location and nature of button (up or
down and which button).
glutMotionFunc(myMotionFunc);
• Handles case when the mouse is moved with
one or more mouse buttons pressed.
Callback Functions (3)
glutPassiveMotionFunc(myPassiveMotionFunc
)
• Handles case where mouse enters the window with
no buttons pressed.
glutKeyboardFunc(myKeyboardFunc);
• Handles key presses and releases. Knows which
key was pressed and mouse location.
glutMainLoop()
• Runs forever waiting for an event. When one occurs,
it is handled by the appropriate callback function.
Libraries to Include
GL, for which the commands begin with GL;
GLUT, the GL Utility Toolkit, opens windows,
develops menus, and manages events.
GLU, the GL Utility Library, which provides
high level routines to handle complex
mathematical and drawing operations.
GLUI, the User Interface Library, which is
completely integrated with the GLUT library.
• The GLUT functions must be available for GLUI to
operate properly.
• GLUI provides sophisticated controls and menus to
OpenGL applications.
A GL Program to Open a Window
// appropriate #includes go here – see Appendix 1
void main(int argc, char** argv)
{
glutInit(&argc, argv); // initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE  GLUT_RGB);
// set the display mode
glutInitWindowSize(640,480); // set window size
glutInitWindowPosition(100, 150);
// set window upper left corner position on screen
glutCreateWindow("my first attempt");
// open the screen window (Title: my first attempt)
// continued next slide
Part 2 of Window Program
// register the callback functions
glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);
glutMouseFunc(myMouse);
glutKeyboardFunc(myKeyboard);
myInit(); // additional initializations as
necessary
glutMainLoop(); // go into a perpetual
loop
}
Terminate program by closing window(s) it is using.
What the Code Does
glutInit (&argc, argv) initializes OpenGL
Toolkit
glutInitDisplayMode (GLUT_SINGLE 
GLUT_RGB) allocates a single display
buffer and uses colors to draw
glutInitWindowSize (640, 480) makes the
window 640 pixels wide by 480 pixels
high
What the Code Does (2)
glutInitWindowPosition (100, 150) puts
upper left window corner at position 100
pixels from left edge and 150 pixels
down from top edge
glutCreateWindow (“my first attempt”)
opens and displays the window with the
title “my first attempt”
Remaining functions register callbacks
What the Code Does (3)
The callback functions you write are
registered, and then the program enters
an endless loop, waiting for events to
occur.
When an event occurs, GL calls the
relevant handler function.
Effect of Program
Drawing Dots in OpenGL
We start with a coordinate system based
on the window just created: 0 to 679 in x
and 0 to 479 in y.
OpenGL drawing is based on vertices
(corners). To draw an object in OpenGL,
you pass it a list of vertices.
• The list starts with glBegin(arg); and ends with
glEnd();
• Arg determines what is drawn.
• glEnd() sends drawing data down the
OpenGL pipeline.
Example
glBegin (GL_POINTS);
• glVertex2i (100, 50);
• glVertex2i (100, 130);
• glVertex2i (150, 130);
glEnd();
GL_POINTS is constant builtinto Open
GL (also GL_LINES, GL_POLYGON, …)
Complete code to draw the 3 dots is in
Fig. 2.11.
Display for Dots
What Code Does: GL Function
Construction
Example of Construction
glVertex2i (…) takes integer values
glVertex2d (…) takes floating point
values
OpenGL has its own data types to make
graphics deviceindependent
• Use these types instead of standard ones
OpenGL Data Types
suffix data type C/C++ type OpenGL type name
b 8bit integer signed char GLbyte
s 16bit integer Short GLshort
i 32bit integer int or long GLint, GLsizei
f 32bit float Float GLfloat, GLclampf
d 64bit float Double GLdouble,GLclampd
ub 8bit unsigned
number
unsigned char GLubyte,GLboolean
us 16bit unsigned
number
unsigned short GLushort
ui 32bit unsigned
number
unsigned int or
unsigned long
GLuint,Glenum,GLbitfield
Setting Drawing Colors in GL
glColor3f(red, green, blue);
// set drawing color
• glColor3f(1.0, 0.0, 0.0); // red
• glColor3f(0.0, 1.0, 0.0); // green
• glColor3f(0.0, 0.0, 1.0); // blue
• glColor3f(0.0, 0.0, 0.0); // black
• glColor3f(1.0, 1.0, 1.0); // bright white
• glColor3f(1.0, 1.0, 0.0); // bright yellow
• glColor3f(1.0, 0.0, 1.0); // magenta
Setting Background Color in GL
glClearColor (red, green, blue, alpha);
• Sets background color.
• Alpha is degree of transparency; use 0.0 for
now.
glClear(GL_COLOR_BUFFER_BIT);
• clears window to background color
Setting Up a Coordinate System
void myInit(void)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 640.0, 0, 480.0);
}
// sets up coordinate system for window
from (0,0) to (679, 479)
Drawing Lines
glBegin (GL_LINES); //draws one line
• glVertex2i (40, 100); // between 2 vertices
• glVertex2i (202, 96);
glEnd ();
glFlush();
If more than two vertices are specified
between glBegin(GL_LINES) and
glEnd() they are taken in pairs, and a
separate line is drawn between each
pair.
Line Attributes
Color, thickness, stippling.
glColor3f() sets color.
glLineWidth(4.0) sets thickness. The default
thickness is 1.0.
a). thin lines b). thick lines c). stippled
lines
Setting Line Parameters
Polylines and Polygons: lists of vertices.
Polygons are closed (right); polylines
need not be closed (left).
Polyline/Polygon Drawing
glBegin (GL_LINE_STRIP);
// GL_LINE_LOOP to close polyline
(make it a polygon)
• // glVertex2i () calls go here
glEnd ();
glFlush ();
A GL_LINE_LOOP cannot be filled with
color
Examples
Drawing line graphs: connect each pair
of (x, f(x)) values
Must scale and shift
Examples (2)
Drawing polyline from vertices in a file
• # polylines
• # vertices in first polyline
• Coordinates of vertices, x y, one pair per line
• Repeat last 2 lines as necessary
File for dinosaur available from Web site
Code to draw polylines/polygons in Fig.
2.24.
Examples (3)
Examples (4)
Parameterizing Drawings: allows making
them different sizes and aspect ratios
Code for a parameterized house is in
Fig. 2.27.
Examples (5)
Examples (6)
Polyline Drawing
Code to set up an array of vertices is in
Fig. 2.29.
Code to draw the polyline is in Fig. 2.30.
Relative Line Drawing
Requires keeping track of current position on
screen (CP).
moveTo(x, y); set CP to (x, y)
lineTo(x, y); draw a line from CP to (x, y),
and then update CP to (x, y).
Code is in Fig. 2.31.
Caution! CP is a global variable, and therefore
vulnerable to tampering from instructions at
other points in your program.
Drawing Aligned Rectangles
glRecti (GLint x
1
, GLint y
1
, GLint x
2
,
GLint y
2
); // opposite corners; filled with
current color; later rectangles are drawn
on top of previous ones
Aspect Ratio of Aligned Rectangles
Aspect ratio = width/height
Filling Polygons with Color
Polygons must be convex: any line from
one boundary to another lies inside the
polygon; below, only D, E, F are convex
Filling Polygons with Color (2)
glBegin (GL_POLYGON);
• //glVertex2f (…); calls go here
glEnd ();
Polygon is filled with the current drawing
color
Other Graphics Primitives
GL_TRIANGLES,
GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN
GL_QUADS, GL_QUAD_STRIP
Simple User Interaction with Mouse
and Keyboard
Register functions:
• glutMouseFunc (myMouse);
• glutKeyboardFunc (myKeyboard);
Write the function(s)
NOTE that any drawing you do when
you use these functions must be done IN
the mouse or keyboard function (or in a
function called from within mouse or
keyboard callback functions).
Example Mouse Function
void myMouse(int button, int state, int x,
int y);
Button is one of GLUT_LEFT_BUTTON,
GLUT_MIDDLE_BUTTON, or
GLUT_RIGHT_BUTTON.
State is GLUT_UP or GLUT_DOWN.
X and y are mouse position at the time of
the event.
Example Mouse Function (2)
The x value is the number of pixels from the
left of the window.
The y value is the number of pixels down from
the top of the window.
In order to see the effects of some activity of
the mouse or keyboard, the mouse or
keyboard handler must call either myDisplay()
or glutPostRedisplay().
Code for an example myMouse() is in Fig.
2.40.
Polyline Control with Mouse
Example use:
Code for Mousecontrolled Polyline
Using Mouse Motion Functions
glutMotionFunc(myMovedMouse); //
moved with button held down
glutPassiveMotionFunc(myMovedMouse
); // moved with buttons up
myMovedMouse(int x, int y); x and y are
the position of the mouse when the
event occurred.
Code for drawing rubber rectangles
using these functions is in Fig. 2.41.
Example Keyboard Function
void myKeyboard(unsigned char theKey, int mouseX, int mouseY)
{
GLint x = mouseX;
GLint y = screenHeight  mouseY; // flip y value switch(theKey)
{case „p‟: drawDot(x, y); break;
// draw dot at mouse position
case „E‟: exit(1); //terminate the program
default: break; // do nothing
}
}
Example Keyboard Function (2)
Parameters to the function will always be
(unsigned char key, int mouseX, int
mouseY).
The y coordinate needs to be flipped by
subtracting it from screenHeight.
Body is a switch with cases to handle
active keys (key value is ASCII code).
Remember to end each case with a
break!
Using Menus
Both GLUT and GLUI make menus
available.
GLUT menus are simple, and GLUI
menus are more powerful.
We will build a single menu that will
allow the user to change the color of a
triangle, which is undulating back and
forth as the application proceeds.
GLUT Menu Callback Function
Int glutCreateMenu(myMenu); returns menu ID
void myMenu(int num); //handles choice num
void glutAddMenuEntry(char* name, int value);
// value used in myMenu switch to handle
choice
void glutAttachMenu(int button); // one of
GLUT_RIGHT_BUTTON,
GLUT_MIDDLE_BUTTON, or
GLUT_LEFT_BUTTON
• Usually GLUT_RIGHT_BUTTON
GLUT subMenus
Create a subMenu first, using menu
commands, then add it to main menu.
• A submenu pops up when a main menu item is
selected.
glutAddSubMenu (char* name, int menuID); //
menuID is the value returned by
glutCreateMenu when the submenu was
created
Complete code for a GLUT Menu application is
in Fig. 2.44. (No submenus are used.)
GLUI Interfaces and Menus
GLUI Interfaces
An example program illustrating how to
use GLUI interface options is available
on book web site.
Most of the work has been done for you;
you may cut and paste from the example
programs in the GLUI distribution.
UNITIV
RENDERING
Polygon shading model
Flat shading  compute lighting once and
assign the color to the whole (mesh)
polygon
Flat shading
Only use one vertex normaland material
property to compute the color for the
polygon
Benefit: fast to compute
Used when:
• Polygon is small enough
• Light source is far away (why?)
• Eye is very far away (why?)
Mach Band Effect
Flat shading suffers from “mach band effect”
Mach band effect – human eyes accentuate the
discontinuity at the boundary
Side view of a polygonal surface
perceived intensity
Smooth shading
Fix the mach band effect – remove edge discontinuity
Compute lighting for more points on each face
Flat shading
Smooth shading
Smooth shading
Two popular methods:
• Gouraud shading (used by OpenGL)
• Phong shading (better specular highlight, not
in OpenGL)
Gouraud Shading
The smooth shading algorithm used in OpenGL
glShadeModel(GL_SMOOTH)
Lighting is calculated for each of the polygon vertices
Colors are interpolated for interior pixels
Gouraud Shading
Pervertex lighting calculation
Normal is needed for each vertex
Pervertex normal can be computed by
averaging the adjust face normals
n
n1
n2
n3
n4
n = (n1 + n2 + n3 + n4) / 4.0
Gouraud Shading
Compute vertex illumination (color)
before the projection transformation
Shade interior pixels: color interpolation
(normals are not needed)
C1
C2
C3
Ca = lerp(C1, C2) Cb = lerp(C1, C3)
Lerp(Ca, Cb)
for all scanlines
* lerp: linear interpolation
Gouraud Shading
Linear interpolation
Interpolate triangle color: use y distance to interpolate the two end
points in the scanline, and use x distance to interpolate interior
pixel colors
a
b
v1 v2
x
x = a / (a+b) * v1 + b/(a+b) * v2
Gouraud Shading Problem
Lighting in the polygon interior can be
inaccurate
Phong Shading
Instead of interpolation, we calculate lighting for each
pixel inside the polygon (per pixel lighting)
Need normals for all the pixels – not provided by user
Phong shading algorithm interpolates the normals
and compute lighting during rasterization (need to
map the normal back to world or eye space though)
Phong Shading
Normal interpolation
• Slow – not supported by OpenGL and
most graphics hardware
n1
n2
n3
nb = lerp(n1, n3)
na = lerp(n1, n2)
lerp(na, nb)
UNITV
FRACTALS
Fractals
Fractals are geometric objects.
Many realworld objects like ferns are
shaped like fractals.
Fractals are formed by iterations.
Fractals are selfsimilar.
In computer graphics, we use fractal
functions to create complex objects.
Koch Fractals (Snowflakes)
Iteration 0 Iteration 1 Iteration 2 Iteration 3
Generator
1/3 1/3
1/3
1/3
1
Fractal Tree
Iteration 1 Iteration 2 Iteration 3 Iteration 4 Iteration 5
Generator
Fractal Fern
Generator
Iteration 0 Iteration 1 Iteration 2 Iteration 3
Add Some Randomness
The fractals we‟ve produced so far seem to be
very regular and “artificial”.
To create some realism and variability, simply
change the angles slightly sometimes based
on a random number generator.
For example, you can curve some of the ferns
to one side.
For example, you can also vary the lengths of
the branches and the branching factor.
Terrain (Random Midpoint
Displacement)
Given the heights of two endpoints, generate
a height at the midpoint.
Suppose that the two endpoints are a and b.
Suppose the height is in the y direction, such
that the height at a is y(a), and the height at b
is y(b).
Then, the height at the midpoint will be:
y
mid
= (y(a)+y(b))/2 + r, where
• r is the random offset
This is how to generate the random offset r:
r = sr
g
ba, where
• s is a userselected “roughness” factor, and
• r
g
is a Gaussian random variable with mean 0 and
variance 1
How to generate a random number with Gaussian
(or normal) probability distribution
// given random numbers x1 and x2 with equal distribution from 1 to 1
// generate numbers y1 and y2 with normal distribution centered at 0.0
// and with standard deviation 1.0.
void Gaussian(float &y1, float &y2) {
float x1, x2, w;
do {
x1 = 2.0 * 0.001*(float)(rand()%1000)  1.0;
x2 = 2.0 * 0.001*(float)(rand()%1000)  1.0;
w = x1 * x1 + x2 * x2;
} while ( w >= 1.0 );
w = sqrt( (2.0 * log( w ) ) / w );
y1 = x1 * w;
y2 = x2 * w;
}
Procedural Terrain Example
Building a more realistic terrain
Notice that in the real world, valleys and
mountains have different shapes.
If we have the same terraingeneration
algorithm for both mountains and valleys, it will
result in unrealistic, alienlooking landscapes.
Therefore, use different parameters for valleys
and mountains.
Also, can manually create ridges, cliffs, and
other geographical features, and then use
fractals to create detail roughness.
Fractals
Infinite detail at every point
Self similarity between parts and overall features of the object
Zoom into Euclidian shape
• Zoomed shape see more detail
• eventually smooths
Zoom in on fractal
• See more detail
• Does not smooth
Model
• Terrain, clouds water, trees, plants, feathers, fur, patterns
General equation P1=F(P0), P2 = F(P1), P3=F(P2)…
• P3=F(F(F(P0)))
Self similar fractals
Parts are scaled down versions of the entire
object
• use same scaling on subparts
• use different scaling factors for subparts
Statistically selfsimilar
• Apply random variation to subparts
• Trees, shrubs, other vegetation
Fractal types
Statistically selfaffine
• random variations
• Sx<>Sy<>Sz
• terrain, water, clouds
Invariant fractal sets
• Nonlinear transformations
• Self squaring fractals
• JuliaFatou set
• Squaring function in complex space
• Mandelbrot set
• Squaring function in complex space
• Selfinverse fractals
• Inversion procedures
JuliaFatou and
Mandelbrot
x=>x
2
+c
• x=a+bi
• Complex number
Modulus
• Sqrt(a
2
+b
2
)
• If modulus < 1
• Squaring makes it go
toward 0
• If modulus > 1
• Squaring falls towards
infinity
If modulus=1
• Some fall to zero
• Some fall to infinity
• Some do neither
• Boundary between
numbers which fall to
zero and those which
fall to infinity
• JuliaFatou Set
Foley/vanDam Computer GraphicsPrinciples and
Practices, 2
nd
edition
JuliaFatou
Julia Fatou and
Mandelbrot con’d
Shape of the JuliaFatou set based on c
To get Mandelbrot set – set of nondiverging points
• Correct method
• Compute the Julia sets for all possible c
• Color the points black when the set is connected and white when it is
not connected
• Approximate method
• Foreach value of c, start with complex number 0=0+0i
• Apply to x=>x
2
+c
• Process a finite number of times (say 1000)
• If after the iterations is is outside a disk defined by modulus>100,
color the points of c white, otherwise color it black.
Foley/vanDam Computer GraphicsPrinciples and
Practices, 2
nd
edition
Constructing a deterministic
selfsimilar fractal
Initiator
• Given geometric shape
Generator
• Pattern which replaces subparts of initiator
Koch Curve
Initiator
generator
First iteration
Fractal dimension
D=fractal dimension
• Amount of variation in the structure
• Measure of roughness or fragmentation of the object
• Small dless jagged
• Large dmore jagged
Self similar objects
• ns
d
=1 (Some books write this as ns
d
=1)
• s=scaling factor
• n number of subparts in subdivision
• d=ln(n)/ln(1/s)
• [d=ln(n)/ln(s) however s is the number of segments versus how much
the main segment was reduced
• I.e. line divided into 3 segments. Instead of saying the line is 1/3,
say instead there are 3 sements. Notice that 1/(1/3) = 3]
• If there are different scaling factors
•
• S
k
d
=1
K=1
n
Figuring out scaling factors
I prefer: ns
d
=1 :d=ln(n)/ln(s)
Dimension is a ratio of
the (new size)/(old size)
• Divide line into n identical
segments
• n=s
• Divide lines on square
into small squares by
dividing each line into n
identical segments
• n=s
2
small squares
• Divide cube
• Get n=s
3
small cubes
Koch‟s snowflake
• After division have 4 segments
• n=4 (new segments)
• s=3 (old segments)
• Fractal Dimension
• D=ln4/ln3 = 1.262
• For your reference: Book method
• n=4
• Number of new segments
• s=1/3
• segments reduced by 1/3
• d=ln4/ln(1/(1/3))
Sierpinski gasket Fractal
Dimension
Divide each side by 2
• Makes 4 triangles
• We keep 3
• Therefore n=3
• Get 3 new triangles from 1 old
triangle
• s=2 (2 new segments from one
old segment)
Fractal dimension
• D=ln(3)/ln(2) = 1.585
Cube Fractal Dimension
Apply fractal algorithm
• Divide each side by 3
• Now push out the middle face of each cube
• Now push out the center of the cube
What is the fractal dimension?
• Well we have 20 cubes, where we used to have 1
• n=20
• We have divided each side by 3
• s=3
• Fractal dimension ln(20)/ln(3) = 2.727
Image from
Angel book
Language Based Models of
generating images
Typical Alphabet {A,B,[,]}
Rules
• A=> AA
• B=> A[B]AA[B]
Starting Basis=B
Generate words
• Represents sequence of
segments in graph
structure
• Branch with brackets
• Interesting, but I want a
tree
B
A[B]AA[B]
AA[A[B]AA[B]]AAAA[A[B]AA[B]]
A
A
A
B
B
A
A
A
B
AA
B
A
A
A
A
A
B
AA
B
Language Based Models of
generating images con’d
Modify Alphabet
{A,B,[,],(,)}
Rules
• A=> AA
• B=> A[B]AA(B)
• [] = left branch () = right
branchStarting Basis=B
Generate words
• Represents sequence of
segments in graph
structure
• Branch with brackets
B
A[B]AA(B)
AA[A[B]AA(B)]AAAA(A[B]AA(B))
A
A
A
B
B
A
A
A
B
AA
B
A
A
A
A
A
B
AA
B
Language Based models have no
inherent geometry
Grammar based model requires
• Grammar
• Geometric interpretation
Generating an object from the word
is a separate process
• examples
• Branches on the tree drawn
at upward angles
• Choose to draw segments
of tree as successively
smaller lengths
• The more it branches,
the smaller the last
branch is
• Draw flowers or leaves at
terminal nodes
A
A
A
B
AA
B
A
A
A
A
A
B
AA
B
Grammar and Geometry
Change branch size according to depth of
graph
Foley/vanDam Computer GraphicsPrinciples and
Practices, 2
nd
edition
Particle Systems
System is defined by a collection of particles that evolve over time
• Particles have fluidlike properties
• Flowing, billowing, spattering, expanding, imploding, exploding
• Basic particle can be any shape
• Sphere, box, ellipsoid, etc
• Apply probabilistic rules to particles
• generate new particles
• Change attributes according to age
• What color is particle when detected?
• What shape is particle when detected?
• Transparancy over time?
• Particles die (disappear from system)
• Movement
• Deterministic or stochastic laws of motion
• Kinematically
• forces such as gravity
Particle Systems modeling
Model
• Fire, fog, smoke, fireworks, trees, grass, waterfall, water spray.
Grass
• Model clumps by setting up trajectory paths for particles
Waterfall
• Particles fall from fixed elevation
• Deflected by obstacle as splash to ground
• Eg. drop, hit rock, finish in pool
• Drop, go to bottom of pool, float back up.
Physically based modeling
Nonrigid object
• Rope, cloth, soft rubber ball, jello
Describe behavior in terms of external and internal forces
• Approximate the object with network of point nodes
connected by flexible connection
• Example springs with spring constant k
• Homogeneous object
• All k’s equal
Hooke’s Law
• F
s
=k x
• x=displacement, F
s
= restoring force on spring
Could also model with putty (doesn’t spring back)
Could model with elastic material
• Minimize strain energy
k
k
k
k
“Turtle Graphics”
Turtle can
• F=Move forward a unit
• L=Turn left
• R=Turn right
Stipulate turtle directions, and
angle of turns
Equilateral triangle
• Eg. angle =120
• FRFRFR
What if change angle to 60
degrees
• F=> FLFRRFLF
• Basis F
• Koch Curve (snowflake)
• Example taken from Angel
book
Using turtle
graphics for trees
Use push and pop for side
branches []
F=> F[RF]F[LF]F
Angle =27
Note spaces ONLY for
readability
F[RF]F[LF]F [RF[RF]F[LF]F]
F[RF]F[LF]F [LF[RF]F[LF]F]
F[RF]F[LF]F
Line and Curve Drawing Algorithms
Line Drawing
y=m.x+b
yend y0 x0
m = (yend – y0) / (xend – x0) b = y0 – m . x0
xend
DDA Algorithm
yend y0 x0
xend
if m<1 xk+1 = xk + 1 yk+1 = yk + m
if m>1 yk+1 = yk + 1 xk+1 = xk + 1/m
yend
y0 x0 xend
DDA Algorithm
#include <stdlib.h> #include <math.h> inline int round (const float a) { return int (a + 0.5); }
void lineDDA (int x0, int y0, int xEnd, int yEnd) { int dx = xEnd  x0, dy = yEnd  y0, steps, k; float xIncrement, yIncrement, x = x0, y = y0; if (fabs (dx) > fabs (dy)) steps = fabs (dx); /* m<1 */ else steps = fabs (dy); /* m>=1 */ xIncrement = float (dx) / float (steps); yIncrement = float (dy) / float (steps);
setPixel (round (x), round (y)); for (k = 0; k < steps; k++) { x += xIncrement; y += yIncrement; setPixel (round (x), round (y)); }
}
Bresenham’s Line Algorithm
yk+1 yk
xk xk+1
yk+1 y yk xk xk+1
du dl
twoDyMinusDx = 2 * (dy . while (x < xEnd) { x++. y = yEnd. int p = 2 * dy . xEnd = x0.0 */ void lineBres (int x0. int yEnd) { int dx = fabs(xEnd . } else { x = x0.dx). int xEnd. p += twoDyMinusDx. */ if (x0 > xEnd) { x = xEnd.y0).dx. y. int y0. } setPixel (x.h> #include <math.x0). dy = fabs(yEnd . } }
. int twoDy = 2 * dy. } setPixel (x. int x. else { y++. y).h> /* Bresenham linedrawing procedure for m<1. /* Determine which endpoint to use as start position.Bresenham’s Line Algorithm
#include <stdlib. y = y0. y). if (p < 0) p += twoDy.
Circle Drawing
r yc xc (x. y)
Pythagorean Theorem: x2 + y2 = r2 (xxc)2 + (yyc)2 = r2
(xcr) ≤ x ≤ (xc+r) y = yc ± √r2 .(xxc)2
.
Circle Drawing
change x change y
.
Circle Drawing using polar coordinates
r (x. yc)
x = xc + r . y) θ
(xc. cos θ y = yc + r . sin θ change θ with step size 1/r
.
y) 450
use symmetry if θ>450
(xc. yc)
. sin θ change θ with step size 1/r
(y. yc)
x = xc + r .Circle Drawing using polar coordinates
r (x. y) θ
(xc. y)
(y. cos θ y = yc + r . x) (x. x) (x.
Midpoint Circle Algorithm
f(x.y) is outside circle
xk
xk+1
use symmetry if x>y
.y) is on the circle <0 if (x.y) = x2 + y2 .y) is inside circle f(x.y) =0 if (x.r2
yk
yk1/2
yk1
<0 if (x.
y. { setPixel (circCtr.y). /* Plot the initial point in each circle quadrant. setPixel (circCtr.x .x + circPt. setPixel (circCtr. circPt).h> class scrPt { public: GLint x. GLint p = 1 .x). circPt).y + circPt.y + circPt.x + circPt. glVertex2i (x. circCtr. circCtr.y. glEnd ( ).circPt.x). */ while (circPt. */ circlePlotPoints (circCtr.y.y . setPixel (circCtr. circCtr. else { circPt. GLint y) { glBegin (GL_POINTS). /* Calculate next points and plot in each octant.y .y) + 1.circPt.x = 0. setPixel (circCtr. if (p < 0) p += 2 * circPt. GLint radius) { scrPt circPt.x++.x + circPt.x.y. } circlePlotPoints (circCtr.x .y . circCtr. circCtr. p += 2 * (circPt.radius.circPt.x).y .x < circPt.y.y). scrPt).circPt.circPt. } } void circlePlotPoints (scrPt circCtr. circCtr. y. void circlePlotPoints (scrPt. void setPixel (GLint x.x.Midpoint Circle Algorithm
#include <GL/glut.circPt. circPt. setPixel (circCtr.x. circPt. setPixel (circCtr.circPt. setPixel (circCtr.x + circPt.x.y + circPt. circCtr.y).y).x .x).circPt.y = radius.x + 1. }
.circPt.y) { circPt. scrPt circPt).x . } void circleMidpoint (scrPt circCtr. y).x . circCtr.y + circPt. }.
// Process all OpenGL routines as quickly as possible. // Set projection parameters. glVertex2i (10. // Set display mode. glutInitWindowSize (400. } void lineSegment (void) { glClear (GL_COLOR_BUFFER_BIT). char** argv) { glutInit (&argc.0. argv). 1. 0. init ( ). 1. } // Execute initialization procedure. glBegin (GL_LINES).0. glEnd ( ). // Specify linesegment geometry. glColor3f (0. // Set line segment color to red. glVertex2i (180. 100). glutCreateWindow ("An Example OpenGL Program").
.0). // Set displaywindow color to white. 145).h> // (or others. // Set topleft displaywindow position. glFlush ( ). 300).0. glutInitDisplayMode (GLUT_SINGLE  GLUT_RGB). glutInitWindowPosition (50. // Create display window.0.0. 0. } void main (int argc. 1. // Send graphics to display window.0). // Initialize GLUT.0.0. 200.0. 150. glutDisplayFunc (lineSegment). glMatrixMode (GL_PROJECTION).
// Clear display window. gluOrtho2D (0. 0. // Set displaywindow width and height. glutMainLoop ( ). 15). // Display everything and wait.OpenGL
#include <GL/glut.0). depending on the system in use) void init (void) { glClearColor (1.
int p1[ ]={50.
* : 2. 4 i (integer) s (short) f (float) d (double)
Ex:
glBegin(GL_POINTS). 100}. glEnd(). glVertex2i(50. glBegin(GL_POINTS). glEnd().OpenGL
Point Functions
• glVertex*( ). 100). glVertex2iv(p1).
. 3.
. glVertex2iv(p1). glEnd().OpenGL
Line Functions
• • •
GL_LINES GL_LINE_STRIP GL_LINE_LOOP
Ex: glBegin(GL_LINES). glVertex2iv(p2).
glVertex2iv(p2). glEnd().OpenGL
glBegin(GL_LINES). glVertex2iv(p4). GL_LINES
p3 p1 p5
GL_LINE_STRIP
p3 p1
p2
p4
p2
p4
GL_LINE_LOOP
p3 p5 p1
p2
p4
. glVertex2iv(p3). glVertex2iv(p5). glVertex2iv(p1).
.Antialiasing
Supersampling
Count the number of subpixels that overlap the line path. Set the intensity proportional to this count.
80%
25%
. Set intensity proportional to the overlap areas. Calculate the overlap areas for pixels.Antialiasing
Area Sampling
Line is treated as a rectangle.
.Antialiasing
Pixel Sampling
Micropositioning Electron beam is shifted 1/2. 1/4. 3/4 of a pixel diameter.
Line Intensity differences
Change the line drawing algorithm:
For horizontal and vertical lines use the lowest intensity For 45o lines use the highest intensity
.
2D Transformations with Matrices
.
Note that we start indexing at 1.
A general matrix will be represented by an uppercase italicised letter.1
a1.1 A a2 . 2 a3.Matrices
a1. 3 a2 .j.1 a3. The element on the ith row and jth column is denoted by ai. whereas C indexes arrays from 0. 2
a1.
.3 a3 . 2 a2 . 3
A matrix is a rectangular array of numbers.
The addition produces a result. j Ai . with elements: Ci .Matrices – Addition
Given two matrices A and B if we want to add B to A (that is form A+B) then if A is (nm). C = A+B. A+B is not defined. B must be (nm). j Bi . j
1 2 5 6 1 5 2 6 6 8 3 4 7 8 3 7 4 8 10 12
. Otherwise.
C = AB. i. the number of columns in A must be equal to the number of rows in B. j aik bkj
k 1 m
(Basically we multiply the first row of A with the first column of B and put this in the c1. AB is not defined.e.1 element of C.
. Otherwise. with elements:
Ci .Matrices – Multiplication
Given two matrices A and B if we want to multiply B by A (that is form AB) then if A is (nm).
The multiplication produces a result. And so on…).. B must be (mp).
Matrices – Multiplication (Examples)
26+ 63+ 72=44
2 6 7 6 8 44 76 4 5 8 3 3 55 95 9 2 3 2 6 66 96 6 8 2 6 3 3 4 5 2 6
Undefined! 2x2 x 3x2 2!=3
2x2 x 2x4 x 4x4 is allowed. Result is 2x4 matrix
.
3 a1.3 A' a1.1 A a2. 2 a1.3
.1 a1. 2 a2 .1 a1. 2 a2 . AB ≠ BA
Matrix multiplication distributes over addition: A(B+C) = AB + AC Identity matrix for multiplication is defined as I.1 a2 . 2 a2 .Basics
Unlike scalar multiplication. is either denoted AT or A‟ is obtained by swapping the rows and columns of A:
a1. The transpose of a matrix.3 a2.Matrices . A.
2D Geometrical Transformations
Translate
Shear
Rotate
Scale
.
Translate Points
Recall. d y
. y) to be moved by dx units parallel to the x axis and by dy units parallel to the y axis. We can translate points in the (x.y)
x' x d x y ' y d y
d x If we define the translation matrix T .. y’ ). to the new point P’(x’. The translation has x' x d x the following form:
P’(x’. then we have P’ =P + T. For each point P(x. y) plane to new positions by adding translation amounts to the coordinates of the points.y’)
dy dx
y' y d y
In matrix format:
P(x.
to half the size of x' s x x an obejct we use a scale factor of 0.Scale Points
Points can be scaled (stretched) by sx along the x axis and by sy along the y axis into the new points by the multiplications:
We can specify how much bigger or smaller by means of a “scale factor” To double the size of an object we use a scale factor of 2.y) P’(x’.y’)
x
y' s y y
x' s x y ' 0
0 . then we have P’ =SP sy
0 x sy y
sx If we define S 0
.5
y sy y sx x
P(x.
)
Points can be rotated through an angle about the origin:
 OP'  OP  l
y
P’(x’.y’)
y’
x'  OP'  cos( ) l cos( ) l cos cos l sin sin x cos y sin y '  OP'  sin( ) l sin( ) l cos sin l sin cos x sin y cos
l
x’ x
P(x.y)
O
x' cos y' sin
sin x cos y
P’ =RP
.Rotate Points (cont.
Review…
Translate: Scale: Rotate:
P‟ = P+T P‟ = SP P‟ = RP
Spot the odd one out…
• •
Multiplying versus adding matrix… Ideally.
• easier to code
Solution: Homogeneous Coordinates
. all transformations would be the same..
W] and [x’. y’. 3. y. 1]
. a homogeneous coordinates for a 2D point has the form: [x.Homogeneous Coordinates
For a given 2D coordinates (x. we introduce a third dimension:
[x. W] Two homogeneous coordinates [x. y. 6. 6] = [4. W’] are said to be of the same (or equivalent) if x = kx’ y = ky’ W = kW’ for some k ≠ 0 eg: [2. y/W. 1]
In general. y. y). W] can be normalised by dividing each element by W: [x/W. 12] where k=2
Therefore any [x. y.
Homogeneous Transformations
Now. we have: Scaling
x' s x y ' 0 1 0
P’ =
Rotation
0 sy 0
S
0 x 0 y 1 1
P
x' cos y ' sin 1 0
P’ =
sin cos 0
R
0 x 0 y 1 1
P
. redefine the translation by using homogeneous coordinates: x' 1 0 d x x dx x' x y ' 0 1 d y y y ' y d y 1 0 0 1 1
P' T P
Similarly.
dy2) first. d y1 ) P] . we can define T21= T(dx1.Composition of 2D Transformations
1. d y 2 )[T (d x1 . '' T
On the other hand. then apply T21 to P: P' ' T21P
T21 T (d x 2 . d y 2 )T (d x1 . dy1) and then to P’’ by another T(dx2Pdy2) (d x 2 . dy1) T(dx2. d y1 )
where
1 0 d x 2 1 0 d x1 0 1 d y 2 0 1 d y1 0 0 1 0 0 1
1 0 d x1 d x 2 0 1 d y1 d y 2 0 0 1
. d y 2 ) P' T (d x 2 . Additivity of successive translations
We want to translate a point P to P’ by T(dx1.
2)
1 0 1 1 0 1 T21 0 1 1 0 1 2 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1
.3)
T(1.2) (2.1)
(2.Examples of Composite 2D Transformations
T(1.1)
(1.
s y1 ) sx 2 0 0 0 sy2 0 0 s x1 0 0 1 0 0 s y 2 * s y1 0 0 s y1 0 0 0 1 0 0 1
s x 2 * s x1 0 0
. s y1 )]P S 21 P
where
S 21 S ( s x 2 .Composition of 2D Transformations (cont. s y 2 )[S ( s x1 . s y1 ) P ] [ S ( s x 2 .)
2. Multiplicativity of successive scalings
P ' ' S ( s x 2 . s y 2 ) S ( s x1 . s y 2 ) S ( s x1 .
)
3. Additivity of successive rotations
P' ' R( 2 )[R(1 ) P] [ R( 2 ) R(1 )]P R21 P
where
R21 R ( 2 ) R (1 ) cos 2 sin 2 0 sin 2 cos 2 0 0 cos1 0 sin 1 1 0 sin 1 cos1 0 0 0 1 0 0 1
cos( 2 1 ) sin( 2 1 ) 0
sin( 2 1 ) cos( 2 1 ) 0
.Composition of 2D Transformations (cont.
d y )
where
. P' R( )[T (d x .Composition of 2D Transformations (cont. d y ) P]
[ R( )T (d x . d y )]P MP
M R ( )T ( d x . Different types of elementary transformations discussed above can be concatenated as well.)
4.
say by degrees counter clockwise.3) P1(1.Consider the following two questions: 1) translate a line segment P1 P2.
P2(3. say.
P2(3. Rotate a line segment P1 P2. by 1 units in the x direction and 2 units in the y direction.3) P1(1.2) P’1 P’2
2).2) P’1 P’2
.
about P1.
P2(3. then join them. Rotate. three steps are needed: 1).2) P1(1.1) R() P2 T(1. Translate such that the point at the origin returns to P1. 3).3) T(1. Translate such that P1 is at the origin. For example.
2).
Scale or Rotate Lines: More complex.2) P1 P2(2. consider to rotate an arbitrary line about a point P1.2) P2 P1
P1
.Other Than Point Transformations…
Translate Lines:
translate both endpoints.
Another Example.
Translate
Translate
Rotate Scale
.
in general. the order for composition of 2D geometrical transformations matters. Translation + Translation 2). However. s y )
M 1 S ( s x . in the following four cases. matrix multiplication is not commutative. it is easy to show that. commutativity holds: 1). Scaling (with sx = sy) + Rotation just to verify case 4:
M 2 R ( ) S ( s x .Order Matters!
As we said. M = M0. Rotation + Rotation 4). 1 =
x y 1 2
sin 0 s x c os sin c os 0 0 0 0 1 0 0 0 s y * sin s * c os 1 x s * sin s y * c os x 0 0
0 sy 0 0 0 1
0 0 1
. s y ) R ( ) 0 0 c os sin sx 0 sin sy 0 c os 0 0 1 0 0 s x * sin 0 s x * c os s * sin y s y * c os 0 if s 0 s . Scaling + Scaling 3). because.
The product of an arbitrary sequence of rotation. Affine Transformations
A transformation matrix of the form
r11 r 21 0 r12 r22 0 tx ty 1
where the upper 22 submatrix is orthogonal. and scale matrices will cause an affine transformation. translations. but not of lengths and angles. preserves angles and lengths.
.RigidBody vs. because the body or object being transformed is not distorted in any way. which have the property of preserving parallelism of lines. An arbitrary sequence of rotation and translation matrices creates a matrix of this form. Such transforms are called rigidbody transformations.
)
Rigid. not in y
Shear transformation is also affine.body Transformation
Affine Transformation
Unit cube
45º
Scale in x.RigidBody vs.
Shear in the x direction
Shear in the y direction
1 SH x 0 0
a 1 0
0 0 1
1 SH y b 0
0 1 0
0 0 1
. Affine Transformations (cont.
2D Output Primitives
Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers
.
Filling area
Polygons are considered!
1)
2)
ScanLine Filling (between edges) Interactive Filling (using an interior starting point)
.
which are the pixels to be included in the area filling?
.1) ScanLine Filling (scan conversion)
Problem: Given the vertices or edges of a polygon.
cont’d
Main idea: locate the intersections between the scanlines and the edges of the polygon sort the intersection points on each scanline on increasing xcoordinates generate framebuffer positions along the current scanline between pairwise intersection points
.ScanLine filling.
Main idea
.
ScanLine filling. cont’d
Problems with intersection points that are vertices: Basic rule: count them as if each vertex is being two points (one to each of the two joining edges in the vertex) Exception: if the two edges joining in the vertex are on opposite sides of the scanline. then count the vertex only once (require some additional processing)
.
Vertex problem
.
cont’d
Timeconsuming to locate the intersection points! If an edge is crossed by a scanline.ScanLine filling. most probably also the next scanline will cross it (the use of coherence properties)
.
ScanLine filling, cont’d
Each edge is well described by an edgerecord: ymax x0 (initially the x related to ymin) x/y (inverse of the slope) (possibly also x and y) x/y is used for incremental calculations of the intersection points
Edge Records
ScanLine filling, cont’d
The intersection point (xn,yn) between an edge and scanline yn follows from the line equation of the edge: yn = y/x . xn + b (cp. y = m.x + b) The intersection between the same edge and the next scanline yn+1 is then given from the following: yn+1 = y/x . xn+1 + b and also yn+1 = yn + 1 = y/x . xn + b +1
ScanLine filling, cont’d
This gives us:
xn+1 = xn + x/y , n = 0, 1, 2, ….. i.e. the new value of x on the next scanline is given by adding the inverse of the slope to the current value of x
ScanLine filling, cont’d
An active list of edge records intersecting with the current scanline is sorted on increasing xcoordinates The polygon pixels that are written in the frame buffer are those which are calculated to be on the current scanline between pairwise xcoordinates according to the active list
ScanLine filling, cont’d
When changing from one scanline to the next, the active edge list is updated: a record with ymax < ”the next scanline” is removed in the remaining records, x0 is incremented and rounded to the nearest integer an edge with ymin = ”the next scanline” is included in the list
ScanLine Filling Example
.
.2) Interactive Filling
Given the boundaries of a closed surface. the complete interior of the surface will be filled with the color of the user‟s choice. By choosing an arbitrary interior point.
if it is also allowed to take diagonal steps. Furthermore. the surface or the boundary is said to be 8connected.
.Interactive Filling. cont’d
Definition: An area or a boundary is said to be 4connected if from an arbitrary point all other pixels within the area or on the boundary can be reached by only moving in horizontal or vertical steps.
4/8connected
.
. Assume that the surface shall have the same color as the boundary (can easily be modified!).Interactive Filling. The first interior position (pixel) is choosen by the user. cont’d
A recursive procedure for filling a 4connected (8connected) surface can easily be defined.
y. fill(x + 1.1.y). fill(x. } }
.1. y. fillColor). if (interiorColor != fillColor) { setPixel(x. interiorColor = getPixel(x. algorithm
void fill(int x. int y. y . int fillColor) { int interiorColor. fillColor). fill(x. y + 1. fillColor). y.Interactive Filling. fill(x . fillColor). fillColor).
count the number of polygon edges that are crossed if odd => interior if even => exterior Note! The vertices!
.InsideOutside test
When is a point an interior point? OddEven Rule Draw conceptually a line from a specified point to a distant point outside the coordinate space.
less good for styles/sizes * outlined (lines and
curves)
+ less storage + good for styles/sizes .Text
Representation: * bitmapped (raster)
+ fast .more storage .slower
.
an n x m rectangular color pixel array with a specified reference point * polymarker (marker symbol) a character representing a point * (polyline) a connected sequence of line segments
.Other output primitives
* pattern (to fill an area) normally.
g setColor(color). color)
2)
a list of current attributes (to be updated when changed) e. y. y). setPixel(x.Attributes
Influence the way a primitive is displayed Two main ways of introducing attributes: 1) added to primitive‟s parameter list
e. setPixel(x.
.g.
11100110011 problem with the joins.Attributes for lines
Lines (and curves) are normally infinitely thin type
• • •
dashed. line caps are used to adjust shape
width
pen/brush shape color (intensity)
. e. solid. dotted. dotdashed.g. … pixel mask.
Lines with width
Line caps
Joins
.
hatch fill.Attributes for area fill
fill style
color pattern
• hollow. pattern. solid. … • tiling
.
Tiling
Tiling = filling surfaces (polygons) with a rectangular pattern
.
Attributes for characters/strings
style font (typeface) color size (width/height) orientation path spacing alignment
.
Text attributes
.
cont’d
.Text attributes.
cont’d
.Text attributes.
Text attributes. cont’d
.
based on some color model.Color as attribute
Each color has a numerical value. A color model typically consists of three primary colors. or intensity. Green and Blue (RGB) For each primary color an intensity can be given. either 0255 (integer) or 01 (float) yielding the final color 256 different levels of each primary color means 3x8=24 bits of information to store
. in the case of displays Red.
Color representations
Two different ways of storing a color value: 1) a direct color value storage/pixel 2) indirectly via a color lookup table index/pixel (typically 256 or 512 different colors in the table)
.
Color Lookup Table
.
Antialiasing
Aliasing ≈ the fact that exact points are approximated by fixed pixel positions Antialiasing = a technique that compensates for this (more than one intensity level/pixel is required)
.
will be given an intensity that is proportional to the extent of the pixel area that is covered by the true polygon
.Antialiasing.
Area sampling (prefiltering): a pixel that is only partly included in the exact polygon. a method
A polygon will be studied (as an example).
Area sampling
P = polygon intensity B = background intensity f = the extent of the pixel area covered by the true polygon pixel intensity = P*f + B*(1 .f) Note! Time consuming to calculate f
.
Topics
Clipping CohenSutherland Line Clipping Algorithm
.
• BUT. as a CS major. you should know how it
.Clipping
Why clipping?
• Not everything defined in the world
coordinates is inside the world window
Where does clipping take place?
Model Clipping Viewport Transformation …
OpenGL does it for you
is done.
window p1. window) • Input parameters: p1. otherwise • Output parameters: p1. p2. p2.Line Clipping
int clipSegment(p1. p2 p1 and/or p2‟s value might be changed so that both p1 and p2 are inside the window
. p2: 2D endpoints that define a line window: aligned rectangle • Returned value: 1. if part of the line is inside the window 0.
Line Clipping
Example
• Line
AB BC CD DE EA
o P4
o P3 o P2
o P1
RetVal Output
o P4
o P1
o P3 o P2
.
CohenSutherland Line Clipping Algorithm
Trivial accept and trivial reject
window trivial reject
• If both endpoints within window trivial accept • If both endpoints outside of same boundary of • Clip against each edge in turn
Throw away “clipped off” part of line each time
Otherwise
How can we do it efficiently (elegantly)?
.
CohenSutherland Line Clipping Algorithm
Examples:
L4
window
• trivial accept? • trivial reject?
L1
L2
L3 L5
L6
.
CohenSutherland Line Clipping Algorithm
Use “region outcode”
.
right) outcode[4] (y < Window.top) outcode[3] (x > Window.CohenSutherland Line Clipping Algorithm
outcode[1] (x < Window.bottom)
.left) outcode[2] (y > Window.
CohenSutherland Line Clipping Algorithm
Both outcodes are FFFF
• Trivial accept
Logical AND of two outcodes FFFF
• Trivial reject
Logical AND of two outcodes = FFFF
• Can‟t tell • Clip against each edge in turn
Throw away “clipped off” part of line each time
.
CohenSutherland Line Clipping Algorithm
Examples:
L4
window
• outcodes? • trivial accept? • trivial reject?
L1
L2
L3 L5
L6
.
. p2) if(p1 is to the left) chop against the left else if(p1 is to the right) chop against the right else if(p1 is below) chop against the bottom else if(p1 is above) chop against the top while(1).CohenSutherland Line Clipping Algorithm
int clipSegment(Point2& p1. else if(trivial reject) return 0. RealRect W) do if(trivial accept) return 1. Point2& p2. else if(p1 is inside) swap(p1.
CohenSutherland Line Clipping Algorithm
A segment that requires 4 clips
.
A.x.y)=?
. (A.CohenSutherland Line Clipping Algorithm
How do we chop against each boundary? Given P1 (outside) and P2.
y .y .y e = p1.x dy = p1.r .r .w.y = (dy/dx)(p1.x = w.w.w.x)
p1.y += (dy/dx)(w.(dy/dx)(p1.r d/dy = e/dx
p1.y + (dy/dx)(w.y .r) A.p2.r d = p1.x .y .CohenSutherland Line Clipping Algorithm
Let dx = p1.y = p1.y A.p1.r)
= p1.p2.p1.r
.x) As A is the new P1
Q: Will we have dividedbyzero problem?
p1.x .x = w.A.A.x .x .
UNITII
THREEDIMENSIONAL CONCEPTS
.
3D
VIEWING
.
3D Viewingcontents
• Viewing pipeline • Viewing coordinates • Projections • View volumes and general projection
transformations • clipping
.
)
.3D Viewing
World coordinate system(where the objects are modeled and defined) Viewing coordinate system(viewing objects with respect to another user defined coordinate system) Scene coordinate system(a viewing coordinate system chosen to be at the centre of a scene) Object coordinate system(a coordinate system specific to an object.
3D viewing
Simple camera analogy is adopted
.
3D viewingpipeline
.
3D viewing
Defining the viewing coordinate system and specifying the view plane
.
3D viewing
steps to establish a Viewing coordinate system or view reference coordinate system and the view plane
First pick up a world coordinate position called the view reference point. This is the origin of the VC system Pick up the +ve direction for the Zv axis and the orientation of the view plane by specifying the view plane normal vector „N‟. Choose a world coordinate position and this point establishes the direction for N relative to either the world or VC origin. The view plane normal vector is the directed line segment.
.
at point.
.3D viewing
steps to establish a Viewing coordinate system or view reference coordinate system and the view plane
Some packages allow us to choose a look at point relative to the view reference point. Or set up a Left handed viewing system and take the N and the +ve Zv axis from the viewing origin to the look.
It can be specified as a twist angle about Zv axis.V U can be specified. Using N. Generally graphics packages allow users to choose a position of the view plane along the Zv axis by specifying the view plane distance from the viewing origin.
.3D viewing
steps to establish a Viewing coordinate system or view reference coordinate system and the view plane
We now choose the view up vector V. The view plane is always parallel to the XvYv plane.
3D viewing
To obtain a series of views of a scene we can keep the view reference point fixed and change the direction of N or we can fix N direction and move the view reference point around the scene.
.
vc=RzRyRx.T
zw
(a) Invert Viewing z Axis
zw
(b) Translate Viewing Origin to World Origin
yw
yw
yw
xv yv zw zv
xw
yv xv zv zw
(d) Rotate About the World y Axis to Align the Two z Axes
yv
xw
zv zw
xv
xw
(c) Rotate About World x Axis to Bring Viewing z Axis into the xz Plane of the World System
(e) Rotate About the World z Axis to Align the Two Viewing Systems
.Transformation from world to viewing coordinate system
3D viewing
yw
yw
xv
yv zv
xw
xv
yv zv
xw
Mwc.
What Are Projections?
Our 3D scenes are all specified in 3D world coordinates To display these we need to generate a 2D image .project objects onto a picture plane
Picture Plane
Objects in World Space
.
Converting From 3D To 2D
Projection is just one part of the process of converting from 3D world coordinates to a 2D image
3D world coordinate output primitives
Clip against view volume
Project onto projection plane
Transform to 2D device coordinates
2D device coordinates
.
Types Of Projections
There are two broad classes of projection:
Parallel: Typically used for architectural and engineering drawings Perspective: Realistic looking and used in computer graphics
Parallel Projection
Perspective Projection
.
Taxonomy Of Projections
.
Types Of Projections
There are two broad classes of projection: • Parallel:
preserves relative proportions of objects accurate views of various sides of an object can be obtained does not give realistic representations of the appearance of a 3D objective. Perspective: produce realistic views but does not preserve relative proportions projections of distant objects are smaller than the projections of objects of the same size that are closer to the projection plane.
•
.
Parallel Projections
Some examples of parallel projections
Orthographic oblique
Orthographic Projection(axonometric)
.
Parallel Projections
Some examples of parallel projections
The projection plane is aligned so that it intersects each coordinate axes in which the object is defined (principal axes) at the same distance from the origin. All the principal axes are foreshortened equally.
Isometric projection for a cube
.
Parallel Projections
Transformation equations for an orthographic parallel projections is simple Any point (x,y,z) in viewing coordinates is transformed to projection coordinates as Xp=X Yp=Y
Parallel Projections
Oblique projections
Transformation equations for oblique projections is as below.
x p 1 y p 0 z p 0 w p 0
0 1 0 0
L1 cos L1 sin 0 0
0 x 0 y 0 z 1 1
Parallel Projections
x p 1 y p 0 z p 0 w p 0 0 L1 cos 1 0 0 L1 sin 0 0 0 x 0 y 0 z 1 1
Oblique projections
Transformation equations for oblique projections is as below. An orthographic projection is obtained when L1=0. In fact the effect of the projection matrix is to shear planes of constant Z and project them on to the view plane.
•Two common oblique parallel projections:
–Cavalier and Cabinet
Parallel Projections
•2 common oblique parallel projections: Cavalier projection tan 1 45
Oblique projections
Cabinet projection tan 2 63.4
All lines perpendicular to the projection plane are projected with no change in length.
They are more realistic than cavaliar
Lines perpendicular to the viewing surface are projected at onehalf their length.
Perspective Projections
visual effect is similar to human visual system... has 'perspective foreshortening„ size of object varies inversely with distance from the center of projection. angles only remain intact for faces parallel to projection plane.
Perspective Projections
Where u varies from o to 1
Perspective Projections
.
Perspective Projections
If the PRP is selected at the viewing cooridinate origin then Zprp=0
The projection coordinates become Xp=X(Zvp/Z) If the view plane is the UV plane itself then Zvp=0. The projection coordinates become Yp=Y(Zvp/Z)
Xp=X(Zprp/(ZprpZ))=X(1/(1Z/Zprp))
Yp=Y(Zprp/(ZprpZ))=Y(1/(1Z/Zprp))
.
Perspective Projections
There are a number of different kinds of perspective views The most common are onepoint and two point perspectives
Coordinate description
Onepoint perspective projection
Twopoint perspective projection
.
corresponding to the number of axes cut by the projection plane.Perspective Projections
Parallel lines that are parallel to the view plane are projected as parallel lines.
. The point at which a set of projected parallel lines appear to converge is called a vanishing point. There are at most 3 such points. the vanishing point is called an principal vanishing point.
If a set of lines are parallel to one of the three principle axes.
View volume
.
. Both near and far planes must be on the same side of the reference point.View volume
Perspective projection Parallel projection The size of the view volume depends on the size of the window but the shape depends on the type of projection to be used.
View volume
Often the view plane is positioned at the view reference point or on the front clipping plane while generating parallel projection. Perspective effects depend on the positioning of the projection reference point relative to the view plane
.
View volume .PHIGS
View Plane Front Clipping Plane
VPN
VRP
Back Clipping Plane
Direction of Propagation
B F
View Plane Back Clipping Plane
Front Clipping Plane
View Plane
Back Clipping Plane Direction of Propagation
Front Clipping Plane
VPN
VRP
VPN
VRP
F
B
F
B
.
. We set the field of view by adjusting the size of the window relative to the distance of the view plane from the PRP.View volume
In an animation sequence. we can place the projection reference point at the viewing coordinate origin and put the view plane in front of the scene. We move through the scene by moving the viewing reference frame and the PRP will move with the view reference point.
General parallel projection transformation Parallel
Far Plane Near Plane View Volume
N
Direction of Projection
Window (a) Original Orientation
Far Plane Near Plane
View Volume
N
Direction of Projection Window
(b) After Shearing
.
c) be the projection vector in viewing coordinates.Vp Shearing
: (a. b. c)
Where Mparallel is
For an orthographic parallel projection Mparallel becomes the identity matrix since a1=b1=0
1 0 0 0
0 a 0 0 b 0 0 1 0 c c 0 0 1 0 0 a a c a1 0 a1 c b b c b1 0 b1 c 0 a1 1 b1
.0.General parallel projection transformation Parallel
Let Vp=(a. The shear transformation can be expressed as V‟p=Mparallel.b. c) : (0.
General perspective projection transformation Regularization of Clipping
(View) Volume
Far
View Volume Near
N
(Cont‟)
View Volume
Perspective
Far
Near
N
Window
Window
Center of Projection (a) Original Orientation
Center of Projection
Shearing
(b) After Transformation
.
Mshear
The transformation involves a combination of zaxis shear and a translation. Scale the view volume with a scaling factor that depends on 1/z.
.General perspective projection Perspective transformation
Steps 1. A shear operation is to align a general perspective view volume with the projection window. Mperspective=Mscale. Shear the view volume so that the centerline of the frustum is perpendicular to the view plane 2.
the projection window and the position of the projection reference point The process of finding the intersection of a line with one of the view volume boundaries is simplified if we convert the view volume before clipping to a rectangular parallelepiped.e we first perform the projection transformation which converts coordinate values in the view volume to orthographic parallel coordinates.Clipping
View volume clipping boundaries are planes whose orientations depend on the type of projection. Oblique projection view volumes are converted to a rectangular parallelepiped by the shearing operation and perspective view volumes are converted with a combination of shear and scale transformations. i.
.
Clippingnormalized view volumes
The normalized view volume is a region defined by the planes X=0. y=0. z=0. z=1
. x=1. y=1.
since Zaxis always points towards the viewer. 3. 2. Clipping procedures are simplified and standardized with unit clipping planes or the viewport planes.
Unit cube
3D viewport
.
Mapping positions within a rectangular view volume to a threedimensional rectangular viewport is accomplished with a combination of scaling and translation. The normalized view volume provides a standard shape for representing any sized view volume. Depth cueing and visiblesurface determination are simplified.Clippingnormalized view volumes
There are several advantages to clipping against the unit cube 1.
Dx 0 0
Where
Unit cube
0 Dy 0 0
0 0 Dz 0
Kx Ky Kz 1
3D viewport
Dx=(xvmaxxvmin)/(xwmaxxwmin) and Kx= xvmin.zwmin Dz
.xwmin Dx
0
Dy= (yvmaxyvmin)/(ywmaxywmin) and Ky= yvmin .ywmin Dy
Dz= (zvmaxzvmin)/(zwmaxzwmin) and Kz= zvmin.Clippingnormalized view volumes
Mapping positions within a rectangular view volume to a threedimensional rectangular viewport is accomplished with a combination of scaling and translation.
Viewport clipping
For a line endpoint at position (x.z) we assign the bit positions in the region code from right to left as Bit 1 = 1 if x< xvmin (left) Bit 1 = 1 if x< xvmax (right) Bit 1 = 1 if y< yvmin (below) Bit 1 = 1 if y< yvmax (above)
Bit 1 = 1 if z< zvmin (front)
Bit 1 = 1 if z< zvmax (back)
.y.
z2) the parametric equations can be
X=x1+(x2x1)u
Y=y1+(y2y1)u Z=z1+(z2z1)u
.z1) and P2(x2.y1.Viewport clipping
For a line segment with endpoints P1(x1.y2.
Hardware implementations Transformation Operations
WORLDCOORDINATE Object descriptions
Clipping Operations
Conversion to Device Coordinates
.
3D Transformations
2D coordinates
y
3D coordinates
y
x z x y Righthanded coordinate system: z x
.
s y . d y .)
1. d z ) 0 0 0 0 dx 1 0 dy 0 1 dz 0 0 1
2.
Scaling is similarly extended:
sx 0 S (sx .
Translation in 3D is a simple extension from that in 2D:
1 0 T (d x . sz ) 0 0 0 sy 0 0 0 0 sz 0 0 0 0 1
.3D Transformations (cont.
cos sin Rz ( ) 0 0 similarly we have: 0 1 0 cos Rx ( ) 0 sin 0 0
sin cos 0 0
0 0 0 0 1 0 0 1
Z
Y
X
0 sin cos 0
0 0 0 1
cos 0 R y ( ) sin 0
0 sin 1 0 0 0 0 cos
0 0 0 1
.)
3.
The 2D rotation introduced previously is just a 3D rotation about the z axis.3D Transformations (cont.
Composition of 3D Rotations
In 3D transformations. the order of a sequence of rotations matters!
cos sin Rz ( ) R y ( ) 0 0 cos 0 R y ( ) Rz ( ) sin 0 sin cos 0 0 0 sin 1 0 0 0 0 cos 0 0 cos 0 0 0 1 0 sin 0 1 0 0 cos 0 sin 0 0 1 0 0 sin 1 0 sin cos 0 0 0 0 0 cos 0 cos cos 0 sin cos 0 sin 1 0 sin cos 0 0 sin cos cos sin sin 0 cos sin sin sin cos 0 sin 0 cos 0 0 0 0 1 0 0 0 1
0 0 cos cos 0 0 sin 1 0 sin cos 0 1 0
R y ( ) Rz ( ) Rz ( ) R y ( )
.
the
axes constituting the coordinate system. z1)
X
. z2). y2 . i. z1) and (x2.e. y1. There are more we can do. z2)
P1(x1.More Rotations
We have shown how to rotate about one of the principle axes. to perform a rotation about an arbitrary axis:
We want to rotate an object about an axis in space passing through (x1. y1 . y2. for example.
Z
Y
P2(x2.
y1. Rotate object about z by : Rz()
. y1. Translate the object by (x1. z1): T(x1. Rotate the axis about x so that it lies on the xz plane: Rx() Y
P1 Z
P1
P2
X
Z
P2
X
3). Rotate the axis about y so that it lies on z: Ry ()
4). z1) Y
2).Rotating About An Arbitrary Axis
Y P2 Y
P1 P1 Z X Z
P2 X
1).
the mixed matrix that will perform the required task of rotating an object about an arbitrary axis is given by: M = T(x1.Rotating About An Arbitrary Axis (cont.
Y
P2
P1 Z X
.y1.y1.z1)
Finding is trivial. don‟t forget to undo the rotations and the translation!
Therefore. but what about ?
The angle between the z axis and the projection of P1 P2 on yz plane is .z1) Rx()Ry() Rz() Ry() Rx()T(x1.)
After all the efforts.
Composite 3D Transformations
.
y y
P3
P1 P2 x z z P2 P3 P1
x
(a)
(b)
The first solution is to compose the primitive transformations T. This approach is easier to illustrate and does offer help on building an understanding. and Rz. The 2nd.Example of Composite 3D Transformations
Try to transform the line segments P1P2 and P1P3 from their start position in (a) to their ending position in (b). more abstract approach is to use the properties of special orthogonal matrices. Rx.
. Ry.
Rotate about the z axis such that P1P3 lies in the (y. Rotate about the x axis such that P1P2 lies on the z axis. z) plane. z) plane. 2.Composition of 3D Transformations
Breaking a difficult problem into simpler subproblems: 1.Translate P1 to the origin. 4. 3.
y P3 P1 P2 y
1
P1 z y 2
P3 P2 x y 3
x
z y 4 P3 P1 z P2 x P3 P2 z P1 x
P3 P2 z P1 x
. Rotate about the y axis such that P1P2 lies in the (y.
0 0 1 0
x1 y1 z1 1
P ' T ( x1 . y1 . y1 .Composition of 3D Transformations
T ( x1 . z1 ) P [0 0 0 1]T 1 1 P2' T ( x1 . z1 ) P3 [ x3 x1 y2 y1 y3 y1 z 2 z1 1]T z3 z1 1]T
2. y1 . y1 . z1 ) P2 [ x2 x1 P3' T ( x1 . z1 ) 1 0 0 0 0 1 0 0
y P3 P1
D1
1.
R y ((90 ) ) sin 0 cos 0
x
0 1 0 0
cos 0 sin 0
P2
0 0 0 1
z
.
we have the composite matrix:
x
P1 z P2
Rz ( ) Rx ( ) R y ( 90 ) T ( x1 . y1 . z1 ) R T
.Composition of 3D Transformations
Rx ( ) 1 0 0 0
x z
3
y
P2
D2
P1
0 cos sin 0
0 sin cos 0
0 0 0 1
4.
y
Rz ( )
P3
D3
Finally.
the resulting vector is
cos u sin
sin 1 cos 0 sin cos
. 0]T. After rotating about the origin by .Vector Rotation
y
Rotate the vector
y
u
x x
1 0
The unit vector along the x axis is [1.
toward a new direction. u (or v). could be simply written as [u  v] without the need of any explicit knowledge of . originally pointing the direction of the x (or y) axis. the rotation matrix.)
y y
0 1
x
Rotate the vector
v
x
Similarly. After rotating about the origin by .Vector Rotation (cont. R. the resulting vector is
cos v sin
sin 0 sin 1 cos cos
The above results states that if we try to rotate a vector. the actual rotation angle.
. 1]T. the unit vector along the y axis is [0.
The rotation matrix in this case is R( ). expressed by R1( ) y u
Rotate the vector
y u
x
x
cos( ) sin( ) cos 1 R ( ) sin sin( ) cos( )
where T denotes the transpose.
sin u T T RT ( ) cos v
.Vector Rotation (cont.)
The reversed operation of the above rotation is to rotate a vector that is not originally pointing the x (or y) direction into the direction of the positive x or y axis.
3)
2 3 2 u u 22 32 13
T
3 13
T
T
R u  v
2 13 3 13
3 13 2 13
If.Example
what is the rotation matrix if one wants the vector T in the left figure to be rotated to the direction of u.
(2. the rotation matrix should be
T u R T v 2 13 3 13 3 13 2 13
. one wants the vector u to be rotated to the direction of the positive x axis. on the other hand.
The two column vectors are those into which vectors along the positive x and y axes are rotated. i. For orthonormal matrices.e. respectively. their dot product is zero.Rotation Matrices
Rotation matrix is orthonormal: • Each row is a unit vector
cos R sin sin cos cos2 ( sin ) 2 1 cos2 sin 2 1
•
Each row is perpendicular to the other. we have
R 1 ( ) R T ( )
•
.
cos sin cos ( sin ) 0
•
Each vector will be rotated by R() to lie on the positive x and y axes.
v1 and v2. is another vector:
y1 z2 y2 z1 v1 v2 ( x1 z2 x2 z1 ) x1 y2 x2 y1
• • The cross product of two vectors is orthogonal to both Righthand rule dictates direction of cross product.
v1 v2 v2 v1
.Cross Product
• The cross product or vector product of two vectors.
Extension to 3D Cases
The above examples can be extended to 3D cases…. In 3D. which will be rotated to the direction of the positive x axis. this
will only give us the third column in the rotation matrix. u1 is aligned to the positive z axis. we need to know more than one vector. two vectors. If after
y
z
u1
u2 x
rotation. for example. however. u1 and u2 are given. What about the other two columns?
v=u1u2
. See in the left figure.
v
u
In 2D. we need to know u.
only one vector will be aligned to one of the coordinate axes. Hence the fist column vector in the rotation matrix is the normalised P1P2.
. we can find it by taking the cross product of P1P2 and P1P3. Since P1P2 P1P3 is perpendicular to both P1P2
P3 P1 z P2 x
and P1P3. and the others are often not explicitly given. in this example. But what about the other two columns? After all. it will be aligned into the direction of the positive x axis.3D Rotation
In many cases in 3D. Well. P1P3 is not perpendicular to P1P2. Let‟s see the example: y Note. vector P1P2 will be
P3 P1 z y P2 x
rotated to the positive z direction.
Therefore. which is P1P2 (P1P2 P1P2 ).3D Rotation (cont. the rotation matrix should be
y v w u P1 z P3 P2 x
P P2 P P3 1 1 P P2 P P3 1 1 P P2 (P P2 P P3 ) 1 1 R 1 P P2 ( P P2 P P3 ) 1 1 1 P P2 1 P P2 1
.)
y v P3 P1 z u P2 x
And the third direction is decide by the cross
product of the other two directions.
and Roll
Imagine three lines running through an airplane and intersecting at right angles at the airplane‟s centre of gravity.
Roll: rotation around the
vertical axis. Pitch.
Roll: rotation around the fronttoback axis.Yaw.
Roll: rotation around the
sidetoside axis.
.
An airplane is oriented such that its nose is pointing in the positive z direction. is centre at P. its cockpit is pointing in the positive y direction. and is not banked. its right wing is pointing in the positive x direction. We want to transform the airplane so that it heads in the direction given by the vector DOF (direction of flight).An Example of the Airplane
Consider the following example.
.
which gives us the third column of the rotation matrix: DOF / DOF. The xp axis must be transformed into a horizontal vector perpendicular to DOF – that is in the direction of yDOF.Solution to the Airplane Example
First we are to rotate the positive zp direction into the direction of DOF. The yp direction is then given by xp zp = DOF (y DOF).
y DOF R y DOF
DOF ( y DOF ) DOF ( y DOF )
DOF DOF
.
) sx s y sz
2. Translation:
T 1 (d x .Inverses of (2D and) 3D Transformations
1. Shear:
SH 1 (shx .shy )
. s y . shy ) SH (shx .d y .d z )
S 1 ( s x . Scaling:
3. d y . s z ) S ( 1 1 1 . Rotation:
R 1 ( ) R( ) RT ( )
4. . d z ) T (d x .
UNITIII
GRAPHICS PROGRAMMING
.
Color Models
.
Color models.cont’d
Different meanings of color: painting wavelength of visible light human eye perception
.
1010 cm/sec
.Physical properties of light
Visible light is part of the electromagnetic radiation (380750 nm) 1 nm (nanometer) = 1010 m (=107 cm) 1 Å (angstrom) = 10 nm Radiation can be expressed in wavelength () or frequency (f). where c=3. c=f.
Physical properties of light
White light consists of a spectrum of all visible colors
.
Physical properties of light
All kinds of light can be described by the energy of each wavelength The distribution showing the relation between energy and wavelength (or frequency) is called energy spectrum
.
EW
. ED . ED 2) brightness (luminance). cp.Physical properties of light
This distribution may indicate: 1) a dominant wavelength (or frequency) which is the color of the light (hue). cp. the area A 3) purity (saturation). intensity of the light (value). cp.
Physical properties of light
Energy spectrum for a light source with a dominant frequency near the red color
.
Material properties
The color of an object depends on the so called spectral curves for transparency and reflection of the material The spectral curves describe how light of different wavelengths are refracted and reflected (cp. the material coefficients introduced in the illumination models)
.
for others reflected E.Properties of reflected light
Incident white light upon an object is for some wavelengths absorbed.g. if all light is absorbed => black If all wavelengths but one are absorbed => the one color is observed as the color of the object by the reflection
.
(two or) three colors used for describing other colors Two main principles for mixing colors: additive mixing subtractive mixing
.two colors combine to produce white light Primary colors .Color definitions
Complementary colors .
Additive mixing
pure colors are put close to each other => a mix on the retina of the human eye (cp. RGB) overlapping gives yellow, cyan, magenta and white the typical technique on color displays
Subtractive mixing
color pigments are mixed directly in some liquid, e.g. ink each color in the mixture absorbs its specific part of the incident light the color of the mixture is determined by subtraction of colored light, e.g. yellow absorbs blue => only red and green, i.e. yellow, will reach the eye (yellow because of addition)
Subtractive mixing,cont’d
primary colors: cyan, magenta and yellow, i.e. CMY the typical technique in printers/plotters connection between additive and subtractive primary colors (cp. the color models RGB and CMY)
Additive/subtractive mixing
Human color seeing
The retina of the human eye consists of cones (78M),”tappar”, and rods (100120M), ”stavar”, which are connected with nerve fibres to the brain
Human color seeing,cont’d
Theory: the cones consist of various light absorbing material The light sensitivity of the cones and rods varies with the wavelength, and between persons The ”sum” of the energy spectrum of the light the reflection spectrum of the object the response spectrum of the eye decides the color perception for a person
CMYK) 4) HSV color model 5) HLS color model
.Overview of color models
The human eye can perceive about 382000(!) different colors Necessary with some kind of classification system. all using three coordinates as a basis: 1) CIE standard 2) RGB color model 3) CMY color model (also.
CIE standard
Commission Internationale de L‟Eclairage (1931) not a computer model each color = a weighted sum of three imaginary primary colors
.
RGB model
all colors are generated from the three primaries various colors are obtained by changing the amount of each primary additive mixing (r.g.b).b≤1
.g. 0≤r.
cont’d
the RGB cube 1 bit/primary => 8 colors. 8 bits/primary => 16M colors
.RGB model.
green and blue. magenta and yellow are complementary colors of red. respectively subtractive mixing the typical printer technique
.CMY model
cyan.
cont’d
almost the same cube as with RGB. i.e cyan
. e.g. if red is absorbed => green and blue are added.CMY model. only black<> white the various colors are obtained by reducing light.
RGB vs CMY
If the intensities are represented as 0≤r,g,b≤1 and 0≤c,m,y≤1 (also coordinates 0255 can be used), then the relation between RGB and CMY can be described as:
c 1 r m 1 g y 1 b
CMYK model
For printing and graphics art industry, CMY is not enough; a fourth primary, K which stands for black, is added. Conversions between RGB and CMYK are possible, although they require some extra processing.
HSV model
HSV stands for HueSaturationValue described by a hexcone derived from the RGB cube
HSV model,cont’d
Hue (0360°); ”the color”, cp. the dominant wavelength (128) Saturation (01); ”the amount of white” (130) Value (01); ”the amount of black” (23)
HSV model,cont’d
The numbers given after each ”primary” are estimates of how many levels a human being is capable to distinguish between, which (in theory) gives the total number of color nuances: 128*130*23 = 382720 In Computer Graphics, usually enough with: 128*8*15 = 16384
HLS model
Another model similar to HSV L stands for Lightness
in yellow
.Color models
Some more facts about colors: The distance between two colors in the color cube is not a measure of how far apart the colors are perceptionally! Humans are more sensitive to shifts in blue (and green?) than. for instance.
COMPUTER
ANIMATIONS
.
particle animation.Computer Animations
Any time sequence of visual changes in a scene. shape. rotation. scaling. color. orientation. changing camera parameters(position. translation. surface texture. transparency. morphing.
Design of animation sequences: Storyboard layout Object definitions Keyframe specifications generation of inbetween frames
. and focal length). Size. lighting effects.
Object defintion Objects are defined interms of basic shapes. Storyboard It is an outline of the action Keyframe Detailed drawing of the scene at a particular instance
. such as polygons or splines.Computer Animations
Frame by frame animation Each frame is separately generated. In addition the associated movements for each object are specified along with the shape.
Computer Animations
Inbetweens Intermediate frames (3 to 5 inbetweens for each two key frames) Motions can be generated using 2D or 3D transformation Object parameters are stored in database Rendering algorithms are used finally Raster animations: Uses raster operations. Here we predefine the object at successive positions along the motion path. and set the successive blocks of pixel values to color table entries
. Ex: we can animate objects along 2D motion paths using the color table transformations.
Keyframe systems – designed simply to generate the inbetweens from the user specified key frames. kinematics etc. Action specification – this involves layout of motion paths for the objects and camera.. defining the photometric parameters and setting the camera parameters. visible surface detection. We need viewing and perspective transformations.Computer Animations
Computer animation languages: A typical task in animation specification is Scene description – includes position of objects and light sources.
. surface rendering. geometric transformations.
Scripting systems – allow object specifications and animation sequences to be defined with a userinput script. The adjustable parameters control such object charateristics as degrees of freedom.
. motion limitations and allowable shape changes. From the script a library of various objects and motions can be constructed.Computer Animations
Computer animation languages: A typical task in animation specification is Parameterized systems – allow object motion characteristics to be specified as part of the object definitions.
Computer Animations
Interpolation techniques Linear
.
Computer Animations
Interpolation techniques
Nonlinear
.
Lk+1) Key frame K Key frame K+1 Ne = Lmax mod Lmin Ns = int(Lmax / Lmin)
. we first adjust the object specification in one of the frames so that number of polygon edges or vertices is the same for the two frames. Given two keyframes for an object transformation.Lk+1) 2‟ 2 Lmin=min(Lk. 1‟ Let Lk.Lk+1 denote the number1 line segments in two different frames of K.Computer Animations
Key frame systems Morphing – Transformation of object shapes from one form to another is called morphing.K+1 3‟ Let us define Lmax=max(Lk.
Dividing the remaining lines of keyframemin into Nssections
1‟ 3‟ 2‟
Key frame K+1
1
2
Key frame K
.Computer Animations
Steps 1. Dividing Ne edges of keyframemin into Ns+1 sections 2.
adding Np points to Nls line sections of keyframemin sections 2.K+1 Let us define Vmax=max(Lk.Lk+1) Vmin=min(Lk.Lk+1) Nls = (Vmax –1)mod (Vmin –1) Np = int((Vmax –1) / (Vmin –1) Steps 1. then the similar analysis follows Let Vk. Adding Np1 points to the remaining edges of keyframemin
. If we equalize the vertex count.Computer Animations
Key frame systems Morphing – Transformation of object shapes from one form to another is called morphing.Vk+1 denote the number of vertices in two different frames K.
To simulate accelerations we can adjust the time spacing for the inbetweens.n
. The time intervals between key frames is then divided into n+1 sub t intervals..Computer Animations
Simulating accelerations Curve fitting techniques are often used to specify the animation paths between keyframes. suppose we want „n‟ inbetweens for keyframes at times t1 and t2.2. yielding an inbetween spacing of t = t2t1/(n+1) We can calculate the time for inbetweens as tBj=t1+j t for j=1.……. For constant speed we use equal interval time spacing for the inbetweens.
n
For j=1 For j=1
tB1=t1+t(1cos /2(n+1))
tB2=t1+t(1cos 2/2(n+1)) where t is the time difference between any two key frames.Computer Animations
Simulating accelerations
To model increase or decrease in speeds we use trignometric functions. We can obtain increase in interval size with the function 1cos..……. we want the time spacing between frames to increase so that greater changes in position occur as the object moves faster.2. To model increasing speed. 0< </2 For ninbetweens the time for the jth inbetween would then be calculated as tBj=t1+t(1cosj /2(n+1))
j=1.
.
…….n
.. 0< </2 For ninbetweens the time for the jth inbetween would then be calculated as tBj=t1+t.Computer Animations
Simulating deccelerations
To model increase or decrease in speeds we use trignometric functions. We can obtain increase in interval size with the function sin. we want the time spacing between frames to decrease. To model decreasing speed.sinj /2(n+1)) j=1.2.
2.…….n
.Computer Animations
Simulating both accelerations and deccelerations To model increase or decrease in speeds we use trignometric functions.. A combination of increasing and decreasing speeds can be modeled using ½(1cos) 0< </2 The time for the jth inbetween is calculated as tBj=t1+t 1cos j[(n+1)/2) j=1.
Then the geometric transformation matrices are applied to transform coordinate positions.Computer Animations
Motion specifications Direct motion specifications Here we explicitly give the rotation angles and translation vectors. A bouncing ball can be approximated by a sine curve y(x)=AI(sin(x+0)Iekx A is the initial amplitude is the angular frequency 0 is the phase angle K is the damping constant
.
Computer Animations
Motion specifications Goal directed systems We can specify the motions that are to take place in general terms that abstractly describe the actions.
. because they determine specific motion paramters given the goals of the animation.
.Computer Animations
Motion specifications Kinematics Kinematic specification of of a motion can also be given by simply describing the motion path which is often done using splines. In inverse kinematics we specify the intital and final positions of objects at specified times and the motion parameters are computed by the system.
rigid body systems and non rigid systems such as cloth or plastic) Ex: magnetic. Descriptions of object behavior under the influence of forces are generally referred to as a Physically based modeling (. gravitational.
.Computer Animations
Motion specifications dynamics specification of the forces that produce the velocities and accelerations. frictional etc We can also use inverse dynamics to obtain the forces. given the initial and final position of objects and the type of motion.
liquids •Cloth animation/draping •Underlying mechanisms are usually:
•Particle systems
•Massspring systems
.Computer Animations
•Ideally suited for:
Physics based animations
•Large volumes of objects – wind effects.
Computer Animations
Physics based animations
.
Computer Animations
Physics based animations
.
Anticipation and Staging
.Computer Animations
Some more animation techniques………….
Computer Animations
Some more animation techniques………….
Secondary Motion
.
Computer Animations
Some more animation techniques………….
Motion Capture
.
Computer Graphics using OpenGL
Initial Steps in Drawing Figures
.
dll
• The entire folder gl is placed in the Include
•
•
directory of Visual C++ The individual lib files are placed in the lib directory of Visual C++ The individual dll files are placed in C:\Windows\System32
.h. .Using OpenGL
Files: .lib. .
If you use capital letters for any file or directory.h> • <gl/gl.h> • <gl/glui. use them in your include statement also.h> • <gl/glut.h> • <gl/glu.
.Using OpenGL (2)
Includes:
• <windows.h> (if used)
Include in order given.
Settings entry • In Object/library modules move to the end of
•
•
the line and add glui32.0
• Project menu.lib glu32. scroll down to end of box and add same set of .lib (separated by spaces from last entry and each other) In Project Options.lib files Close Project menu and save workspace
.lib opengl32.lib glut32.Using OpenGL (3)
Changing project settings: Visual C++ 6.
Properties.lib glut32. add •
glui32. Linker. Command Line • In the white space at the bottom.lib Close Project menu and save your solution
.lib opengl32.lib glu32.NET 2003
• Project.Using OpenGL (3)
Changing Project Settings: Visual C++ .
windows system (b). with yaxis down]. windows system [inverted coordinates] (c)
. [both have usual screen coordinates.Getting Started Making Pictures
Graphics display: Entire screen (a).
y2) • Other names: drawLine() or Line(). color)
• Pixel at location (x. y1. y. or drawPoint()
line(x1. SetPixel().Basic System Drawing Commands
setPixel(x. y1) and (x2. x2. y) gets color specified by
•
color Other names: putPixel().
. y2)
• Draws a line between (x1.
.Alternative Basic Drawing
current position (cp).y) draws a straight line from the current position to (x. y) and then updates the current position to this position. lineTo(x. moveTo(x. specifies where the system is drawing now. y).y) moves the pen invisibly to the location (x. y) and then updates the cp to (x.
4). 4). lineTo(4. 2). //close the square
. lineTo(2.Example: A Square
moveTo(4. //move to starting corner lineTo(2. 4). 2). lineTo(4.
. OpenGL is open source (free).
• .dll files must be with program
OpenGL is an API: it controls whatever hardware you are using. and you use its functions instead of controlling the hardware directly.Device Independent Graphics and OpenGL
Allows same graphics program to be run on many different machine types with nearly identical output.
Registering function does *not* call it!
. Programmer provides “callback” functions to handle each event. such as mouse click or move. System manages event queue.Eventdriven Programs
Respond to events. Callback functions must be registered with OpenGL to let it know which function handles which event. or window reshape or resize. key press.
// enter the unending main loop }
. // register the mouse action function glutMotionFunc(myMotionFunc). // register the mouse motion function glutKeyboardFunc(myKeyboard). // register the redraw function glutReshapeFunc(myReshape). // register the reshape function glutMouseFunc(myMouse). // register the keyboard action function …perhaps initialize other things… glutMainLoop().Skeleton Eventdriven Program
// include OpenGL libraries void main() { glutDisplayFunc(myDisplay).
Callback Functions
glutDisplayFunc(myDisplay). simply redraws display using void myIdle() {glutPostRedisplay().) when nothing else is going on.
• •
(Re)draws screen when window opened or another window moved off it. (Moving a window does not produce a reshape event.}
glutReshapeFunc(myReshape). Reports new window width and height for reshaped window.
•
.
glutIdleFunc(myIdle).
.
• Handles case when the mouse is moved with
one or more mouse buttons pressed.
• Handles mouse button presses. Knows
mouse location and nature of button (up or down and which button).Callback Functions (2)
glutMouseFunc(myMouse).
glutMotionFunc(myMotionFunc).
Runs forever waiting for an event. it is handled by the appropriate callback function.
glutKeyboardFunc(myKeyboardFunc).Callback Functions (3)
glutPassiveMotionFunc(myPassiveMotionFunc )
• •
•
Handles case where mouse enters the window with no buttons pressed. Handles key presses and releases. Knows which key was pressed and mouse location.
glutMainLoop()
. When one occurs.
develops menus. the GL Utility Library. the User Interface Library. GLUI. for which the commands begin with GL. which is completely integrated with the GLUT library.
. and manages events. GLUI provides sophisticated controls and menus to OpenGL applications. which provides high level routines to handle complex mathematical and drawing operations.Libraries to Include
GL. GLU. GLUT. opens windows. the GL Utility Toolkit.
• •
The GLUT functions must be available for GLUI to operate properly.
480). argv). // initialize the toolkit glutInitDisplayMode(GLUT_SINGLE  GLUT_RGB). 150). // open the screen window (Title: my first attempt) // continued next slide
.A GL Program to Open a Window
// appropriate #includes go here – see Appendix 1 void main(int argc. // set window size glutInitWindowPosition(100. // set the display mode glutInitWindowSize(640. // set window upper left corner position on screen glutCreateWindow("my first attempt"). char** argv) { glutInit(&argc.
glutKeyboardFunc(myKeyboard). glutReshapeFunc(myReshape).
.Part 2 of Window Program
// register the callback functions glutDisplayFunc(myDisplay). glutMouseFunc(myMouse). myInit(). // additional initializations as necessary glutMainLoop(). // go into a perpetual loop
}
Terminate program by closing window(s) it is using.
What the Code Does
glutInit (&argc. argv) initializes OpenGL Toolkit glutInitDisplayMode (GLUT_SINGLE  GLUT_RGB) allocates a single display buffer and uses colors to draw glutInitWindowSize (640. 480) makes the window 640 pixels wide by 480 pixels high
.
150) puts upper left window corner at position 100 pixels from left edge and 150 pixels down from top edge glutCreateWindow (“my first attempt”) opens and displays the window with the title “my first attempt” Remaining functions register callbacks
.What the Code Does (2)
glutInitWindowPosition (100.
What the Code Does (3)
The callback functions you write are registered. When an event occurs. waiting for events to occur. and then the program enters an endless loop. GL calls the relevant handler function.
.
Effect of Program
.
. To draw an object in OpenGL. • Arg determines what is drawn. OpenGL drawing is based on vertices (corners). • glEnd() sends drawing data down the
OpenGL pipeline.
• The list starts with glBegin(arg). you pass it a list of vertices. and ends with glEnd().Drawing Dots in OpenGL
We start with a coordinate system based on the window just created: 0 to 679 in x and 0 to 479 in y.
GL_POINTS is constant builtinto OpenGL (also GL_LINES.
.
• glVertex2i (100.11. 50). GL_POLYGON. 130). 130). …) Complete code to draw the 3 dots is in Fig.
glEnd().Example
glBegin (GL_POINTS). 2. • glVertex2i (150. • glVertex2i (100.
Display for Dots
.
What Code Does: GL Function Construction
.
Example of Construction
glVertex2i (…) takes integer values glVertex2d (…) takes floating point values
OpenGL has its own data types to make graphics deviceindependent
• Use these types instead of standard ones
.
GLclampd GLubyte.OpenGL Data Types
suffix data type b s i 8bit integer 16bit integer 32bit integer C/C++ type signed char Short int or long OpenGL type name GLbyte GLshort GLint. GLclampf
GLdouble. GLsizei
f
d ub
32bit float
64bit float 8bit unsigned number
Float
Double unsigned char
GLfloat.GLboolean
us
ui
16bit unsigned number
32bit unsigned number
unsigned short
unsigned int or unsigned long
GLushort
GLuint.GLbitfield
.Glenum.
1.0. • glColor3f(0.0). 1.0). // set drawing color
• glColor3f(1.0). 1.0).0.0. 0.0. • glColor3f(1.
green.Setting Drawing Colors in GL
glColor3f(red. 0.0.0. 1. • glColor3f(0.0.0). blue).0. • glColor3f(1. 0. 1. 0.0). 0.0.0.
// red // green // blue // black // bright white // bright yellow // magenta
. 1. 0.0.0. • glColor3f(1.0). 0.0. 0.0. • glColor3f(0.
use 0. green. • Alpha is degree of transparency. blue.
• Sets background color.
glClear(GL_COLOR_BUFFER_BIT).0 for
now.
• clears window to background color
.Setting Background Color in GL
glClearColor (red. alpha).
0. 640. gluOrtho2D(0. 480. 479)
. glLoadIdentity().0).0) to (679.Setting Up a Coordinate System
void myInit(void) { glMatrixMode(GL_PROJECTION). } // sets up coordinate system for window from (0. 0.
and a separate line is drawn between each pair. • glVertex2i (202.
. //draws one line
• glVertex2i (40. 96). If more than two vertices are specified between glBegin(GL_LINES) and glEnd() they are taken in pairs. glFlush(). 100).
// between 2 vertices
glEnd ().Drawing Lines
glBegin (GL_LINES).
thin lines lines b). glLineWidth(4. thickness. stippled
.0) sets thickness.0.Line Attributes
Color.
a). The default thickness is 1. glColor3f() sets color. thick lines c). stippling.
Setting Line Parameters
Polylines and Polygons: lists of vertices. Polygons are closed (right). polylines need not be closed (left).
.
glFlush (). A GL_LINE_LOOP cannot be filled with color
.Polyline/Polygon Drawing
glBegin (GL_LINE_STRIP). // GL_LINE_LOOP to close polyline (make it a polygon)
• // glVertex2i () calls go here
glEnd ().
f(x)) values Must scale and shift
.Examples
Drawing line graphs: connect each pair of (x.
24.
. 2. x y. one pair per line • Repeat last 2 lines as necessary
File for dinosaur available from Web site Code to draw polylines/polygons in Fig.Examples (2)
Drawing polyline from vertices in a file
• # polylines • # vertices in first polyline • Coordinates of vertices.
Examples (3)
.
Examples (4)
Parameterizing Drawings: allows making them different sizes and aspect ratios Code for a parameterized house is in Fig.27.
. 2.
Examples (5)
.
Examples (6)
Polyline Drawing Code to set up an array of vertices is in Fig. 2.
. Code to draw the polyline is in Fig.29. 2.30.
and therefore vulnerable to tampering from instructions at other points in your program. y) lineTo(x. Code is in Fig. y).
. moveTo(x.31. y). y).Relative Line Drawing
Requires keeping track of current position on screen (CP). 2. Caution! CP is a global variable. y). draw a line from CP to (x. and then update CP to (x. set CP to (x.
later rectangles are drawn on top of previous ones
. GLint x2. filled with current color. GLint y2).Drawing Aligned Rectangles
glRecti (GLint x1. // opposite corners. GLint y1.
Aspect Ratio of Aligned Rectangles
Aspect ratio = width/height
.
below. F are convex
. E.Filling Polygons with Color
Polygons must be convex: any line from one boundary to another lies inside the polygon. only D.
calls go here
glEnd ().
• //glVertex2f (…).Filling Polygons with Color (2)
glBegin (GL_POLYGON). Polygon is filled with the current drawing color
.
Other Graphics Primitives
GL_TRIANGLES. GL_QUAD_STRIP
. GL_TRIANGLE_STRIP. GL_TRIANGLE_FAN GL_QUADS.
Write the function(s) NOTE that any drawing you do when you use these functions must be done IN the mouse or keyboard function (or in a function called from within mouse or keyboard callback functions). • glutKeyboardFunc (myKeyboard).
.Simple User Interaction with Mouse and Keyboard
Register functions:
• glutMouseFunc (myMouse).
X and y are mouse position at the time of the event. int state. State is GLUT_UP or GLUT_DOWN. int y). or GLUT_RIGHT_BUTTON.Example Mouse Function
void myMouse(int button. Button is one of GLUT_LEFT_BUTTON.
. GLUT_MIDDLE_BUTTON. int x.
The y value is the number of pixels down from the top of the window. the mouse or keyboard handler must call either myDisplay() or glutPostRedisplay().Example Mouse Function (2)
The x value is the number of pixels from the left of the window. In order to see the effects of some activity of the mouse or keyboard.
.40. Code for an example myMouse() is in Fig. 2.
Polyline Control with Mouse
Example use:
.
Code for Mousecontrolled Polyline
.
Using Mouse Motion Functions
glutMotionFunc(myMovedMouse). // moved with button held down glutPassiveMotionFunc(myMovedMouse ). // moved with buttons up myMovedMouse(int x.
. 2. Code for drawing rubber rectangles using these functions is in Fig. x and y are the position of the mouse when the event occurred.41. int y).
Example Keyboard Function
void myKeyboard(unsigned char theKey. int mouseY) { GLint x = mouseX. // do nothing } }
. // draw dot at mouse position case „E‟: exit(1). y). // flip y value switch(theKey) {case „p‟: drawDot(x. GLint y = screenHeight . //terminate the program default: break. int mouseX.mouseY. break.
Example Keyboard Function (2)
Parameters to the function will always be (unsigned char key. Body is a switch with cases to handle active keys (key value is ASCII code). int mouseY). The y coordinate needs to be flipped by subtracting it from screenHeight. int mouseX. Remember to end each case with a break!
.
. GLUT menus are simple. and GLUI menus are more powerful. We will build a single menu that will allow the user to change the color of a triangle. which is undulating back and forth as the application proceeds.Using Menus
Both GLUT and GLUI make menus available.
// value used in myMenu switch to handle choice void glutAttachMenu(int button). // one of GLUT_RIGHT_BUTTON. GLUT_MIDDLE_BUTTON. or GLUT_LEFT_BUTTON
•
Usually GLUT_RIGHT_BUTTON
.GLUT Menu Callback Function
Int glutCreateMenu(myMenu). int value). //handles choice num void glutAddMenuEntry(char* name. returns menu ID void myMenu(int num).
int menuID). (No submenus are used. 2.GLUT subMenus
Create a subMenu first. then add it to main menu. // menuID is the value returned by glutCreateMenu when the submenu was created Complete code for a GLUT Menu application is in Fig.)
. using menu commands.
•
A submenu pops up when a main menu item is selected.44.
glutAddSubMenu (char* name.
GLUI Interfaces and Menus
.
Most of the work has been done for you. you may cut and paste from the example programs in the GLUI distribution.GLUI Interfaces
An example program illustrating how to use GLUI interface options is available on book web site.
.
UNITIV
RENDERING
.
Polygon shading model
Flat shading .compute lighting once and assign the color to the whole (mesh) polygon
.
Flat shading
Only use one vertex normaland material property to compute the color for the polygon Benefit: fast to compute Used when:
• Polygon is small enough • Light source is far away (why?) • Eye is very far away (why?)
.
Mach Band Effect
Flat shading suffers from “mach band effect” Mach band effect – human eyes accentuate the discontinuity at the boundary
perceived intensity
Side view of a polygonal surface
.
Smooth shading
Fix the mach band effect – remove edge discontinuity Compute lighting for more points on each face
Flat shading
Smooth shading
.
Smooth shading
Two popular methods:
• Gouraud shading (used by OpenGL) • Phong shading (better specular highlight. not
in OpenGL)
.
Gouraud Shading
The smooth shading algorithm used in OpenGL glShadeModel(GL_SMOOTH) Lighting is calculated for each of the polygon vertices Colors are interpolated for interior pixels
.
Gouraud Shading
Pervertex lighting calculation Normal is needed for each vertex Pervertex normal can be computed by averaging the adjust face normals
n1 n3 n n4 n2 n = (n1 + n2 + n3 + n4) / 4.0
.
Gouraud Shading
Compute vertex illumination (color) before the projection transformation Shade interior pixels: color interpolation (normals are not needed) C1
for all scanlines
Cb = lerp(C1. Cb)
* lerp: linear interpolation
. C2)
C2
C3
Lerp(Ca. C3)
Ca = lerp(C1.
Gouraud Shading
Linear interpolation
x= a / (a+b) * v1 + b/(a+b) * v2
a
b
x v1 v2 Interpolate triangle color: use y distance to interpolate the two end points in the scanline. and use x distance to interpolate interior pixel colors
.
Gouraud Shading Problem
Lighting in the polygon interior can be inaccurate
.
we calculate lighting for each pixel inside the polygon (per pixel lighting) Need normals for all the pixels – not provided by user Phong shading algorithm interpolates the normals and compute lighting during rasterization (need to map the normal back to world or eye space though)
.Phong Shading
Instead of interpolation.
n3)
lerp(na. nb)
n2
n3
•
Slow – not supported by OpenGL and most graphics hardware
.Phong Shading
Normal interpolation
na = lerp(n1. n2)
n1
nb = lerp(n1.
UNITV
FRACTALS
.
.Fractals
Fractals are geometric objects. Fractals are formed by iterations. we use fractal functions to create complex objects. Fractals are selfsimilar. Many realworld objects like ferns are shaped like fractals. In computer graphics.
Koch Fractals (Snowflakes)
1/3 1/3
1
1/3
1/3
Generator
Iteration 0
Iteration 1
Iteration 2
Iteration 3
.
Fractal Tree
Generator
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
.
Fractal Fern
Generator
Iteration 0
Iteration 1
Iteration 2
Iteration 3
.
simply change the angles slightly sometimes based on a random number generator.Add Some Randomness
The fractals we‟ve produced so far seem to be very regular and “artificial”.
. For example. To create some realism and variability. For example. you can curve some of the ferns to one side. you can also vary the lengths of the branches and the branching factor.
Suppose that the two endpoints are a and b. such that the height at a is y(a). and rg is a Gaussian random variable with mean 0 and variance 1
. the height at the midpoint will be:
• r is the random offset This is how to generate the random offset r:
r = srgba. generate a height at the midpoint. and the height at b is y(b). where ymid = (y(a)+y(b))/2 + r. Then. Suppose the height is in the y direction. where
• •
s is a userselected “roughness” factor.Terrain (Random Midpoint Displacement)
Given the heights of two endpoints.
w = sqrt( (2. float &y2) { float x1. w = x1 * x1 + x2 * x2.001*(float)(rand()%1000) .1.0 // and with standard deviation 1. do { x1 = 2. x2.0 * 0.0. } while ( w >= 1.0 * log( w ) ) / w ).How to generate a random number with Gaussian (or normal) probability distribution
// given random numbers x1 and x2 with equal distribution from 1 to 1 // generate numbers y1 and y2 with normal distribution centered at 0. w.001*(float)(rand()%1000) . y2 = x2 * w. x2 = 2.0 * 0.0.1.0.0 ). y1 = x1 * w. }
. void Gaussian(float &y1.
Procedural Terrain Example
.
. cliffs. use different parameters for valleys and mountains. can manually create ridges.Building a more realistic terrain
Notice that in the real world. and then use fractals to create detail roughness. it will result in unrealistic. Also. alienlooking landscapes. Therefore. valleys and mountains have different shapes. If we have the same terraingeneration algorithm for both mountains and valleys. and other geographical features.
trees.Fractals
Infinite detail at every point Self similarity between parts and overall features of the object Zoom into Euclidian shape • Zoomed shape see more detail • eventually smooths Zoom in on fractal • See more detail • Does not smooth Model • Terrain. feathers. P3=F(P2)… • P3=F(F(F(P0)))
. clouds water. plants. patterns General equation P1=F(P0). P2 = F(P1). fur.
shrubs.Self similar fractals
Parts are scaled down versions of the entire object
• use same scaling on subparts • use different scaling factors for subparts • Apply random variation to subparts
• Trees. other vegetation
Statistically selfsimilar
.
water.Fractal types
Statistically selfaffine
• •
random variations
• terrain. clouds Invariant fractal sets
Nonlinear transformations
• Sx<>Sy<>Sz
• Self squaring fractals
• • •
• Selfinverse fractals
JuliaFatou set • Squaring function in complex space Mandelbrot set • Squaring function in complex space Inversion procedures
.
x=>x2+c • x=a+bi • Complex number Modulus • Sqrt(a2+b2) • If modulus < 1 • Squaring makes it go toward 0 • If modulus > 1 • Squaring falls towards infinity If modulus=1 • Some fall to zero • Some fall to infinity • Some do neither • Boundary between numbers which fall to zero and those which fall to infinity • JuliaFatou Set
JuliaFatou and Mandelbrot
JuliaFatou
Foley/vanDam Computer GraphicsPrinciples and Practices. 2nd edition
.
2nd edition
Julia Fatou and Mandelbrot con’d
Shape of the JuliaFatou set based on c To get Mandelbrot set – set of nondiverging points • Correct method • Compute the Julia sets for all possible c • Color the points black when the set is connected and white when it is not connected • Approximate method • Foreach value of c.Foley/vanDam Computer GraphicsPrinciples and Practices. color the points of c white. start with complex number 0=0+0i • Apply to x=>x2+c • Process a finite number of times (say 1000) • If after the iterations is is outside a disk defined by modulus>100.
. otherwise color it black.
Constructing a deterministic selfsimilar fractal
Initiator
• Given geometric shape • Pattern which replaces subparts of initiator
Generator
Koch Curve
First iteration
Initiator
generator
.
line divided into 3 segments. Instead of saying the line is 1/3.Fractal dimension
D=fractal dimension • Amount of variation in the structure • Measure of roughness or fragmentation of the object • Small dless jagged • Large dmore jagged Self similar objects • nsd=1 (Some books write this as nsd=1) • s=scaling factor • n number of subparts in subdivision • d=ln(n)/ln(1/s) • [d=ln(n)/ln(s) however s is the number of segments versus how much the main segment was reduced • I.e. Notice that 1/(1/3) = 3] • If there are different scaling factors
• •
n
Skd=1
K=1
. say instead there are 3 sements.
262
Divide lines on square into small squares by dividing each line into n identical segments
•
For your reference: Book method
•
• •
• n=4
n=s2 small squares Get n=s3 small cubes
Divide cube
• s=1/3
Number of new segments segments reduced by 1/3
• d=ln4/ln(1/(1/3))
.Figuring out scaling factors I prefer: nsd=1 :d=ln(n)/ln(s)
Dimension is a ratio of the (new size)/(old size)
Koch‟s snowflake
•
After division have 4 segments
•
Divide line into n identical segments
•
•
n=s
• n=4 (new segments) • s=3 (old segments) • Fractal Dimension
• • •
D=ln4/ln3 = 1.
Sierpinski gasket Fractal Dimension
Divide each side by 2
• • • •
Makes 4 triangles We keep 3 Therefore n=3
triangle
• Get 3 new triangles from 1 old
s=2 (2 new segments from one old segment) D=ln(3)/ln(2) = 1.585
Fractal dimension
•
.
727
. where we used to have 1
What is the fractal dimension?
• n=20
We have divided each side by 3
• s=3
Fractal dimension ln(20)/ln(3) = 2.Cube Fractal Dimension
Apply fractal algorithm
• • • • • •
Divide each side by 3 Image from Now push out the middle face of each cube Angel book Now push out the center of the cube Well we have 20 cubes.
Language Based Models of generating images
Typical Alphabet {A. but I want a tree
B B A A A
B
AA B
.[.B.]} B Rules A[B]AA[B]
• • • • •
A=> AA B=> A[B]AA[B]
AA[A[B]AA[B]]AAAA[A[B]AA[B]]
AA A
B A A A A A B A A
Starting Basis=B Generate words
Represents sequence of segments in graph structure Branch with brackets Interesting.
B.].[.(.)} Rules
• • •
B A[B]AA(B) AA[A[B]AA(B)]AAAA(A[B]AA(B))
A=> AA B=> A[B]AA(B) [] = left branch () = right branchStarting Basis=B
B AA A A A A A B
Generate words
•
•
B B A A A B
Represents sequence of segments in graph structure Branch with brackets
B
AA A
A A
.Language Based Models of generating images con’d
Modify Alphabet {A.
Language Based models have no inherent geometry
B AA A A A A A AA B A A A B
Grammar based model requires • Grammar • Geometric interpretation Generating an object from the word is a separate process • examples • Branches on the tree drawn at upward angles • Choose to draw segments of tree as successively smaller lengths • The more it branches. the smaller the last branch is • Draw flowers or leaves at terminal nodes
B
.
2nd edition
.Grammar and Geometry
Change branch size according to depth of graph
Foley/vanDam Computer GraphicsPrinciples and Practices.
box. etc • Apply probabilistic rules to particles • generate new particles • Change attributes according to age • What color is particle when detected? • What shape is particle when detected? • Transparancy over time? • Particles die (disappear from system) • Movement • Deterministic or stochastic laws of motion • Kinematically • forces such as gravity
. exploding • Basic particle can be any shape • Sphere.Particle Systems
System is defined by a collection of particles that evolve over time • Particles have fluidlike properties • Flowing. imploding. spattering. ellipsoid. billowing. expanding.
fog. waterfall. hit rock.
. Grass • Model clumps by setting up trajectory paths for particles Waterfall • Particles fall from fixed elevation • Deflected by obstacle as splash to ground • Eg. drop.Particle Systems modeling
Model • Fire. float back up. water spray. go to bottom of pool. grass. trees. finish in pool • Drop. fireworks. smoke.
Fs = restoring force on spring Could also model with putty (doesn’t spring back) Could model with elastic material • Minimize strain energy
k
k
k
k
. jello Describe behavior in terms of external and internal forces • Approximate the object with network of point nodes connected by flexible connection • Example springs with spring constant k • Homogeneous object • All k’s equal Hooke’s Law • Fs=k x • x=displacement. soft rubber ball.Physically based modeling
Nonrigid object • Rope. cloth.
Turtle can
“Turtle Graphics”
F=Move forward a unit L=Turn left R=Turn right
• • •
Stipulate turtle directions. angle =120 FRFRFR
What if change angle to 60 degrees
F=> FLFRRFLF Basis F
•
Koch Curve (snowflake)
Example taken from Angel book
. and angle of turns Equilateral triangle
• • • •
•
Eg.
Using turtle graphics for trees
Use push and pop for side branches [] F=> F[RF]F[LF]F Angle =27 Note spaces ONLY for readability F[RF]F[LF]F [RF[RF]F[LF]F] F[RF]F[LF]F [LF[RF]F[LF]F] F[RF]F[LF]F
.
0.3/ .9..9434190147.2.7010770/94.47:3/079031:03.089.08 .908. 7.9438
4943850. 2.0780/3.90.49475.943.007.89..2.425:90732.80/24/03 7/ 4/889028..390147.3.!8.041 147.3/3437/8890288:.04.039039.3/909504124943
.8.5489434140.7594384140..3/13.9438 /3.943808.8 850..309.09.8 9449.943.08. 17.8.1..1.84:803...9574/:.090..700307. .98..
9438
W/0.80/.8.70.32.425:90732.32.9438
W.98 6:/8 W49.4:2084140.8:90/147 !8.943.98 3/0110.
/7.70:8:.3828.53 W&3/07320.79.88
8573889028
. W!..0889028 W.
80/.9438
.425:90732.9438
!8.32.8.
32.9438
!8.80/.9438
.8.425:90732.
36:08
39.9438
$4202470.425:90732.3
.5.3/$9.32.943.943 90.
9438
$4202470.943 90.32.43/.74943
.425:90732.36:08
$0.
943 90.9438
$4202470.59:70
.36:08
4943.32.425:90732.
3:708
.$905837.5.425:9077.8 :83 503
39.
705. %03/..0/3 3/48$8902
./108.94741'8:.705./:../:./
W %00397014/0785.:/0 W W
/70.&83 503
08 .0/390 /70.0/3903..108.94741'8:. %03/.
:/08
W 3/48 W .&83 503
3.
W .
: W .
:9 W .
947 :80902 34:73.:/0347/07.84
.31047/70.: 1:80/
3.. 099078147.59.0314::80.902039.:/089.
W !740.9.335740.9809938'8:.&83 503
.9203: $099380397 W 3 0.
2080941108 480!740.04785....3/.081742.0
.0949003/41 W W
9030.7.4907 3!740.74/439403/414 .724/:0824.3/8.90/85.9203:.9 59438 8.//::9: 4503 805.3/0..89 0397.//8.7.3/.
%
W !740.99049942 .// W
::9:4503 480!740..&83 503
.9203:.04:784:943
.9$09938'8:.33!740..3/8.0.9 !74507908 307 422.3/30 W 3909085.
.49.8/43( 3/48889023.0:8:.908( .9:708
7.5.790/.0993$9.0790/.7003.8/85.7003 .447/3.
.447/3. 8.908 9
.39708. 3/4888902 .3!.
208/7.3/8
809!0 .943 098.3422.!439
47
30
W 7.94.447 9073.10/ W
.30 4730
..$89027.8.447
W !0.447850.2085:9!0 $09!0 /7.3009003 ..3/ W 9073.8.
0.5 94
.9073.90890 .7.3
.8.108070 90889028/7.:770395489439498548943 30%4 /7.894 904.930174290 ..90890.3/903 :5/.943 .334 24.0%4 24.5 850.:77039548943 .8.897.9.:7703954894394 .08905033.3/903:5/.
70
24.250$6:..0%4 .
.
793 .47307 30%4
30%4
30%4
30%4 .24.09489.
.
48090 86:..70
.
704:.3095089 30.3/ 503
488..7/039.29407:3 432.03/0503/0397.94383890.9 5038450384:7.3/11070392.90..4:95:9
W /1082:89095747.85747./41.07 ..0.2
5038.70:83 .7/.5.0 1700
.3!9.43974390 .439748.3/4::8098 1:3.8.207.7/.5.70/70.
3/00..943.824:80.
.. 4724. 1:3.50 477080$89022.0398 8:.0396:0:0 !747.
.039 .3/08.1:3..080..039 #0890731:3.943894../08 .28
#08543/940.0. 1:3..03!747..2207574.94382:8907089070/ 9 5039409934..943/408 349 .9
.039
/7.0 057088 473/4708.0.3.
03!747.$00943.039
/7.2
.
.
285. .3 :985.4/2.708 .:/0 5037.:3.3.
.
1:3.7089079070/7.50:3. 2#08.943 :9#08.50 .
.
50 1:3.70890790708. 24:80 .943 :94:80:3.
.
943 1:3. 24943:3. .943 :94943:3.7089079024:80..
.
943 :904.7/ . 204.7089079024:8024943 1:3.7/:3.
.
7/ .5839..7089079004.04907938 .9431:3.943 507.
.
0390790:303/32.1:3.4190..9438.3445 < ..70/0130/070
..3445 :9.
285.7003033/445030/47...50
W
:9/0:3. :83.039 03349308084343 82570/7. <
:9#08.0/4119 #054798303/4/9.34907 3/424.0.3. 708. 2/0
W
.4/2/0 :9!489#0/85.3/4/408349574/:..3/09147708.88.:3.9438
:985.8/85.50/ 3/4 4.
W
#0 /7.50:3. 2#08.:3.500.
9438
:94:80:3.3/0824:80:99435708808348
24:804.0/9
43047247024:80:99438570880/
....:3.:9943
:94943:3.943. 24943:3.3/08.3/3.. 24:80
W .
W ..3/.9:7041:9943 :547 /43.80039024:80824.
204..07.93147..3/700.
W .808348..30.04943:3. 2!..8007024:80039078903/49
34 :99438570880/
:904.04943:3.3/08.88.
W ..8570880/..039034304..:3.90.88.3445
W
#:381470.
0.7/:3.9438
:9!.1:3.557457..3/0/90.7/:3.943
:9..:78 98.3/24:804.3/0805708808.943
.
4250903907.:/0
147.708943.3/8039 &% 90&99%449 450383/48 /0.3/0.574.7.9.07./08 0.080.94382:890.90.90/.4250 2..3//7.7 .8 .3/2..7
W W
%0&%1:3..074:930894.9438
.0458203:8 .90/990&%7...0398 & 90&997.7 .3/203:894 503.439748./0884589.55.902.3....90574507 &574.9438 & 90&80739071.422.0147&94 4507.34507.
!747.3/4
.294 503.
.
.:/084070 8005503/ .7. :939 .7..7.3 39.4/2.557457. .7. ..7 .903.
.
0909449 :93985.39.4/0 &%*$&%*# .
.
24/0 :9393/4$0
.80990/85.
.
8093/480 :9393/4!48943
.
.
7003 :970.47307548943438.903/4 21789.8093/4:5507019.990259 .
.
70033/4 %9021789.4503908.990259 .
.
4393:0/3098/0
..
2
.!.79413/4!747.
.
1:3.7/:3.7/ 239 .50 :94:80:3. 204..:3. :9#08.70890790..9438 :985. 2#08. 285.50:3. 24:80 :904..
.
7 :9.39..9438.8 30.//943..3445 .088.
.
2.4833/4 8 98:83
.507509:.4394.905747. 445 <
%0723.
.7. 39.. .0890 3/4
508/0
508
.08 503
%449 :93985.830/85. :1107.4/0 &%*$ &%*# .4.447894/7. :9393/4$0
2.9904/0408
:939 .908.7.3/:808.
903/4 21789.990259 #02.9904/0408
:9393/4!48943
5:98 :55070193/4.9438708907.331:3.8
.9548943
50817420190/0.990259 45038.3/
508 /4317429450/0 :970.8903/4990 990 21789..3//85...47307..
931470.
...2039078 .:7 03..890 700.3/903905747.0394.1:3..:78 .39..94384:790.30..9904/0408
%0..70 7089070/ .3/071:3.039894 4.303/088445 .943
.
2
.941!747.110.
079.079.889.90/
943 .3/..3 W 3/ 803/8/7.98/7.447/3.80/43.08
W %08989.70.9.93 503 4:5.340.7 .799.798903 .08 ./4390
50355030
.34983 503
089.8941.9088902.80/ 43903/4:89.7..38.3/
943 503/7.473078 %4/7.3/03/89 3/ W 7 /09072308.
90/49883
.4389.4/094/7.250
03 *! %$
W '0790
W '0790
W '0790
3/ *! %$8..84*$ *! 425090.39:9
394 503
.
85.147498
.
943 43897:..943
.94/0408:3.
3/..:08 9.0 7.9.0814.:08
9.8/0.9508942./4189.2504143897:.943
'0790 '0790/ .5.0
3/0503/039
W &80908095083890.935439
503.89843/..7/4308
...0839007.
9
9:3830/ 3:207 .9
914.950 8 1 / ::8 :
939007
939007
939007
914.9.503
.9.%508
8:11 /.
25/ :90 440...7
9:3830/ :3830/8479 3:207
9:3830/ :3830/3947 :39 03:2 910/ 3:207 :3830/43
..20 90 8479 39 80 14.9 .3 :8479 830/.7 950 5039503.9 4:0 :3830/..251 /4:0 . $479 394743 4.
344783
4471
70/ 7003 :0 .$09937.
.
809/7.447
W 4471
W 4471
W 4471
W 4471
W 4471
W 4471
W 4471
.3.
.
70/ .
.
7003 .
.
:0 .
.
...
.
7990 .
.
7904 .
.
2.039.
.
74:3/.:80
147
34
0.$0993.74:3/4473
0.
W $098..447 W 5.74:3/.0..783/494.5.703..7 * #*&#*%
W .447
.7447 70/ 7003 :0 .8/07004197.385.
447/3.4/ .//0399 : 794
< .$0993&5.90$8902
.974/0 *!# % 4.4/239 .
.
447/3.90889021473/4 1742
94
.8098:5.
7.3308
03 *$ .
.
/7.843030
W '0790
.
.
78 .3/ 3/ 90.079.08 W '0790
3/ :8 124709.709.394.3090030. 805.90308/7.09003.7..08.3/.7
.0335.10/ 0900303 *$ . 5.079.70850.
89550/ 308
. 93308.308.30997:908
447 9.9.447 30/9
80989.3088%0/01.3088 89553 4471 8098.30888
.:9 9.
480/ 019
.079.209078
!4308.$099330!.70.7.3/!443889841.08 !4438.480/ 79 54308 300/3490.
!430.
!4437.3
03 **$%#! .
.
** !94.4805430 2.5443
W .09.
.
3349010/9
.447
!.84070
3/ :8 ** .'0790
...
..2508
7..3/819
.:08 :898.0.4330..90.7 41 1 .5.58.3307.
079...90841.088..10
W 54308 W .08 4305.08317895430 W 447/3.354301742.9.083..079.750730 W #050.079.2508
7.017420890 4/094/7.830.7
0147/348.89308.54308.:7.
544383
.
.2508
.
209070/4:8083
.97.3/.850..3 902/1107039808.482.38.2090737.5.7.7.948 4/0147.2508
!.
.2508
.
90543083
.77.2508
!4307..0883 4/094/7.41.079.3.3 4/094809:5.
3/90701470 .2507317423897:...0 .0307.:943! 8.7.0949...41.9.2
.#0.90! 94 4/083 .:7703954894343 8.0%4 809! 94 30%4 /7.9438.9 49075439834:75747.301742! 94 .:307.3
#06:708005397.7003 ! 24.4.3/903:5/.
7.9.330/#0.308
#0.9 39 39 39 39 .
.
4554890.:77039.9.47307810/9 .447.70/7.4:84308
.308.90770.3 4394541570.
9.308
850.850.944130/#0.94/9.9#.97.
09
.
349070838/090 544304 43 .3!44389447
!44382:890.0
.3301742 4304:3/.43.43.0.70.794.
3!44389447
03 *!
W .
.
447
.'07901
.:77039/7..84070
3/ !443810/990.3 .
8!729.08
*%#$ *%#*$%#! *%#* *"&$ *"&*$%#!
.5.9077.
9.. 1:3..9438
.7/1:3.7/:3.943 8 %9.7/
#089071:3.943.3/7...0/17429324:8047 04.3/04.943 473.34:/403 4::8090801:3.94382:890/430 9024:804704.7/
790901:3..1:3.$250&8073907.9438
W :94:80:3.7/.94394:80 . 204. 24:80 W :904.
3/.4/24:80 39:9943 3989..2504:80:3.90 39 39 :9943843041&%*%*&%% &%**&%% 47 &%*#%*&%% $9.7024:80548943.99092041 900.943
.039
.908&%*&! 47&%* .
:08903:20741508/43 1742 9094541903/4 347/0794800900110.9.98418420.30.0907285..943
%0..2504:80:3.:08903:20741508174290 01941903/4 %0.... 47:9!489#0/85.25024:80 83
.3/072:89.7/ 9024:8047 04.7/.941 9024:804704. 4/0147.
!4304397494:80
.250:80
.
439740/!430
.4/01474:80
.
24.&834:804943:3.9438
:94943:3.0/4:80 .
.
24. 24.88.0/9:99430//43 :9!.0/4:80 .04943:3.
.
308 :8390801:3.9..943883
.37:0770.0/4:80 39 39 .0394.24.0/9:99438:5 24.:770/ 4/0147/7.70 90548943419024:800390 0.3/.
..7/ :3830/.7900 3924:80 3924:80 3924:80 398.4/204.700309
24:80.7/:3.943
.25004.
.
49 70. .:089.15. 900 ...80 5 /7.
.
80 09
..924:80548943 ./7./49.
.
90905747.:970. .2 /01.90723.
.
/43493 < <
.
..70 3924:80 39 24:80 %0.700309 4/8..93917428. 70....3/0 ...:08$.
..25004.943.20907894901:3.4/0 #0202079403/0.447/3.80894.7.9.809.7/:3.89.90300/89401550/ 8:97..943
!.9.80 :3830/.008 0.
3090.0 &%203:8...0203:8 .490:80794.93..00/8
.830203:9...30 .&8303:8
49&%..3/& 203:8.943574.3/&2..9 .890.44741. 97.3/ 1479.55.708250 .70247054071: 0:/.8:3/:.
4/203: 393:2 .943
39:970..&%03:.9003: 203: 709:738203: .:3..
.
:0 .3/08.20 39.4..4/:9//03:397 ...7 3.03:2 .
.
.3/0 .4/:999.03: 39:9943 .:0:80/3203:89..0 .4..94.
.
&%*#%*&%%
.43041 &%*#%*&%% &%**&%% 47 &%*%*&%%
W
&8:.
7 3.//9942.3/8 903.422.90..90/
:9//$:03: .8:03:1789 :83203: .2.20 39203: .&%8:03:8
70.3203:9028 800.3203:
W
8:203:5458:503.
.
:0709:730/ :970.90/ 425090.9003:03908:203:.55..70.4/0147..9438 3 48:203:8.70:80/
. 203:890.&%03:.8 .
08.&39071.3/03:8
..
250 5747.93494 :80&39071..2:897.04594388.8003/4301474: 4:2.&39071.0 43440890 489419047.8901742900.:9.28390&/897:943
.3/5..08
30...2505747...
&%
'
##
.
0.3/ .88390.98./3
.447949040 208 5443
.425:909343./324/0
.!4438.
. W 08.44714790 5443 030191.07903472.8994.7./3
3:80430..98.071. 574507994..
.3/2.081.425:9090.425:90 &80/03
W !443882.7..907.034: W 984:7.
9 :2..0...3008..8:71.9
...3/0110.3/110..4393:9.9090 /8.3/0110.041.9904:3/..039:.9 ./38:110781742 2..0/390389
$/0.98..0
.5443.7
507.
.4393:9 425:9093147247054398430.1.00/0/8./3
$24498..0
.3/0110.9 7024./3
./3
902.98...$24498.
/3 :80/ 503 W !438.:/8.72094/8
W 4:7./3 09907850.:.79 349
3 503
.$24498./3
%4545:.
90/147390747508
.90/1470.4:7..:.:/$.4792:80/3 503 $./3
%0824498.079...70390754./3.08 4478.41905443./04/0 *$ % 938.
8
3 3 3 3 3 3 3 3 3 3 ..425:90/ ..03472.0790 !07
../3
!07
.:.07903472./:891.:/$..079093.4:7.07...390.8300/0/1470.30.943 472...
.
447390754.4:7.8.381472.7390754.70349300/0/
147..8.075
075 .447 01470905740.0790:23.3308
075
./3
425:90. 07530.943 .943
./0390747508.94397.943 3472.943 $.:/$.
.:/$.943
.4:7.7390754./3
30.
. . . .
. 390754.3/:80/89.90390747 50. .330 . .9097..094390754.90909403/ 543983908.
.447:80/89.30.

.3.094390754.4478
. .3.
:/$..4:7.90
./3!7402
933905443390747.30 3.:7...
943 300/94 2.90931470.5903472.908903472./3...4792390754.8907. 5038/0905443 5075093 00/3472..3/...9447/470085.094:
.8147.8 .!43$.90508 349574./0/:807 !438.:..425:9093/:737./3
3890./41390754.943 0.
075 3 3 075 3.7/./3
472. 3
3
3075 3 3
3 3
W
$4 3498:554790/ 503.390754.5.!43$.70
.3/ 24897.943
3.8.
&%
'
#%$
.
40.70.7 3.9438 7.9..9.425:9077.9.9.8 7. 1:3.98 .370..8.90.70 8.70801
82.50/017.
47/40.98010738.9.98
....8
7.9.5.425040.7014720/907.8..70042097.8 0:8017.8.943894.7.
.9.08
.7.4.8 $341.
.
.
.
943
.943
907.
0307.943
907.947
907.943
907.
%700
0307..943907.9.943907.943
.943907.947
907.7.943907.
947
907.943907.9.073
0307.943907.7.943
907.943
..
84.3.:7.0574/:..3/423088
%017.31.3.790039841 907.250 4:.08.3/ .7.3/907.3.7...0770:.3/.7. %4.3090.80 .//$420#.3.08420419010738 944308/0 470..3/423:2070307.3088984209208.82.947 470..250 4:..90842070..947
.80/ 43.0/841.9.791..70.9 825 .78002940 .
070 2/ .9. .3/424118097
787
.943 8:.90 .3/9009.8 .9909403/
54398.3/42411809 %884940307.9902/
5439 $:554809.3 #.99009.90907. .9 8 . 9...3/ $:5548090098390/70.9902/
54390 W 78907.70.02039
. %03 9009.0390098419403/
54398 0307.09.%077.3/42/
5439 85.
3
.37.947 ..3/ 7 8.3..3/ .:807
800.7.7.3/42.0920...:88.0
. 7 070
W W
88.90/ 74:3088 1.
9/897:943
.4940307.7.:88.90.3/423:2079. 574.3 473472.
.
037..3/423:2078./897:9431742
94 .3/906:.
.
3/93472./897:943.0307.903:2078.9
.039070/.
.
9 14...9 7.3/
<0
8679
4 .9 /4
14.4/.3/.3/989.3/
14.9 7.:88.3 14.943
.7//0.9 14.
<
.
0/:7.3.250
.%077.!74.
.38.38 84 .47921474924:39.5..894.209077.38..247070.47/ .939070.:/3.32.943 .89.9077..70.3/ 24:39.0908.09..3/903:80 17.0/11070398.907/08 .89.3/8.3/ 4907047.118 .3:. .508 10.3
49.08 9 708:93:370.9.209078147.9:708 ...7.3/24:39.08 .70.508 %0701470 :80/11070395.10.03
443.08...3
0307.3/.90/09..74:3088
.
943! !
! ! ! ! W ! !
.50 W 4420/8.508002470/09.824498 44234317.79090035.9:708419040.398 10. W $002470/09.039:.075439 $0182.990738 0307.9078 1:7 5..10.. W 0.3 .4:/8.3/4../.07.9 442394:.907 97008 5.38.06:.7.90. W 40834982449 4/0 W %077.8
31390/09.9.9.798.
$0182.7
W 557.31.798 W :80/11070398.798
$9..7.078438419003970 40.208.94781478:5.989..798..708.0//43.943948:5.943
...3438:5.9
W :808.9.798
W %7008 87:8 4907.009.8
!..801
82.717..3/42.
9433.9.7.731:3.8
.907 ..7.94:809 W $6:.8
W W W
:.9508
$9.07843574.8098
W
4330..9438
W $0186:..7...4:/8 3.0 .731:3.989.3/42.797.9433.9438
W $$$
W 9077.078017.425085.9.
.381472.9.3/0749809 W $6:.3917.0 3.1130
W
7..0/:708
W $01
3...3 .9.7317..425085.801
.
 W 42503:207 4/::8 W $679 .
. W .943139 W $420/430907 W 4:3/.3/9480.732.94:
40.94:.731.7/
W 124/::8 W $6:.0894 94.94:$09
:.709003 3:2078.  W 124/::8 W $6:.894.943139 W :.1.
.7/8 3139 124/::8 W $4201.
. 1.3/0749
:.94 074.3/ .94074 W $4201.
.
.508.08 3/ 0/943
.8
!73.9..5.2425:9077..3.3/ !7.
40.
447905439841..08 3/ 0/943
:.3/900398 349.5...9438884:98/0.03908098.43 /
$./8/0130/24/::8
.3/0749.4479.799.2425:9077..088.94:. 90 490780.508.3/ .
W 1. %409. 89.3/0749809 80941343
/.
.90/.3/ !7.504190:...4330.54880.4330.190790907.3..13903:207419208 8.
.:041.42503:207
W 5594 .9. W 4479054398.07354398 W 4770.8098147.902094/ W 470.92094/ W 425:9090:.94:809.. W !74.8
!73.80/43..90/ W 55742.
947
0307.088:5.50
0307.03042097. 801
82.43897:.93.705.947
.7984139.
39.947
4.99073..0
789907./09072389.717.943
39.8.947
W !.:7.9..947
W .
947 W 33:207418:5..838
/ W 88.9:70 W 0.0/ W ./
088./203843 W 24:3941.7...0/ $0182.98 W 38/ $42044879098..943390897:.9.9.70/
2470..740.31./203843
17.943419040.2039.7.79838:/.843 W /3 3 .9 W $2.8:704174:30884717.
3 .
8 W /3 3 .
3802039./418.078:842:. 902.0/ W 030/./0/39480203983890.870/:.3 8 40.0788903:207418020398.390308.
3890.70802039849.09./9070.9. 8.
.
70/11070398..31. ( W 19070..9478
W W
3
$/
.
.31.:734:98.9478 57010738
//3 3 ..
9441 90 3080 .3 8
2038438.7.
0
W
1907/.203843
W
3./0303943/039.08020398
W W
. 8020398
W
38
W 3 308020398 W 8 4/8020398 W 7. 88341. 4/80
4...843..9.
86:.708 /.303943 /039.8020398
W
474:77010703..0/.70 39482.0442094/
W 3
W W
:20741308020398 802039870/:../30./03084386:.3
.
86:.708 0938 82./0.:0
W
W 8.
W
38 82..:08
W
.
W /3.
3 .
.
.
0897.$07538.9.8097.30
8 3080203981742430 4/802039 3 .8/0
W W W W
.30817424/
97... 203843
./00.308 0005 %07014703
W 093097.
9./203843
W
..3
7.
8/0
W 8
7.9..:0 3044 45:84:990.9..01742 45:84:9902//01.203843
5517..8/0 2.9.0
.0/.989017.0
.4792
W W W W W W
./2038433
.0410./203843
W 3
0../00.039074190.9..:0 00..:08 0700:80/94.....:07..../0/0.
3
.
3.3:.88 0307.041 802039837.098 39070893 :9. 9700
..9:70 7.0.80/4/0841 0307.09 (< #:08 ((
W W W W W
((
((((((
$9.9047/8
#057080398806:03.5 897:.97.39..932.5.08
%5..793.
80/4/0841 0307.098
.5 897:.0..3:.041 802039837.3.09 ( < #:08
W W W W W
( ( ( (
( (0197.3.3.08.9:70 7.9047/8
#057080398806:03.43 /
4/15.$9.88
0307. 79 7.97.793..932.
34/08
.80/24/0706:708 W 7.39075709.0.3:.917429047/ 8.22.308 W 448094/7.088 W 0.3.7 W 042097.9 90723.0843909700/7.88:.14078470.7.9:5.08 9082.93.80/24/08.0 82.8020398 419700.943 0307.7/..3.90574.805.3 .8 W 7.3..088.034 307039042097
7.340.22.070398 W %0247097.89 7...08.7.0790.2508 W 7.
5
40.22..3.47/394/05941 7..7.3/042097
.80.307.7.
.508.8
!73..5.3.2425:9077.3/ !7.08 3/ 0/943
.9..
.84124943 W 302.02039 W 09072389.7174288902 W 4.79.79. W 147.7....90305.5085.90/ W .79.3.3/3 254/3 054/3 W ..997:908.089.04.90/ W %7.79.003/090.50 W $5070 4 0584/ 09.08/0 /8.9.5.385.9.0 W .4.!.07920 W !.9
.38..89.40.30.0.08.79.01:/
0574507908 W 43 43 85.088:.8.79.08 W . W 55574.4.943415.7:08945.0$89028
$89028/0130/..79.90.08 W 0307.30..79..44785.550.07920 W !.98.79.87.89.47894.99073 05.47/394..003/090.
885.0.0$8902824/03
4/0 W 70 14 8240 170478 97008 7.907857.081.:5
.943 W 010.79.174210/00.89474:3/ W /745 974..90/489. W !.08 .!. .. 7.9071.79..88 .9.9071.:25880993:597.79. 1383544 W 745 4944994241544 14.0.88 W 4/0.9475.981475.
993094741543934/08 .39 W 4240304:840.907. 4:/24/090.0438573 4:/.08 W 55742.473907284109073.9 W #450 .49 84197:07..!8..2508573898573.4330.90/100. W 320897.. W 8
W /85.4330.2.943 W . 440 8.4389.30307
.8424/095:99 /4083 98573.3/39073.147.9 W 806:.909040.80/24/03
43
7/40. 04 08..02039 8 7089473147.700..89..
3094
/07008
## .5.0
.3/ .88
W
4.:39 %:73019 #%:7379
W W W
$95:.30
W W W W W
.30
###
..0147.30.97.0 8341.03174230 44
.:7.3
%:7907.9438 .907.30419:738 6:.91.2509.909:790/70.
%:790.8
4..7/.
&839:790 7.08( #(( 30 49085..9 #((##((( #((#((( #((
.08 147 70.5.814797008
&805:8.3/5451478/0 7.3./.