Geometry Transformations: 1 MCA 401A - Computer Graphics, Dept of Computer SC, M U
Geometry Transformations: 1 MCA 401A - Computer Graphics, Dept of Computer SC, M U
***
Q=T(P)
frame
u T(u) buffer
transformation rasterizer
v T(v) T(v)
T(v)
v
T(u)
u T(u)
vertices vertices pixels
p, q, r: representations of points
-array of 4 scalars in homogeneous coordinates
u, v, w: representations of points
-array of 4 scalars in homogeneous coordinates
P
Displacement determined by a vector d
Three degrees of freedom
P’ = P + d
z’=z+dz
MCA 401A - Computer Graphics, Dept of Computer Sc, M U 9
Translation Matrix
We can also express translation using a
4 x 4 matrix T in homogeneous coordinates
p’=Tp where 1 0 0 d x
0 1 0 dy
T = T(dx, dy, dz) = 0 0 1 dz
0 0 0 1
This form is better for implementation because all affine transformations can be
expressed this way and multiple transformations can be concatenated together
x’ = x cos q – y sin q
y’ = x sin q + y cos q
x = r cos f
y = r sin f
p’=Rz(q)p
1 0 0 0
0 cos q - sin q 0
R = Rx(q) = 0 sin q cos q 0
0 0 0 1
cos q 0 sin q 0
0 1 0 0
R = Ry(q) =
- sin q 0 cos q 0
0 0 0 1
MCA 401A - Computer Graphics, Dept of Computer Sc, M U 14
Scaling
Expand or contract along each axis (fixed point of origin)
x’ = sx x
y’ = sy x
z’ = sz x
p’ = S p
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
R -1(q) = R T(q)
Scaling: S-1(sx, sy, sz) = S(1/sx, 1/sy, 1/sz)
x’ = x + y cot q
y’ = y
z’ = z
1 cot q 0 0
0 1 0 0
H(q) =
0 0 1 0
0 0 0 1
C
p p’=Cp
CI
C CT -1
C CR
C CT
Note that the last operation specified is the first executed in the program
Multiply on right:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(1.0, 2.0, 3.0);
glRotatef(30.0, 0.0, 0.0, 1.0);
glTranslatef(-1.0, -2.0, -3.0);
Remember that last matrix specified in the program is the first applied
glLoadMatrixf(m)
glMultMatrixf(m)
glPushMatrix(); glPushMatrix();
glPopMatrix(); glTranslatef (...);
glRotatef(...);
glTranslatef
/*.. draw object .. */
glPopMatrix();
MCA 401A - Computer Graphics, Dept of Computer Sc, M U 41
Reading Back Matrices
Can also access matrices (and other parts of the state) by query
functions
glGetIntegerv
glGetFloatv
glGetBooleanv
glGetDoublev
glIsEnabled
For orientating an object, we can use the fact that every rotation
corresponds to part of a great circle on a sphere
Find the axis of rotation and angle
Virtual trackball (see text)
Use the final positions to determine the axis and angle of rotation, then
increment only the angle
Quaternions can be more efficient than either
q=q0+q1i+q2j+q3k
Quaternions can express rotations on sphere smoothly and efficiently.
Process:
Model-view matrix quaternion
Carry out operations with quaternions
Quaternion Model-view matrix
Generally it is a good idea to look for data structures that separate the
geometry from the topology
Geometry: locations of the vertices
Topology: organization of the vertices and edges
Example: a polygon is an ordered list of vertices with an edge connecting
successive pairs of vertices and the last to the first
Topology holds even if geometry changes
• Note that vertices are ordered so that we obtain correct outward facing
normals
MCA 401A - Computer Graphics, Dept of Computer Sc, M U 63
Efficiency
The weakness of our approach is that we are building the model in the
application and must do many function calls to draw the cube
Drawing a cube by its faces in the most straight forward way requires
6 glBegin, 6 glEnd
6 glColor
24 glVertex
More if we use texture and lighting
glDrawElements(GL_QUADS, 24,
GL_UNSIGNED_BYTE, cubeIndices);