![Page 1: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/1.jpg)
Computer Graphics (Fall 2008)Computer Graphics (Fall 2008)
COMS 4160, Lecture 4: Transformations 2
http://www.cs.columbia.edu/~cs4160
![Page 2: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/2.jpg)
To DoTo Do
Start doing assignment 1 Time is short, but needs only little code [Due Thu Sep 25, 11:59pm] Ask questions or clear misunderstandings by next lecture
Specifics of HW 1 Last lecture covered basic material on transformations in 2D. You
likely need this lecture though to understand full 3D transformations
Last lecture had some complicated stuff on 3D rotations. You only need final formula (actually not even that, setrot function available)
gluLookAt derivation this lecture should help clarifying some ideas
Read bulletin board and webpage!!
![Page 3: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/3.jpg)
OutlineOutline
Translation: Homogeneous Coordinates
Transforming Normals
Rotations revisited: coordinate frames
gluLookAt (quickly)
Exposition is slightly different than in the textbook
![Page 4: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/4.jpg)
TranslationTranslation
E.g. move x by +5 units, leave y, z unchanged
We need appropriate matrix. What is it?
transformation_game.jar
' 5
' ?
'
x x x
y y y
z z z
![Page 5: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/5.jpg)
Homogeneous CoordinatesHomogeneous Coordinates
Add a fourth homogeneous coordinate (w=1)
4x4 matrices very common in graphics, hardware
Last row always 0 0 0 1 (until next lecture)
' 1 0 0 5 5
' 0 1 0 0
' 0 0 1 0
' 0 0 0 1 1 1
x x x
y y y
z z z
w
![Page 6: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/6.jpg)
Representation of Points (4-Vectors)Representation of Points (4-Vectors)
Homogeneous coordinates
Divide by 4th coord (w) to get (inhomogeneous) point
Multiplication by w > 0, no effect
Assume w ≥ 0. For w > 0, normal finite point. For w = 0, point at infinity (used for vectors to stop translation)
/
/
/
1
x x w
y y wP
z z w
w
![Page 7: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/7.jpg)
Advantages of Homogeneous CoordsAdvantages of Homogeneous Coords
Unified framework for translation, viewing, rot…
Can concatenate any set of transforms to 4x4 matrix
No division (as for perspective viewing) till end
Simpler formulas, no special cases
Standard in graphics software, hardware
![Page 8: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/8.jpg)
General Translation MatrixGeneral Translation Matrix
3
1 0 0
0 1 0
0 0 1 0 1
0 0 0 1
x
y
z
T
T I TT
T
1 0 0
0 1 0'
0 0 1
0 0 0 1 1 1
x x
y y
z z
T x x T
T y y TP TP P T
T z z T
![Page 9: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/9.jpg)
Combining Translations, RotationsCombining Translations, Rotations
Order matters!! TR is not the same as RT (demo)
General form for rigid body transforms
We show rotation first, then translation (commonly used to position objects) on next slide. Slide after that works it out the other way
simplestGlut.exe
transformation_game.jar
![Page 10: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/10.jpg)
Combining Translations, RotationsCombining Translations, Rotations
' ( )P TR P MP RP T
11 12 13 11 12 13
21 22 23 21 22 23
31 32 33 31 32 33
1 0 0 0
0 1 0 0
0 0 1 0 0 1
0 0 0 1 0 0 0 1 0 0 0 1
x x
y y
z z
T R R R R R R T
T R R R R R R T R TM
T R R R R R R T
transformation_game.jar
![Page 11: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/11.jpg)
Combining Translations, RotationsCombining Translations, Rotations
' ( ) ( )P RT P MP R P T RP RT
11 12 13
3 3 3 3 3 121 22 23
1 331 32 33
0 1 0 0
0 0 1 0
0 10 0 0 1
0 0 0 1 0 0 0 1
x
y
z
R R R T
R R TR R R TM
R R R T
transformation_game.jar
![Page 12: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/12.jpg)
OutlineOutline
Translation: Homogeneous Coordinates
Transforming Normals
Rotations revisited: coordinate frames
gluLookAt (quickly)
Exposition is slightly different than in the textbook
![Page 13: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/13.jpg)
NormalsNormals Important for many tasks in graphics like lighting
Do not transform like points e.g. shear
Algebra tricks to derive correct transformIncorrect to transform like points
![Page 14: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/14.jpg)
Finding Normal TransformationFinding Normal Transformation
?t Mt n Qn Q
0Tn t
0T T Tn Q Mt Q M I
1( )TQ M
![Page 15: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/15.jpg)
OutlineOutline
Translation: Homogeneous Coordinates
Transforming Normals
Rotations revisited: coordinate frames
gluLookAt (quickly)
Section 6.5 of textbook
![Page 16: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/16.jpg)
Coordinate FramesCoordinate Frames All of discussion in terms of operating on points
But can also change coordinate system
Example, motion means either point moves backward, or coordinate system moves forward
(2,1)P ' (1,1)P (1,1)P
![Page 17: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/17.jpg)
Coordinate Frames: In generalCoordinate Frames: In general Can differ both origin and orientation (e.g. 2 people)
One good example: World, camera coord frames (H1)
o x
y e
u
v
World
Camera p
o 2x0.9y
e
0.5u0.6v
World
Camera p
![Page 18: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/18.jpg)
Coordinate Frames: RotationsCoordinate Frames: Rotations
x
y
P
'P
cos sin
sin cosR
P
v
ucos sin
sin cos
u x
v y
![Page 19: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/19.jpg)
Geometric Interpretation 3D RotationsGeometric Interpretation 3D Rotations
Rows of matrix are 3 unit vectors of new coord frame
Can construct rotation matrix from 3 orthonormal vectors
u u u
uvw v v v u u u
w w w
x y z
R x y z u x X y Y z Z
x y z
![Page 20: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/20.jpg)
Axis-Angle formula (summary)Axis-Angle formula (summary)
*3 3( \ ) ( cos cos ) ( sin )T
ROTb a I aa b A b
( ) ( )TROTb a aa b
*3 3( , ) cos (1 cos ) sinTR a I aa A
2
2
2
1 0 0 0
( , ) cos 0 1 0 (1 cos ) sin 0
0 0 1 0
x xy xz z y
R a xy y yz z x
xz yz z y x
![Page 21: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/21.jpg)
OutlineOutline
Translation: Homogeneous Coordinates
Transforming Normals
Rotations revisited: coordinate frames
gluLookAt (quickly)
Not fully covered in textbooks. However, look at sections 6.5 and 7.2.1We’ve already covered the key ideas, so we go over it quickly showing how things fit together
![Page 22: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/22.jpg)
Case Study: Derive gluLookAtCase Study: Derive gluLookAt
Defines camera, fundamental to how we view images gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz)
Camera is at eye, looking at center, with the up direction being up
May be important for HW1
Combines many concepts discussed in lecture so far
Core function in OpenGL for later assignments
Eye
Up vector
Center
![Page 23: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/23.jpg)
StepsSteps
gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz)
Camera is at eye, looking at center, with the up direction being up
First, create a coordinate frame for the camera
Define a rotation matrix
Apply appropriate translation for camera (eye) location
![Page 24: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/24.jpg)
Constructing a coordinate frame?Constructing a coordinate frame?
aw
a
We want to associate w with a, and v with b But a and b are neither orthogonal nor unit norm And we also need to find u
b wu
b w
v w u
from lecture 2
![Page 25: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/25.jpg)
Constructing a coordinate frameConstructing a coordinate frame
aw
a
We want to position camera at origin, looking down –Z dirn
Hence, vector a is given by eye – center
The vector b is simply the up vector
b wu
b w
v w u
Eye
Up vector
Center
![Page 26: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/26.jpg)
StepsSteps
gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz)
Camera is at eye, looking at center, with the up direction being up
First, create a coordinate frame for the camera
Define a rotation matrix
Apply appropriate translation for camera (eye) location
![Page 27: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/27.jpg)
Geometric Interpretation 3D RotationsGeometric Interpretation 3D Rotations
Rows of matrix are 3 unit vectors of new coord frame
Can construct rotation matrix from 3 orthonormal vectors
u u u
uvw v v v u u u
w w w
x y z
R x y z u x X y Y z Z
x y z
![Page 28: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/28.jpg)
StepsSteps
gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz)
Camera is at eye, looking at center, with the up direction being up
First, create a coordinate frame for the camera
Define a rotation matrix
Apply appropriate translation for camera (eye) location
![Page 29: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/29.jpg)
TranslationTranslation
gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz)
Camera is at eye, looking at center, with the up direction being up
Cannot apply translation after rotation
The translation must come first (to bring camera to origin) before the rotation is applied
![Page 30: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/30.jpg)
Combining Translations, RotationsCombining Translations, Rotations
' ( ) ( )P RT P MP R P T RP RT
11 12 13
3 3 3 3 3 121 22 23
1 331 32 33
0 1 0 0
0 0 1 0
0 10 0 0 1
0 0 0 1 0 0 0 1
x
y
z
R R R T
R R TR R R TM
R R R T
![Page 31: Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2 cs4160](https://reader035.vdocument.in/reader035/viewer/2022062516/56649d775503460f94a596a0/html5/thumbnails/31.jpg)
gluLookAt final formgluLookAt final form
0 1 0 0
0 0 1 0
0 0 0 1
0 0 0 1 0 0 0 1
u u u x
v v v y
w w w z
x y z e
x y z e
x y z e
0 0 0 1
u u u u x u y u z
v v v v x v y v z
w w w w x w y w z
x y z x e y e z e
x y z x e y e z e
x y z x e y e z e