09-Viewing2 - UW Graphics Group

advertisement
Transformation Stack
Normalized Device Coordinates [-1,1]^3
Projective Transform (frustum coordinates = near, far, top, bottom, left right)
Field of View (assumes centered, left = -right)
Frustum coordinates
Viewing transformation – rotate / translate
“camera transformation” (lookfrom, lookat, up)







G = A-F
W = -G/|G|
U = T x W / | T x W|
V=WxU
Note: we find transpose (where global axes go)
Inverse = transpose for rotations
Then apply translation
Other ways to come up with camera as rotation and translation (remember: bring object to screen
volume)
Drawing in 3D via 2D
Homogeneous:



Lines -> lines, triangles -> triangles
Triangle (or line) in 3D -> Triangle in 2D – just need to transform the points (*)
Inside coordinate system gets messed up (halfway could be farther away, tilted triangle)
Can just draw triangles in 2D (and lines in 2D)
Rasterization: converting “objects” to “pixels”
What pixels does this object cover?
Old ways (or software)




Loop over pixels for lines
DDA -> Brezenham’s algorithm
Triangle edge list, horizontal spans (compute 2 lines and fill)
Not how hardware works (very serial)
Actual ways (hardware, even modern software)


Barycentric coordinates
Try “all” x,y and decide if its inside of triangle
Visibility
How to make objects opaque – closer object blocks one farther back.
Analytic visibility (historical, hard) – chop triangles, figure out which parts can be seen
Useful for line drawings (where we don’t fill in regions)
Regular drawing: see last thing drawn (overwrite)
(1) Change order that things get drawn in (painter’s algorithm) – sort by depth
(2) Check while drawing (don’t over-write)
Painter’s algorithm





Can’t handle intersections
Can’t handle cycles
Requires you to know all triangles ahead of time
Fancy algorithms – build trees, fast re-sorts (when view direction changes), divide on
intersection
Forms basis for pre-computed visibility (quickly determine things without drawing all of them)
Z-Buffer (depth buffer)






Idea of storing depth
Per-pixel decision
Sampling issue
Throwing memory at the problem (old days – really tough)
Z-precision issues
Clear to max depth, read/test/write
Good points



Memory is cheap nowadays
Generally pretty order-independent
Simple
Bad points





Decision per pixel
Limited precision for Z
o Floating point used to be way too expensive (now, practical)
o Non-linear Z (because of perspective divide thing)
o Near / Far planes set resolution
Z-fighting (if things at the same depth) – order matters
Z-fighting (if things are close) – flipping based on numerical noise
Order matters for transparent
o (need to have transparent thing in front drawn last)
This is what modern graphics cards do (draw triangles, with Z-buffer).
3D Rotations (an intro)
Rotations (motions) vs. Orientations (configurations) vs. Rotations (relative orientations)
3 D.O.F. (point in direction, rotate around it)
Since loops around space is complex – SO(3) – group of positive, orthonormal 3x3 matrices
Cannot map nicely to R^3 – will be a singularity
Cannot map nicely to R^4 - redundancy
Rotations about an axis – always will be an axis – Basis axes, arbitrary axis
Euler Theorems
–
Any rotation can be represented by a single rotation about an arbitrary axis (axis-angle form)
–
Any rotation can be represented by 3 rotations about fixed axes (Euler Angle form)
–
XYZ, XZX, any non-repeating set works
–
Each set is different (gets different singularities)
Building rotations
–
Pick a vector (for an axis)
–
Pick another perpindicular vector (or make one w/cross product)
–
Get third vector by cross product
“Euler Angles” – horrible term
•
Pick convention
–
Are axes local or global?
–
Local: roll, pitch, yaw
–
What order?
•
Apply 3 rotations
•
Good news: 3 numbers
•
Bad news:
–
Can’t add, can’t compose
–
Many representations for any rotation
–
Singularities
Rot X ~~ Rot Y Rot Z - same place, 2 ways – long way from one to the other!
Axis Angle – harder to think about (for most people)
Rotation Vector – multiply by angle (scale length)
Lots of different 360 degree rotations. Shells at different radii
Scale by sin(theta)? (makes math messy)
Still can’t compose or interpolate
Quaternion
4D
Unit Sphere
Encoding rotation vectors cos, sin V
Compose by multiplication
Interpolate by careful formula
Download