Documente Academic
Documente Profesional
Documente Cultură
Assignment 1
3D Primitives and Transformations
v2
glVertex3fv(v2);
glVertex3fv(v3);
v0
v4
glVertex3fv(v4);
v5
glVertex3fv(v5);
glEnd();
v1
v3
Primitive Types
GL_POINTS
GL_LINE
{S | _STRIP | _LOOP}
GL_TRIANGLE
{S | _STRIP | _FAN}
GL_QUAD
{S | _STRIP}
GL_POLYGON
GL_POLYGON
List of vertices defines polygon edges
Polygon must be convex
Non-planar Polygons
Imagine polygon with non-planar vertices
Some perspectives will be rendered as concave
polygons
These concave polygons may not rasterize
correctly
Single Buffering
Buffer corresponds to frame buffer
Single corresponds to there being just one
Place where you write pixel color values is same place
graphics hardware goes to read color values for display
Can draw on top of existing image
Might be faster than redrawing whole image
Can also lead to flickering and half-drawn images
Double Buffering
OpenGL writes raster image to separate buffer from that read for
display
front buffer is for video signal
back buffer is the drawing target
After each frame is drawn, the front and back buffers swap
glxSwapBuffers (Display *dpy, Window, w)
glutSwapBuffers (void)
Avoids displaying partially rendered frame buffer
Avoids flickering
r
0
0 0 0
s 0 0
0 t 0
0 0 1
Scaling
1
0
0
1
0
0
0 x
0 y
1 z
0 1
Translation
Rotation in 3-D
Looks similar to 2-D Case
Specify arbitrray rotation as
three angles
One per coordinate axis
Called an Euler Angle
Common representation
Rotation x
0
1
0 cos
0
sin
0 sin
0
0
cos
0
Rotation y
sin
0
cos
sin
0
0
cos
0
0 sin
1
0
0 cos
0
0
sin
cos
0
0
0
0
1
0
0
0
0 0
0 0
1 0
0 1
3-D Rotation
General rotations in 3-D require rotating about an
arbitrary axis of rotation
Deriving the rotation matrix for such a rotation
directly is a good exercise in linear algebra
Standard approach: express general rotation as
composition of canonical rotations
Rotations about X, Y, Z
= -(90 - ) = - 90
dist = ?
Composing Matrices
So we have the following matrices:
p: The point to be rotated about A by
Ry : Rotate about Y by
Rx : Rotate about X by
Rz : Rotate about Z by
Rx -1: Undo rotation about X by
Ry-1 : Undo rotation about Y by
In what order should we multiply them?
Compositing Matrices
Short answer: the transformations, in order, are
written from right to left
In other words, the first matrix to affect the vector goes next
to the vector, the second next to the first, etc.
So in our case:
p = Ry-1 Rx -1 Rz Rx Ry p
Rotation Matrices
Notice these two matrices:
Rx : Rotate about X by
Rx -1: Undo rotation about X by
How can we calculate Rx -1?
Rotation Matrices
Notice these two matrices:
Rx : Rotate about X by
Rx -1: Undo rotation about X by
How can we calculate Rx -1?
Obvious answer: calculate Rx (-)
Clever answer: exploit fact that rotation matrices are
orthonormal
Rotation Matrices
Notice these two matrices:
Rx : Rotate about X by
Rx -1: Undo rotation about X by
How can we calculate Rx -1?
Obvious answer: calculate Rx (-)
Clever answer: exploit fact that rotation matrices are orthonormal
Rotation Matrices
Orthonormal matrix:
orthogonal (columns/rows linearly independent)
normalized (columns/rows length of 1)
e
i
f
j
d
h
e
i
f
j
b
c
e
f
i
j
Rotation Matrix
9 DOFs must reduce to 3
Rows must be unit length (-3 DOFs)
Rows must be orthogonal (-3 DOFs)
Drifting matrices is very bad
Numerical errors results when trying to gradually rotate matrix
by adding derivatives
Resulting matrix may scale / shear
Gram-Schmidt algorithm will re-orthogonalize your matrix
Euler Angles
( x, y, z) = RzRyRx
Rotate x degrees about x-axis
Rotate y degrees about y-axis
Rotate z degrees about z-axis
Euler Angles
Rotations not uniquely defined
ex: (z, x, y) = (90, 45, 45) = (45, 0, -45)
takes positive x-axis to (1, 1, 1)
cartesian coordinates are independent of one another, but
Euler angles are not
Gimbal Lock
Term derived from mechanical problem that arises in
gimbal mechanism that supports a compass or a gyro
Gimbal Lock
Gimbal Lock
Occurs when two axes are
aligned
Second and third rotations
have effect of transforming
earlier rotations
ex: Rot x, Rot y, Rot z
If Rot y = 90 degrees, Rot z ==
-Rot x