Professional Documents
Culture Documents
Computer Graphics
COMP 557
9 January 2018
Paul Kry
“Computers are useless. They can
only give you answers”
Pablo Picasso
Art
Meats Meier
Visualization
[van Dam]
Original Macintosh New iMac 27”
Date 1984 2018 +34
x 425
CPU 8 MHz 3.4 GHz (Quad) (x 1700)
Memory
128KB RAM 8.0GB DDR3 SDRAM x 65536
(2 GB on GPU)
Storage 400KB Floppy 1TB Hard Disk x 2500000
1,000,000,000
100,000,000
Transistor count
100,000
GPUs now part of every machine,
10,000
arguably more powerful than CPUs
and programmable
2,300
Date of introduction
Today
• Research overview
• Introduction
• Course details
• Announcements
• Transforms
Who are you?
• 31 MSc Computer Science
• 41 BSc Physics Earth Math Computer Science
• 8 BEng Software, Computer, Mechanical
• 4 BA Computer Science
• 2 BSc Biol, Biomed & Life Sci CS & Bio
• 2 MEng Electrical
• 1 MA Digital Humanitites
• 2 PhD
Comp 557
• You will:
• explore fundamental ideas
• learn math essential to graphics
• implement key algorithms
• write cool programs
• You will not:
• Learn Photoshop, AutoCad, Maya, Renderman, etc.
• Become experts at OpenGL or DirectX
(but you will become comfortable with OpenGL)
• write huge programs
Prerequisites
(COMP206, COMP251, MATH223)
• Programming
• ability to read (understand), write, and debug small Java
programs (10s of classes)
• understanding of basic data structures
• no serious software design required
• Mathematics
• vector geometry (dot/cross products, etc.)
• linear algebra (matrices in 2D to 4D, linear systems)
• basic calculus (derivatives and integrals)
Topics
• Coordinates, Transformations, Projections
• Meshes, Curves, Smooth Surfaces, Subdivision
• Lighting, Texturing, Rendering
• Images, Sampling
• Color science
Textbook and Resources
• Computer Graphics Principles and Practice 3rd ed
• Other good resources
• OpenGL Programming Guide: The official guide to
learning OpenGL
• Fundamentals of Computer Graphics, 3rd ed., Peter
Shirley and Steve Marschner
• The Graphics Codex (mostly rendering focused)
• Additional papers will be posted to MyCourses
throughout the term
Textbook and Resources
• CGPP Chapter 10 Transforms in 2D
• CGPP Chapter 11 Transforms in 3D
• CGPP Chapter 13 Viewing and Projection
It should be noted that, in accordance with article 15 of the Charter of Students' Rights,
students may submit examination answers in either French or English.
According to Senate regulations, instructors are not permitted to make special arrangements
for final exams. Please consult the Calendar, section 4.7.2.1, General University Information
and Regulations at www.mcgill.ca. Special arrangements in emergencies may be requested
at your Student Affairs Office. If you have a disability, please advise the Office for Students
with Disabilities (398-6009) as early in the term as possible so that we can provide
appropriate accommodation to support your success.
In the event of circumstances beyond the instructor's control, the evaluation scheme as set
out in this document might require change. In such a case, every effort will be made to obtain
consensus agreement from the class.
Additional policies governing academic issues which affect students can be found in
the Handbook on Student Rights and Responsibilities, Charter of Students' Rights.
Assignments (four)
• Late Policy: 10% penalty, three days max
• Try “getting started” sample code now!
• Assignments, probably covering:
• Rotations and transform hierarchies
• Projections
• Mesh subdivision or simplification
• Ray tracing (with competition)
Getting started!
• Get started with Eclipse, JOGL
• http://cs.mcgill.ca/~kry/comp557W18/asetup/
• We will use vecmath, and some other jars too
• In class, will provide some introduction to OpenGL, java
bindings, and general graphics debugging strategies
• Need more help?
• TA contact info and office hours on My Courses
• Prof office hours 2-4 pm Wednesdays, or any other time
by email appointment
Today
• Research overview
• Introduction
• Course details
• Announcements
• Transforms
COMP 559 Fundamentals of Computer Animation
Computational techniques for generating animation
1 0 𝑡 𝑥 𝑥+𝑡
0 1 𝑠 𝑦 = 𝑦+𝑠
0 0 1 1 1
Homogeneous Coordinates
• Composition works by 3-by-3 matrix multiplication
(note we use block matrix notation)
𝑀𝑆 𝐮𝑆 𝑀𝑇 𝐮 𝑇 𝐩
0 1 0 1 1
𝑀𝑆 𝑀𝑇 𝑀𝑆 𝐮 𝑇 + 𝐮𝑆 𝐩
=
0 1 1
• This is exactly the same as carrying around 𝑀 and 𝐮
• But cleaner
• And generalizes in useful ways as we will see later!
Review and more information
• Review
• CGPP Chapter 7 up to and not including 7.7
• Essential Math and Geometry of 2D and 3D
• CGPP Chapter 10 up to and including 10.10
• 2D transformations
• Points and Vectors
• Skip the SVD (10.3.8 and 10.3.9)
• Inverses of transformation matrices
• Coordinate Transformations
Transformations
COMP 557
11 January 2018
Paul Kry
Affine transformations
• The set of transformations we have been looking at,
linear transformations combined with translation,
is known as affine transformations
• Straight lines are preserved
• Parallel lines are preserved
• Ratios of lengths along lines are preserved (e.g., midpoints)
Affine transformation examples
in homogeneous coordinates
1 0 𝑡𝑥 1 0 2.15
0 1 𝑡𝑦 , for example, 0 1 0.85
0 0 1 0 0 1
• Translation
Affine transformation examples
in homogeneous coordinates
𝑠 0 0 1.5 0 0
0 𝑠 0 , for example, 0 1.5 0
0 0 1 0 0 1
• Uniform scale
Affine transformation examples
in homogeneous coordinates
𝑠𝑥 0 0 1.5 0 0
0 𝑠𝑦 0 , for example, 0 0.8 0
0 0 1 0 0 1
• Non-uniform scale
Affine transformation examples
in homogeneous coordinates
cos 𝜃 −sin 𝜃 0 0.866 −0.5 0
sin 𝜃 cos 𝜃 0 , for example, 0.5 0.866 0
0 0 1 0 0 1
• Rotation
Affine transformation examples
in homogeneous coordinates
−1 0 0
0 1 0
0 0 1
• Reflection (about y axis)
Affine transformation examples
in homogeneous coordinates
1 𝑎 0 1 0.5 0
0 1 0 , for example, 0 1 0
0 0 1 0 0 1
• Shear
General affine transformations
• The previous slides show “canonical” examples of
the different types of affine transformations
• In general, an affine transformations can be
different than any single canonical example
• Often define them as a product of canonical transforms
• Sometimes define them more directly based on desired
properties (e.g., creating a change of coordinates)
Composite affine transformation
• In general, non commutative: order matters!
𝑀 = 𝑇 −1 𝑅 𝑇
Composing to change axes
• Want to scale along particular axis and point?
• We know how to scale about y axis at origin
• Suppose we want to stretch by 1.5 times in the direction
and at the point shown below
𝑀 = 𝑇 −1 𝑅 −1 𝑆 𝑅 𝑇
What are the contents of 𝑆 𝑅 and 𝑇?
Transforming points and vectors
• Note distinction between points and vectors
• Vectors are offsets (differences between points)
• Points have a location
• Represented by vector offset from a fixed origin
• Points and vectors transform differently
• Points respond to translation; vectors do not
• Consider
𝑣 = 𝑝−𝑞
𝑇 𝑥 = 𝑀𝑥 + 𝑡
Transforming points and vectors
𝑣 = 𝑝−𝑞
𝑇 𝑥 = 𝑀𝑥 + 𝑡
• 𝑇 is an affine transformation
• 𝑇 is not a linear transformation
𝑇 𝑥+𝑦 ≠𝑇 𝑥 + 𝑇 𝑦
=𝑀 𝑥+𝑦 +𝑡+𝑡
𝑇 𝑝 – 𝑇 𝑞 = 𝑀𝑝 + 𝑡 – 𝑀𝑞 + 𝑡
= 𝑀 𝑝−𝑞 + 𝑡−𝑡
= 𝑀𝑣
• Vectors are only transformed by linear part
Transforming points and vectors
• In homogeneous coordinates, vectors have 𝑤 = 0
• Translation of an affine transformation excluded for
vectors in homogeneous coordinates
𝑀 𝐭 𝐩 𝑀𝐩 + 𝐭
=
0 1 1 1
𝑀 𝐭 𝐯 𝑀𝐯
=
0 1 0 0
• Preview of what is to come
• Last coordinate need not always be 0 or 1
• Can change last row in matrix to do perspective projection
Coordinate systems
• Can express vectors with respect to different bases
• Linear transformation is a change of basis
• This leads to an alternate view
• We were previously thinking of modeling
transformations (e.g., “make it bigger”)
• Can instead think of them as a means of using different
reference frames, or different units (e.g., cm to inches)
Affine change of coordinates
• There are 6 degrees of freedom
𝑎1 𝑎2 𝑎3
𝐮 𝐯 𝐩
𝑎4 𝑎5 𝑎6 or
0 0 1
0 0 1
Affine change of coordinates
• Coordinate frame: point and a basis
• Interpretation is that the transformation changes
the representation of point (or vector) from one
basis to another
• Frame to canonical matrix has frame in columns
• Takes points in coordinates of the frame
• Gives points in coordinates of the canonical basis
𝐮 𝐯 𝐩
0 0 1
Affine change of coordinates
• A new way to “read off” the matrix
• e.g., shear from earlier
• Observe how the matrix columns correspond to the
change of shape
1 0.5 0
0 1 0
0 0 1
Affine change of coordinates
• When we move an object to the origin to apply a
transformation, we are really changing coordinates
• Easy to express the transformation in the object’s frame
• Define it there and transform it
𝑇𝑒 = 𝐹 𝑇𝐹 𝐹 −1
• 𝑇𝑒 is the transform expressed wrt 𝐞1 𝐞2 canonical basis
• 𝑇𝐹 is the transformation expressed in the natural frame
• 𝐹 is the frame-to-canonical matrix 𝐮 𝐯 𝐩 , here in
block form with homogeneous representation for basis
vectors 𝐮 and 𝐯 and origin point 𝐩
• This is a similarity transformation
Coordinate frame summary
• Frame is a point plus a basis
• Frame matrix (frame to canonical) is
𝐮 𝐯 𝐩
𝐹=
0 0 1
• Change coordinates of point 𝑎 to and from frame
by multiplying by 𝐹 and 𝐹 −1
𝑎𝑒 = 𝐹𝑎𝐹 𝑎𝐹 = 𝐹 −1 𝑎𝑒
• “Move” transformations using similarity transform
𝑇𝑒 = 𝐹 𝑇𝐹 𝐹 −1 𝑇𝐹 = 𝐹 −1 𝑇𝑒 𝐹
Classes of Transformations
• The set of 3x3 matrices we can use to transform
homogenous points have a variety of properties
• Most generally, they map lines to lines.
• These are called Homographies provided they are invertible
(this set include perspective projection)
• A more restrictive set also preserves parallel lines
• These are called Affine transforms
• A more restrictive set also preserves angles
• These are called Conformal
• A more restrictive set also preserves lengths
• These are called Rigid
• Where do translate, rotate, and scale fit?
Conformal (preserve angles)
uniform scale
Question
25
Review and more information
• Review
• CGPP Chapter 7 up to and not including 7.7
• Essential Math and Geometry of 2D and 3D
• CGPP Chapter 10 up to and including 10.10
• 2D transformations
• Points and Vectors
• Skip the SVD (10.3.8 and 10.3.9)
• Inverses of transformation matrices
• Coordinate Transformations
3D Transformations
COMP557
Paul Kry
McGill COMP557 1
Transformations in OpenGL
Your Code
Geometry OpenGL
(points)
Transformation Matrix
(and many other things)
Window
2
Translation glTranslated(x,y,z)
𝑥′ 1 0 0 𝑡𝑥 𝑥
𝑦′ 0 1 0 𝑡𝑦 𝑦
=
𝑧′ 0 0 1 𝑡𝑧 𝑧
1 0 0 0 1 1
McGill COMP557 3
Based on slides by Steve Marschner
Scaling glScaled(x, y, z)
𝑥′ 𝑠𝑥 0 0 0 𝑥
𝑦′ 0 𝑠𝑦 0 0 𝑦
=
𝑧′ 0 0 𝑠𝑧 0 𝑧
1 0 0 0 1 1
McGill COMP557 4
Based on slides by Steve Marschner
Rotation glRotate(deg, x, y, z)
• For example, rotation about the 𝑧 axis
• glRotate( thetaDegrees, 0, 0, 1 )
𝑥′ cos 𝜃 − sin 𝜃 0 0 𝑥
𝑦′ sin 𝜃 cos 𝜃 0 0 𝑦
=
𝑧′ 0 0 1 0 𝑧
1 0 0 0 1 1
McGill COMP557 5
Based on slides by Steve Marschner
Rotation glRotate(deg, x, y, z)
• For example, rotation about the 𝑥 axis
• glRotate( thetaDegrees, 1, 0, 0 )
𝑥′ 1 0 0 0 𝑥
𝑦′ 0 cos 𝜃 − sin 𝜃 0 𝑦
=
𝑧′ 0 sin 𝜃 cos 𝜃 0 𝑧
1 0 0 0 1 1
McGill COMP557 6
Based on slides by Steve Marschner
Rotation glRotate(deg, x, y, z)
• For example, rotation about the 𝑦 axis
• glRotate( thetaDegrees, 0, 1, 0 )
𝑥′ cos 𝜃 0 sin 𝜃 0 𝑥
𝑦′ 0 1 0 0 𝑦
=
𝑧′ −sin 𝜃 0 cos 𝜃 0 𝑧
1 0 0 0 1 1
McGill COMP557 7
Based on slides by Steve Marschner
General rotations
• A rotation in 2D is around a point
• A rotation in 3D is around an axis
• so 3D rotation is w.r.t a line through origin, not just
about the origin point
• there are many more 3D rotations than 2D
In 3D, one way to specify a
Rotation is via a unit vector
(the axis) and an angle.
Convention: positive rotation
2D is CCW when vector points
3D points toward you.
McGill COMP557 8
Based on slides by Steve Marschner
What are 3D rotations?
More precisely…
3D Rotations are the set of linear transformations
{𝑅 ∈ ℝ3×3 ∶ 𝑅𝑇 = 𝑅−1 , det 𝑅 = +1}
which form a group with matrix multiplication as the binary group
operation (i.e., operation that combines two elements)
• Closed under the group operation
• Exist identity element (the identity matrix)
• Exist an inverse for every group element
• Associative, A(BC) = (AB)C
This group is the “special orthogonal group” SO(3). Each different
possible 3D orientation is specified only once in this group.
9
Based on slides by Steve Marschner
Specifying rotations
• In 2D, a rotation just has an angle
• How many Degrees Of Freedom, i.e., DOFs?
• 𝑅𝑇 = 𝑅−1 , det(𝑅) = +1 does not perhaps give much
intuition, but
• Knowing that an angle about an axis direction lets us
specify any rotation with 3 DOFs
• This is how you specify a rotation with glRotate in OpenGL
McGill COMP557 10
Based on slides by Steve Marschner
Specifying Rotations
Euler Angles
• Can specify a rotation matrix with Euler angles
• Stack up three coordinate axis rotations, for instance
𝑅 = 𝑅𝑥 𝜃𝑥 𝑅𝑦 𝜃𝑦 𝑅𝑧 𝜃𝑧
• Can see z rotation as being about the object frame
• Can see x rotation as being about the canonical frame
• The y rotation is about an intermediate frame
• Why not another order? (more on this shortly)
• Also, problem of gimbal lock !! (more on this shortly)
11
Based on slides by Steve Marschner
Euler’s Theorem
• Any two independent orthonormal coordinate
frames can be related by a sequence of rotations
(not more than three) about coordinate axes,
where no two successive rotations may be about
the same axis.
• Have 12 possible sequences!
XYZ XZY XYX XZX YXZ YZX
YXY YZY ZXY ZYX ZXZ ZYZ
14
Based on slides by Steve Marschner
Interpolating Euler Angles
• One can simply interpolate between the three values
independently
• This will result in the interpolation following a different
path depending on which of the 12 schemes you
choose
• This may or may not be a problem, depending on your
situation
• Interpolating near singularities is problematic
• Note: when interpolating angles, remember to check
for crossing the +180/-180 degree boundaries
17
Data structures with transforms
• Representing a drawing (“scene”)
• List of objects
• Transform for each object
• Can use minimal primitives: ellipse is transformed circle
• Transform applies to points of object
COMP557 McGill 18
Based on slides by Steve Marschner
COMP557 McGill 19
Based on slides by Steve Marschner
COMP557 McGill 20
Based on slides by Steve Marschner
COMP557 McGill 21
Based on slides by Steve Marschner
COMP557 McGill 22
Based on slides by Steve Marschner
COMP557 McGill 24
Based on slides by Steve Marschner
COMP557 McGill 25
Based on slides by Steve Marschner
COMP557 McGill 26
Based on slides by Steve Marschner
COMP557 McGill 27
Based on slides by Steve Marschner
28
COMP557 McGill
Based on slides by Steve Marschner Based on slides by Steve Marschner
Implementing traversal
In OpenGL*, transforms are kept on matrix stack, with push
and pop matrix commands allowing us to easily store copies
before we make modifications in different sub-trees.
COMP557 McGill 30
Based on slides by Steve Marschner
COMP557 McGill 32
Based on slides by Steve Marschner
COMP557 McGill 36
Based on slides by Steve Marschner
38
Group of Unit Quaternions
• Quaternions are like complex numbers, but with three
imaginary parts
𝑖𝑗𝑘 = 𝑖2 = 𝑗2 = 𝑘2 = −1
• Example multiplication:
𝐴 = 𝑎0 + 𝑎1𝑖 + 𝑎2𝑗 + 𝑎3𝑘
𝐵 = 𝑏0 + 𝑏1𝑖 + 𝑏2𝑗 + 𝑏3𝑘
𝐴𝐵 = 𝑎0𝑏0 – 𝑎1𝑏1 – 𝑎2𝑏2 – 𝑎3𝑏3 +
(𝑎0𝑏1 + 𝑎1𝑏0 + 𝑎2𝑏3 – 𝑎3𝑏2)𝑖 + …
The set of unit quaternions, combined with quaternion
multiplication as a binary operation, form a group which is
very similar to the rotation group SO(3), except that each 3D
orientation appears twice! It is a double covering.
39
Based on slides by Steve Marschner
Quaternions as Rotations
• Related to a rotation by q on unit length axis (x,y,z)
(𝑐, 𝑠𝑥, 𝑠𝑦, 𝑠𝑧) ≡ 𝑐 + 𝑠𝑥𝑖 + 𝑠𝑦𝑗 + 𝑠𝑧𝑘
𝑞 𝑞
where 𝑐 = cos and 𝑠 = sin
2 2
• Why q/2?
• This means that q and –q are same rotation
• The angle between two unit quaternions in 4D space is half the
angle between the 3D orientations that they represent
• Composition by multiplication (rules on previous slide)
• Inverse of unit quaternions similar to complex
conjugation
• If 𝑞 = (𝑤, 𝑥, 𝑦, 𝑧) is unit length, then 𝑞 −1 = (𝑤, −𝑥, −𝑦, −𝑧)
• Vector (𝑥, 𝑦, 𝑧) transforms as 𝑞𝑣𝑞 −1 where
𝑣 = 0 + 𝑖𝑥 + 𝑗𝑦 + 𝑘𝑧 and the result is the imaginary part
40
Based on slides by Steve Marschner
Questions
41
Based on slides by Steve Marschner
Comparison of Rotation representations
• Rotation matrix
• 3x3 matrix with RTR = I and det(R) = +1
• Euler angles
• Used widely, often simple and convenient, also problematic
• Quaternion
• Compact storage, efficient and nice mathematical
properties…
• Axis and Angle
• Similar to quaternions
• Axis scaled by angle
• Save storage space!
42
Based on slides by Steve Marschner
Important issues for different
rotation representations
• Storage Numerical problems?
• How much memory? • Suppose we need to
compose hundreds or
• Composition thousands of
• Is it possible? transformations?
• What’s the cost? • Does this ever happen?
• What’s the cost of • What can go wrong?
transforming points and • How can we fix it?
vectors?
• Conversion between • Interpolation
representations? • Smoothly interpolating
between two rotations is
• Easy or Hard? important for animation!
43
Based on slides by Steve Marschner
Aside:
Linear Interpolation
• Linear interpolation between two points a and b
Lerp(t,a,b) = (1-t)a + (t)b
where t ranges from 0 to 1
• Note that the Lerp operation can be thought of as a
weighted average (convex)
• We can also write it in as an additive blend:
Lerp(t,a,b) = a + t(b-a)
• What happens if we use linear interpolation with
rotations in different representations?
44
Based on slides by Steve Marschner
Aside:
Spherical Linear Interpolation
• We define the spherical linear interpolation of two
unit vectors in N dimensional space as
sin 1 t q sin tq
Slerp(t , a, b) a b
sin q sin q
where : q cos 1 a b
• We can use this formula to smoothly interpolate
two arbitrary rotations represented as quaternions.
• Watch out if a dot b is negative!
• What happens in this case? How to fix this?
45
Based on slides by Steve Marschner
Interaction
• What is a good way to rotate an object you are
viewing on screen using a mouse?
46
Based on slides by Steve Marschner
Ken Shoemake, ARCBALL: A User
Interface for Specifying Three-
ArcBall / TrackBall Dimensional Orientation Using a
Mouse, Graphics Interface 1992.
McGill COMP557 48
Based on slides by Steve Marschner
Building general rotations
• Using elementary transforms you need three
• translate axis to pass through origin
• rotate about y to get into x-y plane
• rotate about z to align with x axis
• Alternative: construct frame and change
coordinates
• choose p, u, v, w to be orthonormal frame with p and u
matching the rotation axis
• apply similarity transform T = F Rx(q) F–1
McGill COMP557 49
Based on slides by Steve Marschner
Orthonormal frames in 3D
• Useful tools for constructing transformations
• Recall rigid motions
• affine transforms with pure rotation
• columns (and rows) form right handed orthonormal
basis
McGill COMP557 50
Based on slides by Steve Marschner
Building 3D frames
• Given a vector a and a secondary vector b
• The u axis should be parallel to a; the u–v plane should
contain b
• u = u / ||u||
• w = u x b; w = w / ||w||
• v=wxu
• Given just a vector a
• The u axis should be parallel to a; don’t care about
orientation about that axis
• Same process but choose arbitrary b first
• Good choice is not near a, e.g., set smallest entry to 1
McGill COMP557 51
Based on slides by Steve Marschner
Building general rotations
• Alternative: construct frame and change
coordinates
• choose p, u, v, w to be orthonormal frame with p and u
matching the rotation axis
• apply similarity transform T = F Rx(q) F–1
• interpretation: move to x axis, rotate, move back
• interpretation: rewrite u-axis rotation in new
coordinates
• (each is equally valid)
McGill COMP557 52
Based on slides by Steve Marschner
Building transforms from points
• 2D affine transformations have 6 degrees of freedom (DOFs)
• this is the number of “knobs” we have to set to define one
• Therefore 6 constraints suffice to define the transformation
• Constrain point p maps to point q (2 constraints at once)
• three point constraints add up to constrain all 6 DOFs
(i.e., can map any triangle to any other triangle)
• 3D affine transformation has 12 degrees of freedom
• count them by looking at the matrix entries we’re allowed to
change
• Therefore 12 constraints suffice to define the
transformation
• in 3D, this is 4 point constraints
(i.e., can map any tetrahedron to any other tetrahedron)
McGill COMP557 53
Based on slides by Steve Marschner
Transforming normal vectors
• Transforming surface normals
• Differences of points (e.g., tangents) transform OK
• Normals are covectors, and do not transform the same
way
54
McGill COMP557
Based on slides by Steve Marschner
Question
55
Other Questions
56
Based on slides by Steve Marschner
Review and More Information
• Transforming covectors (normals) CGPP 10.12
• Transformations in 3D, Chapter 11, in particular:
• Euler angles and gimbal lock 11.2
• Quaternions 11.2.6
• Trackball and Arcball, 11.6
• CGPP 6.6, Hierarchical modeling using a scene
graph
• glPushMatrix and glPopMatrix
• Convenient but not in the latest spec
• http://www.davidbishop.org/oglmeta#old-vs
57
Based on slides by Steve Marschner
3D Viewing, Orthographic and
Perspective Projection
COMP557
Paul Kry
COMP557 McGill 1
Image order and Object order
• Image order: “backward” approach
– start from pixel
– ask what part of scene projects to pixel
– explicitly construct the ray corresponding to the pixel
• Object order: “forward” approach
– start from a point in 3D
– compute its projection into the image
• Matrix transformations critical for object order
approach (actually important for both)
– combines seamlessly with coordinate transformations
used to position camera and model
– ultimate goal: single matrix operation to map any 3D point
to its correct screen location.
COMP557 McGill 2
Based on slides by Steve Marschner
Image Order Approach to Viewing
[Durand]
• Ray generation produces rays, not points in scene
• Cast a ray at every pixel and find points of intersection
• This is called ray tracing
COMP557 McGill 3
Based on slides by Steve Marschner
Object Order Approach to Viewing
[Durand]
• Inverting the ray tracing process requires division for the perspective case
• Once triangle vertices are known in screen coordinates the triangle can be
filled in (rasterization… more on this later)
COMP557 McGill 4
Based on slides by Steve Marschner
Mathematics of projection
• Always work in eye coordinates
– assume eye point at 0 and plane perpendicular to z
• Orthographic case
– a simple projection: just toss out z
• Perspective case: scale diminishes with z
– and increases with d
COMP557 McGill 5
Based on slides by Steve Marschner
Pipeline of transformations
• Standard sequence of transforms
COMP557 McGill 6
Based on slides by Steve Marschner
Camera / Eye Coordinates
• We have discussed object to world transformations
• Need world to camera transformation
– In viewing, we typically know:
• Where the camera is
• What we want to look at
• Which way is up
– Need a rigid transformation
(rotation and translation)
– How many degrees of freedom?
[Toldo]
– How to compute it?
– In OpenGL we can use gluLookat
COMP557 McGill 7
Based on slides by Steve Marschner
“Lookat” Transformation
• uvn or uvw commonly used for xyz camera axes
• Compute transform from points e, l, and vector Vup
– e is the eye point, or view reference point
– l is the lookat point
• Separate the rotation R and translation T
– What order to compose? What is easiest?
– What is T?
– What is R?
• We want
COMP557 McGill 8
Based on slides by Steve Marschner
Pipeline of transformations
• Standard sequence of transforms
COMP557 McGill 9
Based on slides by Steve Marschner
Projection
• How to form an image by planar perspective projection?
In computer graphics,
projection plane is in front
of center of projection
[Source unknown]
COMP557 McGill 10
Based on slides by Steve Marschner
Parallel projection: orthographic
COMP557 McGill 11
Based on slides by Steve Marschner
Pipeline of transformations
• Standard sequence of transforms
COMP557 McGill 13
Based on slides by Steve Marschner
View volume: orthographic
COMP557 McGill 14
Based on slides by Steve Marschner
Viewing a cube of size 2
• Start by looking at a restricted case: the canonical view volume
• It is the cube [-1,1]3, viewed from the z direction
• Matrix to project it into a square image in [-1,1]2 is trivial:
COMP557 McGill 15
Based on slides by Steve Marschner
Viewing a cube of size 2
• To draw in image, need coordinates in pixel units
• Suppose nx pixels in x direction and ny pixels in y direction
1 ny – .5
–1 –.5
–1 1 –.5 nx – .5
COMP557 McGill 16
Based on slides by Steve Marschner
Windowing transforms
• This transformation is worth generalizing
– take one axis-aligned rectangle or box to another
– a useful transformation chain
COMP557 McGill 17
Based on slides by Steve Marschner
Viewport transformation
1 ny – .5
–1 –.5
–1 1 –.5 nx – .5
COMP557 McGill 19
Based on slides by Steve Marschner
Orthographic projection
• First generalization: different view rectangle
– retain the minus-z view direction
COMP557 McGill 20
Based on slides by Steve Marschner
Clipping planes
• Recall…
– Object-order rendering considers each object in turn
• i.e., forward rendering, rasterization
– Image-order rendering considers each pixel in turn
• i.e., backward rendering, ray tracing
COMP557 McGill 21
Based on slides by Steve Marschner
Orthographic projection
• We can implement this by mapping the view volume
to the canonical view volume.
• This is just a 3D windowing transformation!
COMP557 McGill 22
Based on slides by Steve Marschner
Camera and modeling matrices
• We worked out all the preceding transforms starting from
eye coordinates
– before we do any of this we need to transform into that space
• Transform from world (canonical) to eye space is
traditionally called the viewing matrix
– Easy for us to compute the matrix Fc which takes us from eye
space to canonical space, but here we use the inverse Fc–1
• Remember that geometry would originally have been in
the object’s local coordinates; transform into world
coordinates is called the modeling matrix, Mm
• Note some systems (e.g., OpenGL) combine the two into a
modelview matrix and just skip world coordinates
COMP557 McGill 23
Based on slides by Steve Marschner
Viewing transformation
COMP557 McGill 25
Based on slides by Steve Marschner
Planar Perspective projection
COMP557 McGill 27
Based on slides by Steve Marschner
Homogeneous coordinates revisited
• Introduced w = 1 coordinate as a placeholder
COMP557 McGill 28
Based on slides by Steve Marschner
Implications of w
COMP557 McGill 30
Based on slides by Steve Marschner
View volume: perspective
COMP557 McGill 31
Based on slides by Steve Marschner
View volume: perspective (clipped)
COMP557 McGill 32
Based on slides by Steve Marschner
Carrying depth through perspective
• Perspective has a varying denominator—can’t preserve depth!
• Compromise: preserve order, and depth on near and far planes
COMP557 McGill 33
Based on slides by Steve Marschner
Official perspective matrix
• Use near plane distance as the projection distance
• Let 𝑛 be negative and 𝑑 = – 𝑛
• Scale by –1 to have fewer minus signs
– The matrix is different but this does not change the
projective transformation
Potential Confusion:
In OpenGL the near and
far plane are specified as
positive numbers giving
the distance along the
negative z axis!
COMP557 McGill 34
Based on slides by Steve Marschner
Questions
• Questions to better understand the action of a 4x4
homogenous planar perspective transformation matrix
– What happens to lines through the origin ?
• They become parallel
– What happens to vectors (x,y,z,0) ?
• They map to plane z=near+far
– What happens to points on plane with z normal at center of projection ?
• Map to points at infinity (all vectors come from the homogeneous
representations of points on this plane at center of projection)
– What happens to points at z = (near+far)/2 ?
• (n*n+f*f) / (n+f), that is, z is not preserved !! However, order is!
(has implications for z depth precision)
– What happens to points behind the camera ?
• It goes in front of the camera
COMP557 McGill 35
Based on slides by Steve Marschner
Aside: What goes where?
Is n-f a bug?
Is it not f-n ??
Answer:
The convention is that -near
maps to -1 and -far maps to 1.
Subtle detail, confusing, yes!
COMP557 McGill 37
Based on slides by Steve Marschner
Perspective transformation chain
• Transform into world coords (modeling transform, Mm)
• Transform into eye coords (camera xf., Mcam = Fc–1)
• Perspective matrix, P
• Orthographic projection, Morth
• Viewport transform, Mvp
COMP557 McGill 38
Based on slides by Steve Marschner
OpenGL view frustum: orthographic
COMP557 McGill 39
Based on slides by Steve Marschner
OpenGL view frustum: perspective
COMP557 McGill 41
Based on slides by Steve Marschner
COMP557 McGill 42
Based on slides by Steve Marschner
COMP557 McGill 43
Based on slides by Steve Marschner
COMP557 McGill 44
Based on slides by Steve Marschner
COMP557 McGill 45
Based on slides by Steve Marschner
Review and More Information
• CAPP Section 10.7
– Windowing Transformations
• CAPP Chapter 13
– View Specification 13.3
– Perspective 13.6
– Orthographic cameras 13.8
COMP557 McGill 46
Based on slides by Steve Marschner
Review and more information
• FCG chapter 7
– Viewing and projection
COMP557 McGill 47
Based on slides by Steve Marschner