Opengl Primitives: CSE 320 Graphics Programming
Opengl Primitives: CSE 320 Graphics Programming
OPENGL PRIMITIVES
CSE 320
GRAPHICS PROGRAMMING
2D Transformations
• Rotation
• Scaling
• Uniform Scaling
• Un-uniform Scaling
• Reflection
• Shear
Translation
• A translation moves all points
in an object along the same
straight-line path to new
positions.
• The path is represented by a
vector, called the translation or P'(8,6)
shift vector.
• We can write the components:
p'x = px + tx t y=4
p'y = py + ty
P(2, 2) t x= 6
• or in matrix form:
P' = P + T
x' x tx
y' = + ty
y
Rotation
• A rotation repositions
all pointsin an object
along a circular path in
the plane centered at P
the pivot point.
• First, we’llassume
the pivot is at the P
origin.
Rotation
• Review Trigonometry
=> cos = x/r , sin = y/r
• x = r. cos , y = r.sin
P’(x’, y’)
P’(x’, y’)
• or in matrix form:
P' = R • P
can be clockwise (-ve) or
counterclockwise (+ve as our
example). y’ P(x, y)
• Rotation matrix
cos sin r y
R
sin cos x’ x
Scaling
• Scaling changes the size of an
object and involves two scale
factors, Sx and Sy for the x- and
y- coordinates respectively. P’
• Scales are about the origin.
• We can write the components:
p'x = sx • px
p'y = sy • py
or in matrix form: P
P' = S • P
Scale matrix as:
s 0
Sx
0 s
y
Scaling
•If Sx Sy differential P
(1 2)
scaling.
•Change in size and shape
•P(1, 3), Sx = 2, Sy = 5
General pivot point rotation
• Translate the object so that pivot-
position is moved to the coordinate origin
• Rotate the object about the coordinate origin
• Translate the object so thatthe pivot
point is returned to its original position
(xr,yr)
(xf,yf)
(a) (b)
Translation of (c) (d)
Original Position
of Object and object so that scaling was Translation of the object
Fixed point fixed point about so that the Fixed point
(xf,yf)is at origin origin is returned to position
(xf,yf)
Composite Transformations
(A) Translations
If two successive translation vectors (tx1,ty1) and (tx2,ty2) are applied to a
coordinate position P, the final transformed location P’ is calculated
as: -
P’=T(tx2,ty2) . {T(tx1,ty1) .P}
={T(tx2,ty2) . T(tx1,ty1)} .P
Where P and P’ are represented as homogeneous-coordinate column
vectors. We can verify this result by calculating the matrix product for
the two associative groupings. Also, the composite transformation
matrix for this sequence of transformations is: -
1 0 tx2 • 0 • 0 tx1+tx2
0 1 ty2 tx1
= 0 1 ty1+ty2
0 0 1 . 0 1 ty1 0 0 1
Or, T(tx2,ty2) . T(t
0 ,t ) = T(t +t , t +t )
x1 y1 x1 x2 y1 y2
0
Which demonstrate that 1 two successive translations are additive.
(B) Rotations
Two successive rotations applied to point P produce the transformed
position: -
P’= R(Ө2) . {R(Ө1 ) . P}
= {R(Ө2) . R(Ө1)} . P
By multiplication the two rotation matrices, we can verify that two
successive rotations are additive:
R(Ө2) . R(Ө1) = R (Ө1+ Ө2)
So that the final rotated coordinates can be calculated with the
composite rotation matrix as: -
P’ = R(Ө1+ Ө2) . P
(C) Scaling
Concatenating transformation matrices for two successive scaling
operations produces the following composite scaling matrix: -
Sx2 0 0 Sx1 0 0 0 0
Sx1 . Sx2
0 Sy2 0 . 0 Sy1 0 = 0 Sy1 .Sy2
0
0 0 1 0 0 1 1
0 0
1 0 0
2 3
0 -1 0
2’ 3’
0 0 1
1’
Reflected
position
Reflection
-1 0 0
0 1 0
0 0 1
Reflection
Reflection of an object relative to an axis perpendicular to the
xy plane and passing through the coordinate origin
Y-axis
-1 0 0
Reflected position 0 -1 0
3’
0 0 1
2’
1’ The above reflectionmatrix is
Origin O X-axis the rotation matrix with
1 (0,0) angle=180 degree.
2 This can be generalized to any
reflection point in the xy plane.
3 This reflection is the same as a
180 degree rotation in the xy
Original
plane using the reflection point
position
as the pivot point.
Reflection of an object w.r.t the
straight line y=x
0 1 0
Y-axis
Original position 1 0 0
3
0 0 1
2 1
1’
3’
Reflected position
2’
OriginO X-axis
(0,0)
Reflection of an object w.r.t the
Y-axis
straight line y=-x
-1
0
OriginO 2 -1
(0,0) 3
Original position 0
1
1’ 0
2’ Line Y = - X 0
3’
Reflected position 0
Reflection of an arbitrary axis
y=mx+b
Original position
3
2 1
Original position Translation so that it passes through origin
3 Rotate so that it coincides with x-
Original position axis and reflect also about x-axis
3
2 1
2 1
Original position
2 3
1
1’
Rotate back Translate back
Original position Original position
3 Reflected position
3
2’ 3’
2
2 1 1
1’ Reflected position 1’
3’
3’
2’ Reflected position
2’
Shear Transformations
1 0 0 1 shx 0
shy 1 0 0 1 0
0 0 1 0 0 1
An X- direction Shear
(2,1) (3,1)
(1,1)
(0,1)
( (0,0) (1,0)
0,0) (1,0)
An Y- direction Shear
Y Y (1,3)
(1,2)
(1,1)
(0,1) (0,1)
X X
( (0,0)
0,0) (1,0)
CONCLUSION