Professional Documents
Culture Documents
Geometrical Transformation
2D Transformation
2D Matrix Transformation
a b e f ae bg af bh
………………………….… (1)
c d g h ce dg cf dh
For example,
3 1 1 2 3 1 1 2 3 2 1 0 1 6
2 1 2 0 2 1 1 2 2 2 1 0 4 4
2D Transformation
1 2 3 1 5 1
2 0 2 1 6 2
3 1 1 2 1 6
2 1 2 0 4 4
2D Transformation
3 1 1 2 1 0 3 1 5 2 13 6
2 1 2 0 2 1 2 1 2 0 12 4
2D Translation
Translation is the ability to reposition an image or object along a straight
line path from one location to another.
The translation transformation shifts all points by the same amount.
Therefore, in 2-D, we must define two translation parameters:
• the -translation
• the -translation
To translate a point to we add on a vector :
px ………………………………………………….……….. (2)
P
py
px ………………………………………………….……….. (3)
P
py
tx
T ………………………………………………….……….. (4)
ty
Cont’d
………………………………………………….……….. (5)
Therefore, from Eq. (5) we can see that the relationship between points
before and after the translation is:
Translation by
2D Rotation
Sx 0
S ………………………………………………….……….. (12)
0 S y
px S x 0 px
………………………………………………….……….. (13)
p 0 S y p y
y
Cont’d
A 2-D Scaling by
Homogeneous Coordinates
px
………………………………………………….……….. (16)
P py
1
px
P py ………………………………………………….……….. (17)
1
1 0 tx
T 0 1 ty ………………………………………………….……….. (18)
0 0 1
px 1 0 t x px
p
y 0 1 t y p y ………………………………………………….……….. (19)
1 0 0 1 1
Cont’d
cos sin 0
R sin cos 0 ………………………………………………….……….. (20)
0 0 1
Sx 0 0 ………………………………………………….……….. (22)
S 0 Sy 0
0 0 1
px S x 0 0 px
py 0 Sy 0 p y ………………………………………………….……….. (23)
1 0 0 1 1
2 1…………………………………………………………………………………..…………..(24)
Cont’d
The composite matrix C can now be computed from the three constituent
matrices T2, R and T1,
• and represents a rotation about the pivot point (2,2) by θo.
Note from Eq. (24) that 𝟏 is applied first, followed by and then 2.
For instance, if we were to apply the three transformations to a point P the result
would be
2 1
3D Matrix Transformation
The 3-D homogeneous coordinate’s translation matrix is similar in form to the 2-D
matrix, and is given by:
1 0 0 t
0 1 0 ty ………………………………………….. (25)
T
0 0 1 tz
0 0 0 1
px 1 0 0 t px
py 0 1 0 t y p y
p 0
0 1 t z pz ………………………………………….. (26)
z
1 0 0 0 1 1
Similarly, 3-D scaling are defined by three scaling parameters, Sx, Sy and Sz.
The matrix is:
Sx 0 0 0
0 Sy 0 0
S
0 0 Sz 0
0 0 0 1
1 0 0 0
0 cos sin 0
Rx
0 sin cos 0
0 0 0 1
For a rotation about the the matrix is:
cos 0 sin 0
0 1 0 0
Ry
sin 0 cos 0
0 0 0 1
3D Rotation homogeneous coordinates
cos sin 0 0
sin cos 0 0
Rz
0 0 1 0
0 0 0 1
OpenGL Rotation Function
glTranslatef( , , 0.0f);
To turn on and off many of these states, use these two simple commands:
• void glEnable(GLenum cap);
• void glDisable(GLenum cap);
glEnable() turns on a capability, and glDisable() turns it off.
The glEnable function is used to enable specific OpenGL capabilities.
It takes a single argument ‘cap’ which is an enumeration (GLenum)
representing the capability to be enabled.
Examples
To control the size of a rendered point, use glPointSize() and supply the desired size
in pixels as the argument.
void glPointSize(GLfloat size);
• Sets the width in pixels for rendered points; size must be greater than 0.0 and
by default is 1.0.
• if the width is 1.0, the square is 1 pixel by 1 pixel;
• if the width is 2.0, the square is 2 pixels by 2 pixels, and so on.
Lines Details
With OpenGL, you can specify lines with different widths and lines that are stippled
in various ways :
• dotted,
• dashed,
• drawn with alternating dots and dashes, and so on.
Wide Lines
void glLineWidth(GLfloat width);
Sets the width in pixels for rendered lines; width must be greater than 0.0 and by
default is 1.0.
Cont’d
Stippled Lines
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, 0x3F07);
Cont’d
Polygons are typically drawn by filling in all the pixels enclosed within the boundary,
but you can also draw them as outlined polygons or simply as points at the vertices.
A filled polygon might be solidly filled or stippled with a certain pattern.
By default, both front and back faces are drawn in the same way.
To change this, or to draw only outlines or vertices, use glPolygonMode().
glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_LINE);
Stippling Polygons
glEnable(GL_POLYGON_STIPPLE);
Normal Vectors
A normal vector (or normal, for short) is a vector that points in a direction that’s
perpendicular to a surface.
An object’s normal vectors define the orientation of its surface in space in
particular, its orientation relative to light sources.
Cont’d
normal vectors are essential for simulating realistic lighting and shading effects in
computer graphics. glVertex3f(0.0, 0.0, 3.0); // length
glVertex3f(0.0, 0.0, 0.0);
You may have noticed that OpenGL requires many function calls to render
geometric primitives.
Drawing a 3−sided polygon requires 5 function calls:
• one call to glBegin(), one call for each of the vertices, and a final call to glEnd().
• Generally, to draw sided polygon, call.
In the others code, additional information (polygon boundary edge flags or surface
normal) added function calls for each vertex.
This can quickly double or triple the number of function calls required for one
geometric object.
For some systems, function calls have a great deal of overhead and can hinder
performance.
Cont’d
OpenGL has vertex array routines that allow you to specify a lot of vertex−related
data with just a few arrays and to access that data with equally few function calls.
Using vertex array routines, all vertices in a −sided polygon could be put into
Arranging data in vertex arrays may increase the performance of your application.
ii. Put data into the array or arrays. The arrays are accessed by the addresses
iii. Draw geometry with the data. OpenGL obtains the data from all activated
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
static GLint vertices[] = {25, 25, static GLfloat colors[] = {1.0, 0.2, 0.2,
glDrawArrays(GL_POLYGON, 0, 3);