Date post: | 22-Dec-2015 |
Category: |
Documents |
Upload: | alberta-day |
View: | 228 times |
Download: | 1 times |
3D Translation
• Remembering 2D transformations -> 3x3 matrices, take a wild guess what happens to 3D transformations.
1000
100
010
001
,,
100
10
01
,
z
y
x
z
y
x
zyx
y
x
y
xyx
t
t
t
t
t
t
z
y
x
tttT
t
t
t
t
y
xttT
T=(tx, ty, tz)
3D Scale
1000
000
000
000
*
00
00
00
,,
100
00
00
*0
0,
z
y
x
z
y
x
zyx
y
x
y
xyx
s
s
s
z
y
x
s
s
s
sssS
s
s
y
x
s
sssS
S=(sx, sy, sz)
3D Rotations
R=(rx, ry, rz, )What does a rotation in 3D mean?
Q: How do we specify a rotation?
A: We give a vector to rotate about, and a theta that describes how much we rotate.
Q: Since 2D is sort of like a special case of 3D, what is the vector we’ve been rotating about in 2D?
Rotations about the Z axis
R=(0,0,1,)
What do you think the rotation matrix is for rotations about the z axis?
1000
0100
00cossin
00sincos
),1,0,0(
100
0cossin
0sincos
cossin
sincos
R
R
Rotations about the X axis
R=(1,0,0,)
Let’s look at the other axis rotations
1000
0cossin0
0sincos0
0001
),0,0,1(
R
Rotations around a principle axis
1000
0100
00cossin
00sincos
),1,0,0(
R
1000
0cos0sin
0010
0sin0cos
),0,1,0(
R
1000
0cossin0
0sincos0
0001
),0,0,1(
R
xyzyx RRRRRR 11
Rotations for an arbitrary axis
Steps:1. Normalize vector u2. Compute 3. Compute 4. Create rotation matrix
u
Vector Normalization
• Given a vector v, we want to create a unit vector that has a magnitude of 1 and has the same direction as v. Let’s do an example.
V
VVNormalized _
Computing the Rotation Matrix
• 1. Normalize u ( the vector we are rotating around )
• 2. Compute Rx(x)
• 3. Compute Ry(y)
• 4. Generate Rotation Matrix
xy
y
yx
z
z
zx
zy
z
zy
zyx
dd
duu
uu
u
u
d
u
sin
cos
sin
'
'cos
),,0('
)1,0,0(
),,(
22
Rotations for an arbitrary axis
xy
y
yx
z
z
zx
zy
z
zy
zyx
dd
duu
uu
u
u
d
u
sin
cos
sin
'
'cos
),,0('
)1,0,0(
),,(
22
Rotations for an arbitrary axis
xy
y
yx
z
z
zx
zy
z
zy
zyx
dd
duu
uu
u
u
d
u
sin
cos
sin
'
'cos
),,0('
)1,0,0(
),,(
22
Euler Angles
More intuitive: represent rotations by 3 angles, one for each axis
glRotatef(anglex,1,0,0);glRotatef(angley,0,1,0);glRotatef(anglez,0,0,1);
Think: if we have a torus unstranformed at the origin, what will the torus look like if you have anglex=90, angley=90, and anglez=90
Transformed
Gimbal LockRotate around these
How can we gain altitude here?
Initial orientation (x=blue, y=green, z = red)
Gimbal Lock in OpenGL
What is the problem here?
glRotatef(anglex,1,0,0);glRotatef(angley,0,1,0);glRotatef(anglez,0,0,1);
Avoiding Gimbal Lock: Quaternions
• Quaternions represent 3D rotations in 4D using imaginary numbers – a 4-tuple Q = (w,x,y,z)
• Convert Angle-axis -> Quaternion
• (,x,y,z) -> ( cos( /2), xsin(/2), ysin(/2), zsin(/2) )
• Why quaternions?
• No gimbal lock
• Smooth interpolation between rotations (for animation)
Quaternions
• Quaternions have rules for multiplication, inversion, etc
• See: http://www.j3d.org/matrix_faq/matrfaq_latest.html
• Typical usage:
• Convert from euler, matrix, or angle-axis
• Do rotations
• Convert to angle-axis or matrix
gluLookAt
Orients and positions the “camera”
gluLookat(eyex, eyey, eyez,centerx, centery, centerz, upx,upy, upz);
eye – the position of the camera in world coordinatescenter – the camera is pointed at this pointup – the direction defined to be up for the camera
Cross Products
Given two vectors, the cross product returns a vector that is perpendicular to the plane of the two vectors and with magnitude equal to the area of the parallelogram formed by the two vectors.
u
Let’s Examine the Camera
• If I gave you a world, and said I want to “render” it from another viewpoint, what information do I have to give you?– Position
– Which way we are looking
– Which way is “up”
– Aspect Ratio
– Field of View
– Near and Far
Graphics Pipeline So FarObject
Object Coordinates
Transformation
Object -> World
World
World Coordinates
Projection Xform
World -> Projection
Camera
Projection Coordinates
Screen
Device Coordinates
Normalize Xform & Clipping
Projection -> Normalized
Viewport
Normalized Coordinates
Viewport Transform
Normalized -> Device