Class 03 Virtual World
Class 03 Virtual World
• Unlike a camera, you don’t actually see the signal received on the cones
• Instead, you perceive an image (highly) processed by your brain
• Your eyes constantly move around obtaining multiple images for your brain to work with
• You have two eyes, and see two images (in stereo), so triangulation can be used to estimate
depth and to undo distortion
• If your skeptical about all this processing, remember that your eye sees this:
Dealing with Objects
𝑥
• Let’s start with a single 3D point 𝑥⃗ = 𝑦 and move it around in the virtual world
𝑧
• An object is just a collection of points, so methods for handling a single point extend to
handling entire objects
• Typically, objects are created in a reference space, which we refer to as object space
• After creation, we place objects into the scene, which we refer to as world space
• This may require rotation, translation, resizing of the object
• When taking a (virtual) picture, points on the object are projected onto the 2D film plane,
which we refer to as screen space
• Unlike rotation/translation/resizing, the projection onto screen space is highly nonlinear and
the source of undesirable distortion
Rotation
𝑥
• Given a 3D point, 𝑥⃗ = 𝑦
𝑧
• In 2D, one can rotate a point counter-clockwise about the origin via:
• This is equivalent to rotating a 3D point around the z-axis using (i.e. multiplying by):
cos 𝜃 − sin 𝜃 0
𝑅$ 𝜃 = sin 𝜃 cos 𝜃 0
0 0 1
Rotation
• To rotate a 3D point around the x-axis, y-axis, z-axis (respectively), multiply by:
1 0 0
𝑅" 𝜃 = 0 cos 𝜃 − sin 𝜃
0 sin 𝜃 cos 𝜃 cos 𝜃 0 sin 𝜃
𝑅! 𝜃 = 0 1 0
− sin 𝜃 0 cos 𝜃
cos 𝜃 − sin 𝜃 0
𝑅# 𝜃 = sin 𝜃 cos 𝜃 0
0 0 1
• Matrix multiplication doesn’t commute, i.e. 𝐴𝐵 ≠ 𝐵𝐴, so the order of rotations matters!
• Rotating about the x-axis and then the y-axis, 𝑅! 𝜃! 𝑅" 𝜃" 𝑥,
⃗ is different than rotating about
the y-axis and then the x-axis, 𝑅" 𝜃" 𝑅! 𝜃! 𝑥⃗
• 𝑅! 𝜃! 𝑅" 𝜃" 𝑥⃗ ≠ 𝑅" 𝜃" 𝑅! 𝜃! 𝑥⃗ because 𝑅! 𝜃! 𝑅" 𝜃" ≠ 𝑅" 𝜃" 𝑅! 𝜃!
Line Segments are Preserved
• Consider two points 𝑝⃗ and 𝑞⃗ and the line segment between them:
𝑢 𝛼 = 1 − 𝛼 𝑝⃗ + 𝛼𝑞⃗
• 𝑢 0 = 𝑝⃗ and 𝑢 1 = 𝑞,
⃗ and 0 ≤ 𝛼 ≤ 1 specifies all the points on the line segment
• 𝑅𝑝⃗$ − 𝑅𝑝⃗% %% = 𝑅 𝑝⃗$ − 𝑝⃗% %% = 𝑝⃗$ − 𝑝⃗% & 𝑅& 𝑅 𝑝⃗$ − 𝑝⃗% = 𝑝⃗$ − 𝑝⃗% %% shows that the
distance between two rotated points is equivalent to the distance between the two original (un-
rotated) points
Angles are Preserved
• Consider two line segments 𝑢 and 𝑣⃗ with 𝑢 ⋅ 𝑣⃗ = 𝑢 % 𝑣⃗ % cos(𝜃) where 𝜃 is the angle
between them
• The 3 lengths of these three line segments and the 3 angles between any two of them are
used to compare the undeformed tetrahedron to its deformed counterpart
• Since we proved these were all identical under rotations, rotations are shape preserving
Shape is Preserved
• Thus, we can rotate entire objects without changing them
Scaling (or Resizing)
𝑠$ 0 0
• A scaling matrix 𝑆 = 0 𝑠% 0 can both scale and shear the object
0 0 𝑠'
• Shearing changes lengths/angles creating significant distortion
𝑠 0 0
• When 𝑠$ = 𝑠% = 𝑠', then 𝑆 = 0 𝑠 0 = 𝑠𝐼 is pure scaling
0 0 𝑠
• The distributive law of matrix multiplication (again) guarantees that line segments map to line
segments
• 𝑆𝑝⃗$ − 𝑆𝑝⃗% %% = 𝑠 𝑝⃗% − 𝑝⃗% %% implies that the distance between scaled points is
increased/decreased by a factor of 𝑠
• 𝑆𝑢 ⋅ 𝑆𝑣⃗ = s %𝑢 ⋅ 𝑣⃗ = 𝑠 % 𝑢 % 𝑣⃗ % cos 𝜃 = 𝑆𝑢 % 𝑆𝑣⃗ % cos(𝜃) shows that angles between
line segments are preserved
• Thus, uniform scaling grows/shrinks objects proportionally (they are mathematically similar)
Scaling (or Resizing)
non-uniform
uniform
uniform
Homogenous Coordinates
• In order to use matrix multiplication for transformations, homogeneous coordinates are
required
𝑥 𝑥𝑤
𝑦𝑤
• The homogeneous coordinates of a 3D point 𝑥⃗ = 𝑦 are 𝑥⃗( = 𝑧𝑤 for any 𝑤 ≠ 0
𝑧 𝑤 𝑥
𝑦
• Dividing homogenous coordinates by the fourth component (i.e. 𝑤) gives 𝑧 or 𝑥⃗
1
𝑥 1
𝑦
• 3D points are converted to 𝑥⃗( = 𝑧 , with 𝑤 = 1, to deal with translations
1 𝑢$
𝑢$
𝑢
• Vectors 𝑢 = 𝑢% have homogenous coordinates 𝑢( = 𝑢% or 𝑢
𝑢' ' 0
0
Homogenous Coordinates
• Let 𝑀'"' be a 3x3 rotation or scaling matrix (as discussed previously)
• The transformation of a point 𝑥⃗ is given by 𝑀'"'𝑥⃗
0 𝑥
𝑀'"' 𝑦 𝑀'"'𝑥⃗
• To obtain the same result for 𝑥⃗ , use a 4x4 matrix 0
𝑧 =
1 0 1
0 0 0 1 1
0 𝑢$
𝑀'"' 0 𝑢% 𝑀'"'𝑢
• Similarly, for a vector 𝑢' =
0 0
0 0 0 1 0
Translation
𝑡$ 𝑥
𝑡$
𝐼'"' 𝑡% 𝑦 𝑥⃗ + 𝑡⃗
• To translate a point 𝑥⃗ by 𝑡⃗ = 𝑡% , multiply 𝑧 =
𝑡' 1
𝑡'
0 0 0 1 1
1 0 0
• 𝐼#"# = 0 1 0 is the 3x3 identity matrix
0 0 1
𝑡$ 𝑢$
𝐼'"' 𝑡% 𝑢% 𝑢 has no effect (as desired)
• For a vector 𝑢' =
𝑡' 0
0 0 0 1 0
• Translation preserves line segments and the angles between them (and thus preserves shape)
Shape is Preserved
• We can translate entire objects without changing them
Composite Transforms
• Rotate 45 degrees about the point (1,1)
T(-1,-1) T(1,1)
R(45)
T(1,1)R(45) ≠ R(45)T(1,1)
Hierarchical Transforms
• M1 transforms the teapot from its object space to the table’s object space (puts it on the table)
• M2 transforms the table from its object space to world space
• M2M1 transforms the teapot from its object space to world space (and onto the table)
𝑀" 𝑀!
𝑀!
𝑀"
Using Transformations
• Create objects (or parts of objects) in convenient coordinate systems
• Assemble objects from their parts (using transformations)
• Transform the assembled object into the scene (via hierarchical transformations)
• Can make multiple copies (even of different sizes) of the same object (simply) by adding
another transform stack (efficiently avoiding the creation of a new copy of the object)
• Helpful Hint: Always compute composite transforms for objects or sub-objects, and apply the
single composite transform to all relevant points (it’s a lot faster)
pinhole x
x’ (x’,y’,h)
z-axis
z
h
and
Matrix Form
𝑥 * 𝑤′
𝑦 * 𝑤′ ! * =𝑧
• Writing the screen space result as gives the desired after dividing by 𝑤
𝑧 * 𝑤′ "
𝑤′
𝑥 * 𝑤′ ℎ 0 0 0 𝑥
𝑦 * 𝑤′ 0 ℎ 0 0 𝑦
• Consider: = 𝑧
*
𝑧 𝑤′ 0 0 𝑎 𝑏
𝑤′ 0 0 1 0 1
+" +!
• This has 𝑤 * = 𝑧, 𝑥 * 𝑤 * = ℎ𝑥 or 𝑥 * * * *
= # , and 𝑦 𝑤 = ℎ𝑦 or 𝑦 = # (as desired)
.
• Homogenous coordinates allows the nonlinear to be expressed with linear matrix
$
multiplication (so it can be added to the matrix multiplication stack!)
Perspective Projection
• The third equation is 𝑧 * 𝑤 * = 𝑎𝑧 + 𝑏 or 𝑧 * 𝑧 = 𝑎𝑧 + 𝑏
• New 𝑧 values aren’t required (projected points all lie on the 𝑧 = ℎ image plane)
• However, computing 𝑧′ as a monotonically increasing function of 𝑧 allows it to be used to
determine occlusions (for alpha channel transparency)
• The near (𝑧 = 𝑛) and far (𝑧 = 𝑓) clipping planes are preserved via 𝑧′ = 𝑛 and 𝑧′ = 𝑓
• 2 equations in 2 unknowns (𝑛% = 𝑎𝑛 + 𝑏 and 𝑓 % = 𝑎𝑓 + 𝑏); so, 𝑎 = 𝑛 + 𝑓 and 𝑏 = −𝑓𝑛
• This transforms the viewing frustum into an orthographic volume in screen space