foundations of computer graphics (spring 2010) cs 184, lecture 5: viewing cs184
Post on 19-Dec-2015
218 views
TRANSCRIPT
![Page 1: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/1.jpg)
Foundations of Computer Graphics Foundations of Computer Graphics (Spring 2010)(Spring 2010)
CS 184, Lecture 5: Viewing
http://inst.eecs.berkeley.edu/~cs184
![Page 2: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/2.jpg)
To DoTo Do
Questions/concerns about assignment 1?
Remember it is due next Thu. Ask me or TAs re problems
![Page 3: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/3.jpg)
MotivationMotivation
We have seen transforms (between coord systems)
But all that is in 3D
We still need to make a 2D picture
Project 3D to 2D. How do we do this?
This lecture is about viewing transformations
![Page 4: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/4.jpg)
Demo (Projection Tutorial)Demo (Projection Tutorial)
Nate Robbins OpenGL tutors
Projection.exe
Download others
![Page 5: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/5.jpg)
What we’ve seen so farWhat we’ve seen so far Transforms (translation, rotation, scale) as 4x4
homogeneous matrices
Last row always 0 0 0 1. Last w component always 1
For viewing (perspective), we will use that last row and w component no longer 1 (must divide by it)
![Page 6: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/6.jpg)
OutlineOutline
Orthographic projection (simpler)
Perspective projection, basic idea
Derivation of gluPerspective (handout: glFrustum)
Brief discussion of nonlinear mapping in z
Not well covered in textbook chapter 7. We follow section 3.5 of real-time rendering most closely. Handouts on this will be given out.
![Page 7: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/7.jpg)
ProjectionsProjections
To lower dimensional space (here 3D -> 2D)
Preserve straight lines
Trivial example: Drop one coordinate (Orthographic)
![Page 8: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/8.jpg)
Orthographic ProjectionOrthographic Projection
Characteristic: Parallel lines remain parallel
Useful for technical drawings etc.
Orthographic PerspectiveFig 7.1 in text
![Page 9: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/9.jpg)
ExampleExample
Simply project onto xy plane, drop z coordinate
![Page 10: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/10.jpg)
In generalIn general We have a cuboid that we want to map to the
normalized or square cube from [-1, +1] in all axes
We have parameters of cuboid (l,r ; t,b; n,f)
![Page 11: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/11.jpg)
Orthographic MatrixOrthographic Matrix First center cuboid by translating
Then scale into unit cube
![Page 12: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/12.jpg)
Transformation MatrixTransformation Matrix
20 0 0 1 0 0
22
0 0 0 0 1 02
20 0 0 0 0 1
20 0 0 10 0 0 1
l rr l
t bt bM
f nf n
Scale Translation (centering)
![Page 13: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/13.jpg)
CaveatsCaveats Looking down –z, f and n are negative (n > f)
OpenGL convention: positive n, f, negate internally
![Page 14: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/14.jpg)
Final ResultFinal Result
20 0
20 0
20 0
0 0 0 1
r l
r l r lt b
t b t bMf n
f n f n
20 0
20 0
20 0
0 0 0 1
r l
r l r lt b
t b t bglOrthof n
f n f n
![Page 15: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/15.jpg)
OutlineOutline
Orthographic projection (simpler)
Perspective projection, basic idea
Derivation of gluPerspective (handout: glFrustum)
Brief discussion of nonlinear mapping in z
![Page 16: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/16.jpg)
Perspective ProjectionPerspective Projection
Most common computer graphics, art, visual system
Further objects are smaller (size, inverse distance)
Parallel lines not parallel; converge to single point
B
A’
B’
Center of projection(camera/eye location)
APlane of Projection
![Page 17: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/17.jpg)
Overhead View of Our ScreenOverhead View of Our Screen
Looks like we’ve got some nice similar triangles here?
x x d xx
z d z
*y y d yy
z d z
, ,x y d , ,x y z
d
0,0,0
![Page 18: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/18.jpg)
In MatricesIn Matrices
Note negation of z coord (focal plane –d)
(Only) last row affected (no longer 0 0 0 1)
w coord will no longer = 1. Must divide at end
1 0 0 0
0 1 0 0
0 0 1 0
10 0 0
P
d
![Page 19: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/19.jpg)
VerifyVerify
1 0 0 0
0 1 0 0?0 0 1 0
110 0 0
x
y
z
d
*
*
1
d xx
zy
d yz zz dd
![Page 20: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/20.jpg)
OutlineOutline
Orthographic projection (simpler)
Perspective projection, basic idea
Derivation of gluPerspective (handout: glFrustum)
Brief discussion of nonlinear mapping in z
![Page 21: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/21.jpg)
Remember projection tutorialRemember projection tutorial
![Page 22: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/22.jpg)
Viewing FrustumViewing Frustum
Near plane
Far plane
![Page 23: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/23.jpg)
Screen (Projection Plane)Screen (Projection Plane)
Field of view(fovy)
width
height
Aspect ratio = width / height
![Page 24: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/24.jpg)
gluPerspectivegluPerspective
gluPerspective(fovy, aspect, zNear > 0, zFar > 0)
Fovy, aspect control fov in x, y directions
zNear, zFar control viewing frustum
![Page 25: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/25.jpg)
Overhead View of Our ScreenOverhead View of Our Screen
, ,x y d , ,x y z
d
0,0,0 1
? ?d
cot2
fovyd
![Page 26: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/26.jpg)
In MatricesIn Matrices
Simplest form:
Aspect ratio taken into account
Homogeneous, simpler to multiply through by d
Must map z vals based on near, far planes (not yet)
1 0
10 0 0
0 1 0 0
0 0
10 0 0
aspect
P
d
![Page 27: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/27.jpg)
In MatricesIn Matrices
A and B selected to map n and f to -1, +1 respectively
10 0 0
0 0 0
0 1 0 00 0 0
0 00 0
10 0 1 00 0 0
1 0
daspect
aspec
A B
t
dP
d
![Page 28: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/28.jpg)
Z mapping derivationZ mapping derivation
Simultaneous equations?
?1 0 1
A B z
Az B BA
z z
1
1
BA
nB
Af
2
f nA
f n
fnB
f n
![Page 29: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/29.jpg)
OutlineOutline
Orthographic projection (simpler)
Perspective projection, basic idea
Derivation of gluPerspective (handout: glFrustum)
Brief discussion of nonlinear mapping in z
![Page 30: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/30.jpg)
Mapping of Z is nonlinearMapping of Z is nonlinear
Many mappings proposed: all have nonlinearities
Advantage: handles range of depths (10cm – 100m)
Disadvantage: depth resolution not uniform
More close to near plane, less further away
Common mistake: set near = 0, far = infty. Don’t do this. Can’t set near = 0; lose depth resolution.
We discuss this more in review session
Az B BA
z z
![Page 31: Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing cs184](https://reader035.vdocuments.us/reader035/viewer/2022062320/56649d3e5503460f94a177f5/html5/thumbnails/31.jpg)
Summary: The Whole Viewing PipelineSummary: The Whole Viewing Pipeline
Modeltransformation
CameraTransformation
(gluLookAt)
PerspectiveTransformation(gluPerspective)
Viewporttransformation
Rastertransformation
Model coordinates
World coordinates
Eye coordinates
Screen coordinates
Window coordinates
Device coordinates
Slide courtesy Greg Humphreys