Chapter 03 Computer Graphics
Chapter 03 Computer Graphics
Transformation
Instructor
LE Thanh Sach, Ph.D
Contact
Geometry
Representation
Geometric Transformation
Transformation in OpenGL
Building Models
v w
v -v v
u
Computer Graphics: Chapter 03 – Transformation Slide: 11
Linear Vector Spaces
Mathematical system for manipulating vectors
Operations
Scalar-vector multiplication u=v
Vector-vector addition: w=u+v
Expressions such as
v=u+2w-3r
Make sense in a vector space
Location in space
Operations allowed between points and
vectors
Point-point subtraction yields a vector
Equivalent to point-vector addition
v=P-Q
P=v+Q
Q Q
P() P(, b)
Computer Graphics: Chapter 03 – Transformation Slide: 22
Planes
Q
R u R
P(,b)=R+u+bv P(,b)=R+(Q-R)+b(P-Q)
u
P
Computer Graphics: Chapter 03 – Transformation Slide: 25
Representation
v=2v1+3v2-4v3
a=[2 3 –4]T
Note that this representation is with respect
to a particular basis
For example, in OpenGL we start by
representing vectors using the object basis
but later the system needs a representation in
terms of the camera or eye basis
Computer Graphics: Chapter 03 – Transformation Slide: 32
Coordinate Systems
Which is correct?
v
v
u1 = g11v1+g12v2+g13v3
u2 = g21v1+g22v2+g23v3
u3 = g31v1+g32v2+g33v3
u1 = g11v1+g12v2+g13v3
u2 = g21v1+g22v2+g23v3
u3 = g31v1+g32v2+g33v3
Q0 = g41v1+g42v2+g43v3 +g44P0
defining a 4 x 4 matrix g g g
g g
M = g
g g g
g g g
Computer Graphics: Chapter 03 – Transformation Slide: 44
Working with Representations
Q=T(P)
Line preserving
Characteristic of many physically important
transformations
Rigid body transformations: rotation, translation
Scaling, shear
Importance in graphics is that we need only
transform endpoints of line segments and let
implementation draw line segment between the
transformed endpoints
frame
u T(u) buffer
transformation rasterizer
T(v) T(v)
v
T(v)
v
T(u)
u T(u)
vertices vertices pixels
d
P
0 0 1 d z
T = T(dx, dy, dz) =
0 0 0 1
x = r cos f
y = r sin f
cos q sin q 0 0
sin q cos q 0 0
R = Rz(q) = 0 0 1 0
0 0 0 1
sx 0 0 0
0 sy 0 0
S = S(sx, sy, sz) = 0 0 sz 0
0 0 0 1
sx = -1 sy = 1 original
sx = -1 sy = -1 sx = 1 sy = -1
1 cot q 0 0
0 1 0 0
H(q) =
0 0 1 0
0 0 0 1
We want C = T –1 R T
so we must do the operations in the following order
CI
C CT -1
C CR
C CT
Multiply on right:
glPushMatrix()
glPopMatrix()
Consider a mesh e2 v5
v6 e9 e3
e8 v v4
8
e1 e11
e10
v1 e7 v7 e4
v2 e12
e6 e5 v3
There are 8 nodes and 12 edges
5 interior polygons
6 interior (shared) edges
Each vertex has a location vi = (xi yi zi)
Computer Graphics: Chapter 03 – Transformation Slide: 98
Simple Representation
void colorcube( ) 5 6
{
polygon(0,3,2,1);
polygon(2,3,7,6); 2
polygon(0,4,7,3);
1
polygon(1,2,6,5);
polygon(4,5,6,7); 7
4
polygon(0,1,5,4);
} 0 3
Note that vertices are ordered so that
we obtain correct outward facing normals
Method 2:
glDrawElements(GL_QUADS, 24,
GL_UNSIGNED_BYTE, cubeIndices);