viewing, projections i/ii week 2, tue may 17 · week 2, tue may 17. news extra lab coverage with...

126
University of British Columbia CPSC 314 Computer Graphics May-June 2005 Tamara Munzner http://www.ugrad.cs.ubc.ca/~cs314/Vmay2005 Viewing, Projections I/II Week 2, Tue May 17

Upload: others

Post on 19-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

University of British ColumbiaCPSC 314 Computer Graphics

May-June 2005

Tamara Munzner

http://www.ugrad.cs.ubc.ca/~cs314/Vmay2005

Viewing, Projections I/II

Week 2, Tue May 17

Page 2: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

News

� extra lab coverage with TAs� 12-2 Mondays, Wednesdays� for rest of term� just for answering questions, no presentations

Page 3: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Reading: Today

� FCG Chapter 6 � FCG Section 5.3.1 � RB rest of Chap Viewing� RB rest of App Homogeneous Coords

Page 4: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Reading: Next Time

� FCG Section 2.11 � FCG Chap 3

� except 3.8� FCG Chap 17 Human Vision (pp 293-298) � FCG Chap 18 Color pp 301-311

� until Section 18.9 Tone Mapping

Page 5: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Textbook Errata

� list at http://www.cs.utah.edu/~shirley/fcg/errata� p 113

� last matrix, last column denominators� D-a -> A-a� E-b -> B-b� F-c -> C-c

� p 120 � "Sometimes we will want to take the inverse of

P" should be "M_p" instead of "P"

Page 6: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Correction2: Vector-Vector Subtraction

� subtract: vector - vector = vector

���

���

−−−

=−

33

22

11

vu

vu

vu

vu

)0,4,1()1,1,3()1,5,2()2,3()4,6()2,3(

−=−−−−=−

=− vu

uv

v−

)( vu −+

vu + v

u uv −v

uargument reversal

2

Page 7: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: 2D Rotation

θ

(x, y)

(x�, y�)x� = x cos(θ) - y sin(θ)y� = x sin(θ) + y cos(θ)

� counterclockwise, RHS

( ) ( )( ) ( ) �

���

���

���

� −=�

���

y

x

y

x

θθθθ

cossinsincos

''

Page 8: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: 2D Rotation From Trig Identities

x = r cos (φ)y = r sin (φ)x� = r cos (φ + θ)y� = r sin (φ + θ)

Trig Identity…x� = r cos(φ) cos(θ) – r sin(φ) sin(θ)y� = r sin(φ) cos(θ) + r cos(φ) sin(θ)

Substitute…x � = x cos(θ) - y sin(θ)y � = x sin(θ) + y cos(θ)

θ

(x, y)

(x�, y�)

φ

Page 9: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: 2D Rotation: Another Derivation

θθθθ

cossin'sincos'

yxy

yxx

+=−=

xx

xx'

x'= A − B

BB

AA

(x�,y�)

(x,y) A = x cosθθθθθθθθθ

xx

Page 10: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: Shear, Reflection

� shear along x axis� push points to right in proportion to height

� reflect across x axis� mirror

x

y

x

y

��

���

�+��

���

���

���

�=��

���

′′

00

101

y

xsh

y

x x

��

���

�+��

���

���

���

−=�

���

′′

00

1001

y

x

y

x

x x

Page 11: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: 2D Transformations

��

���

�=�

���

++

=��

���

�+��

���

''

y

x

by

ax

b

a

y

x

( ) ( )( ) ( ) �

���

���

���

� −=�

���

y

x

y

x

θθθθ

cossinsincos

''

��

���

���

���

�=�

���

y

x

b

a

y

x

00

''

scaling matrix rotation matrix

��

���

�=��

���

���

���

''

y

x

y

x

dc

ba

translation multiplication matrix??

vector addition

matrix multiplicationmatrix multiplication

),( ba(x,y)

(x�,y�)

Page 12: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: Linear Transformations� linear transformations are combinations of

� shear� scale� rotate� reflect

� properties of linear transformations� satisifes T(sx+ty) = s T(x) + t T(y)� origin maps to origin� lines map to lines� parallel lines remain parallel� ratios are preserved� closed under composition

��

���

���

���

�=�

���

y

x

dc

ba

y

x

''

dycxy

byaxx

+=+=

''

Page 13: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: Homogeneous Coordinates Geometrically

� point in 2D cartesian + weight w =point P in 3D homog. coords

� multiples of (x,y,w) � all homogeneous points on 3D line L

represent same 2D cartesian point� homogenize to convert homog. 3D

point to cartesian 2D point� divide by w to get (x/w, y/w, 1)

� w=0 is direction; (0,0,0) is undefined

),,( wyx

homogeneoushomogeneous

),(wy

wx

cartesiancartesian

/ w/ w

xx

yy

ww

w=w=11

���

���

⋅⋅

w

wy

wx

���

���

1y

x

Page 14: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: 3D Homog Transformations

� use 4x4 matrices for 3D transformations

����

����

����

����

=

����

����

111

11

1'''

zy

x

cb

a

zy

x

translate(a,b,c)translate(a,b,c)

����

����

����

����

−=

����

����

11cossin

sincos1

1'

''

z

y

x

z

y

x

θθθθ

),(Rotate θx

����

����

����

����

=

����

����

111''

'

z

y

x

c

b

a

z

y

x

scale(a,b,c)scale(a,b,c)

����

����

−1

cossin1

sincos

θθ

θθ

),(Rotate θy

����

����

� −

11

cossinsincos

θθθθ

),(Rotate θz

Page 15: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: Affine Transformations� affine transforms are combinations of

� linear transformations� translations

� properties of affine transformations� origin does not necessarily map to origin� lines map to lines� parallel lines remain parallel� ratios are preserved� closed under composition

���

���

���

���

=���

���

w

y

x

fed

cba

w

y

x

100''

Page 16: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: Composing Transformations

Ta Tb = Tb Ta, but RaTa Tb = Tb Ta, but Ra Rb Rb !=!= Rb Rb Ra and TaRa and Ta Rb Rb !=!= Rb Rb Ta Ta

Page 17: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: Composing Transforms

� order matters� 4x4 matrix multiplication not commutative!

� moving to origin � transformation of geometry into coordinate

system where operation becomes simpler� perform operation� transform geometry back to original

coordinate system

Page 18: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

p'= TRpReview: Composing Transformations

� which direction to read? � right to left

� interpret operations wrt fixed coordinates � moving object

� left to right� interpret operations wrt local coordinates � changing coordinate system� OpenGL updates current matrix with postmultiply

� glTranslatef(2,3,0);� glRotatef(-90,0,0,1);� glVertexf(1,1,1);

� specify vector last, in final coordinate system� first matrix to affect it is specified second-to-last

OpenGL pipeline ordering!

Page 19: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: Arbitrary Rotation

� problem: � given two orthonormal coordinate systems XYZ and UVW � find transformation from one to the other

� answer: � transformation matrix R whose columns are U,V,W:

R =ux vx wx

uy vy wy

uz vz wz

� � �

� � �

Y Z

X

W

V

U

Page 20: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

(2,1)

(1,1)

(1,1)

left to right: changing coordinate system

right to left: moving object

translate by (-1,0)

Review: Interpreting Transformations

� same relative position between object and basis vectors

intuitive?

OpenGL

p'= TRp

Page 21: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Review: Transformation Hierarchies

� transforms apply to graph nodes beneath them� design structure so that object doesn’t fall apart� instancing

Page 22: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

glPushMatrixglPushMatrix()()

glPopMatrixglPopMatrix()()

AA

BB

CC

AA

BB

CC

AA

BB

CC

CC

glScale3f(2,2,2)glScale3f(2,2,2)

D = C scale(2,2,2) trans(1,0,0)D = C scale(2,2,2) trans(1,0,0)

AA

BB

CC

DD

DrawSquareDrawSquare()()glTranslate3f(1,0,0)glTranslate3f(1,0,0)

DrawSquareDrawSquare()()

Review: Matrix Stacks� OpenGL matrix calls postmultiply matrix M onto current

matrix P, overwrite it to be PM� or can save intermediate states with stack� no need to compute inverse matrices all the time� modularize changes to pipeline state� avoids accumulation of numerical errors

Page 23: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Review: Transforming Normals

� shear, nonuniform scale makes normal nonperpendicular� need to use inverse transpose matrix instead

Page 24: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Review: Display Lists� precompile/cache block of OpenGL code for reuse

� efficiency� exact optimizations depend on driver

� multiple instances of same object� static objects redrawn often� exploit hierarchical structure when possible

� set up list once with glNewList/glEndList� call multiple times

Page 25: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Viewing

Page 26: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Using Transformations

� three ways� modelling transforms

� place objects within scene (shared world)� viewing transforms

� place camera� projection transforms

� change type of camera

Page 27: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Viewing and Projection

� need to get from 3D world to 2D image� projection: geometric abstraction

� what eyes or cameras do� two pieces

� viewing transform: � where is the camera, what is it pointing at?

� perspective transform: 3D to 2D� flatten to image

Page 28: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Rendering Pipeline

GeometryDatabaseGeometryGeometryDatabaseDatabase

Model/ViewTransform.Model/ViewModel/ViewTransform.Transform. LightingLightingLighting Perspective

Transform.PerspectivePerspectiveTransform.Transform. ClippingClippingClipping

ScanConversion

ScanScanConversionConversion

DepthTest

DepthDepthTestTestTexturingTexturingTexturing BlendingBlendingBlending

Frame-buffer

FrameFrame--bufferbuffer

Page 29: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Rendering Pipeline

GeometryDatabaseGeometryGeometryDatabaseDatabase

Model/ViewTransform.Model/ViewModel/ViewTransform.Transform. LightingLightingLighting Perspective

Transform.PerspectivePerspectiveTransform.Transform. ClippingClippingClipping

ScanConversion

ScanScanConversionConversion

DepthTest

DepthDepthTestTestTexturingTexturingTexturing BlendingBlendingBlending

Frame-buffer

FrameFrame--bufferbuffer

Page 30: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Ren

deri

ng P

ipel

ine

���

������

�� ��������

����

���

�����

������

����

�������

�����

����

��� ��

����

�����

����

Page 31: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

� result� all vertices of scene in shared 3D world coordinate system

���������� � �������� ����

� ��������� �������� �

� ��� ���� ��������

��� ������� ��������

Rendering Pipeline

Page 32: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

� result� scene vertices in 3D view(camera) coordinate system

���������� � �������� ����

� ��������� �������� �

� ��� ���� ��������

��� ������� ��������

Rendering Pipeline

Page 33: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

� result� 2D screen coordinates of clipped vertices

���������� � �������� ����

� ��������� �������� �

� ��� ���� ��������

��� ������� ��������

Rendering Pipeline

Page 34: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Coordinate Systems

� result of a transformation� names

� convenience� giraffe: neck, head, tail

� standard conventions in graphics pipeline� object/modelling� world� camera/viewing/eye� screen/window� raster/device

Page 35: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Projective Rendering Pipeline

OCS - object/model coordinate system

WCS - world coordinate system

VCS - viewing/camera/eye coordinate system

CCS - clipping coordinate system

NDCS - normalized device coordinate system

DCS - device/display/screen coordinate system

OCSOCS O2WO2W VCSVCS

CCSCCS

NDCSNDCS

DCSDCS

modelingmodelingtransformationtransformation

viewingviewingtransformationtransformation

projectionprojectiontransformationtransformation

viewportviewporttransformationtransformation

perspectiveperspectivedividedivide

object world viewing

device

normalizeddevice

clipping

W2VW2V V2CV2C

N2DN2D

C2NC2N

WCSWCS

Page 36: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Basic Viewing

� starting spot - OpenGL� camera at world origin

� probably inside an object

� y axis is up� looking down negative z axis

� why? RHS with x horizontal, y vertical, z out of screen

� translate backward so scene is visible� move distance d = focal length

� can use rotate/translate/scale to move camera� demo: Nate Robins tutorial transformations

Page 37: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Viewing in Project 1

� where is camera in template code?� 5 units back, looking down -z axis

Page 38: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Convenient Camera Motion

� rotate/translate/scale not intuitive� arbitrary viewing position

� eye point, gaze/lookat direction, up vector

Page 39: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Convenient Camera Motion

� rotate/translate/scale not intuitive� arbitrary viewing position

� eye point, gaze/lookat direction, up vector

Peye

Pref

upview

eye

lookaty

z

xWCS

Page 40: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

From World to View Coordinates: W2V

� translate eye to origin� rotate view vector (lookat – eye) to w axis� rotate around w to bring up into vw-plane

y

z

xWCS

v

u

VCS

Peyew

Pref

upview

eye

lookat

Page 41: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

OpenGL Viewing Transformation

gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz)

� postmultiplies current matrix, so to be safe:

glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz)// now ok to do model transformations

� demo: Nate Robins tutorial projection

Page 42: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Deriving W2V Transformation

� translate eye to origin T =

1 0 0 −ex0 1 0 −ey0 0 1 −ez0 0 0 1

� � � �

� � � �

y

z

xWCS

v

u

VCS

Peyew

Pref

upview

eye

lookat

Page 43: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Deriving W2V Transformation

� rotate view vector (lookat – eye) to w axis� w is just opposite of view/gaze vector g

w = −ˆ g = − gg

y

z

xWCS

v

u

VCS

Peyew

Pref

upview

eye

lookat

Page 44: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Deriving W2V Transformation

� rotate around w to bring up into vw-plane� u should be perpendicular to vw-plane, thus

perpendicular to w and up vector t� v should be perpendicular to u and w

u = t × wt × w

v = w × uy

z

xWCS

v

u

VCS

Peyew

Pref

upview

eye

lookat

Page 45: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Deriving W2V Transformation� rotate from WCS xyz into uvw coordinate system

with matrix that has rows u, v, w

� reminder: rotate from uvw to xyz coord sys with matrix M that has columns u,v,w� rotate from xyz coord sys to uvw coord sys with

matrix MT that has rows u,v,w

u = t × wt × w

R =

ux uy uz 0vx vy vz 0wx wy wz 00 0 0 1

� � � �

� � � �

v = w × u w = −ˆ g = − gg

Page 46: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Deriving W2V Transformation

� M=RT

Mworld− > view =

ux uy uz 0vx vy vz 0wx wy wz 00 0 0 1

� � � �

� � � �

1 0 0 −ex

0 1 0 −ey

0 0 1 −ez

0 0 0 1

� � � �

� � � �

=

ux uy uz −u• evx vy vz −v• ewx wy wz −w•e0 0 0 1

� � � �

� � � �

T =

1 0 0 −ex0 1 0 −ey0 0 1 −ez0 0 0 1

� � � �

� � � �

R =

ux uy uz 0vx vy vz 0wx wy wz 00 0 0 1

� � � �

� � � �

Page 47: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Moving the Camera or the World?

� two equivalent operations� move camera one way vs. move world other way

� example� initial OpenGL camera: at origin, looking along -z axis� create a unit square parallel to camera at z = -10� translate in z by 3 possible in two ways

� camera moves to z = -3� Note OpenGL models viewing in left-hand coordinates

� camera stays put, but square moves to -7

� resulting image same either way� possible difference: are lights specified in world or view

coordinates?

Page 48: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

World vs. Camera Coordinates

WW

aa = = (1,1)(1,1)WW

aa

bb = = (1,1)(1,1)C1 C1 = (3,2)= (3,2)WW

cc = = (1,1)(1,1)C2C2= = (1,3)(1,3)C1C1 = (4,4)= (4,4)WW

C1C1

bb

C2C2

cc

Page 49: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Projections I

Page 50: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Pinhole Camera

� ingredients� box� film� hole punch

� results� pictures!

www.kodak.com

www.pinhole.org

www.debevec.org/Pinhole

Page 51: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Pinhole Camera

� theoretical perfect pinhole

film plane

pinhole

one rayof projection

Page 52: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Pinhole Camera

� non-zero sized hole

film plane

pinhole

multiple raysof projection

Page 53: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Pinhole Camera

� field of view and focal length

film plane

field of viewpinhole

focallength

Page 54: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Pinhole Camera

� field of view and focal length

film plane

field of viewpinhole

focallength

Page 55: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Real Cameras

real pinhole camerareal pinhole cameraapertureaperture

ff

lenslens

cameracamera

price to pay: limited depth of fieldprice to pay: limited depth of field

� pinhole camera has small aperture (lens opening)� hard to get enough light to expose the film

� lens permits larger apertures� lens permits changing distance to film plane without

actually moving the film plane

Page 56: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Graphics Cameras

� real pinhole camera: image inverted

imageimageplaneplane

eyeeyepointpoint

� computer graphics camera: convenient equivalent

imageimageplaneplane

eyeeyepointpoint

center ofcenter ofprojectionprojection

Page 57: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

General Projection

� image plane need not be perpendicular to view plane

imageimageplaneplane

eyeeyepointpoint

imageimageplaneplane

eyeeyepointpoint

Page 58: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective Projection

� our camera must model perspective

Page 59: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective Projection

� our camera must model perspective

Page 60: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Projection

� our camera must model perspective

Page 61: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Projections

oneone--pointpointperspectiveperspective

twotwo--pointpointperspectiveperspective threethree--pointpoint

perspectiveperspective

� classified by vanishing points

Page 62: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Projective Transformations

� planar geometric projections� planar: onto a plane� geometric: using straight lines� projections: 3D -> 2D� aka projective mappings

� counterexamples?

Page 63: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Projective Transformations

� properties� lines mapped to lines and triangles to triangles� parallel lines do NOT remain parallel

� e.g. rails vanishing at infinity� affine combinations are NOT preserved

� e.g. center of a line does not map to center of projected line (perspective foreshortening)

Page 64: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective Projection

� project all geometry � through common center of projection (eye point) � onto an image plane

xxzz xxzz

yy

xx

--zz

Page 65: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective Projection

how tall shouldthis bunny be?

COPCOP

projectionprojectionplaneplane

Page 66: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Basic Perspective Projection

similar trianglessimilar triangles

→=zy

dy'

zdy

y⋅='

zz

P(x,y,z)P(x,y,z)

P(P(x’x’,,yy’,z’)’,z’)

z’=z’=dd

yy

zdx

x⋅='

� nonuniform foreshortening� not affine

dz ='butbut→=zx

dx'

Page 67: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective Projection

� desired result for a point [x, y, z, 1]T projected onto the view plane:

� what could a matrix look like to do this?

dzdz

yzdy

ydz

xzdx

x

zy

dy

zx

dx

==⋅==⋅=

==

,','

',

'

Page 68: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Simple Perspective Projection Matrix

�������

�������

d

dzy

dzx

/

/

Page 69: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Simple Perspective Projection Matrix

�������

�������

d

dzy

dzx

/

/ is homogenized version of

where w = z/d ����

����

dz

z

y

x

/

Page 70: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Simple Perspective Projection Matrix

����

����

����

����

=

����

����

10100010000100001

/z

y

x

ddz

z

y

x�������

�������

d

dzy

dzx

/

/ is homogenized version of

where w = z/d ����

����

dz

z

y

x

/

Page 71: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Projection

� expressible with 4x4 homogeneous matrix� use previously untouched bottom row

� perspective projection is irreversible� many 3D points can be mapped to same

(x, y, d) on the projection plane� no way to retrieve the unique z values

Page 72: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Moving COP to Infinity

� as COP moves away, lines approach parallel� when COP at infinity, orthographic view

Page 73: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Orthographic Camera Projection

� camera’s back plane parallel to lens

� infinite focal length� no perspective

convergence

� just throw away z values

���

���

=���

���

0y

x

z

y

x

p

p

p

����

����

����

����

=

����

����

11000000000100001

1z

y

x

z

y

x

p

p

p

Page 74: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective to Orthographic

� transformation of space� center of projection moves to infinity� view volume transformed

� from frustum (truncated pyramid) to parallelepiped (box)

--zz

xx

--zz

xx

FrustumFrustum ParallelepipedParallelepiped

Page 75: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

View Volumes

� specifies field-of-view, used for clipping� restricts domain of z stored for visibility test

z

perspective view volumeperspective view volume orthographic view volumeorthographic view volume

x=left

x=right

y=top

y=bottom z=-near z=-farxVCS x

z

VCS

yy

x=lefty=top

x=right

z=-farz=-neary=bottom

Page 76: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

View Volume

� convention� viewing frustum mapped to specific

parallelepiped� Normalized Device Coordinates (NDC)� same as clipping coords

� only objects inside the parallelepiped get rendered

� which parallelepiped? � depends on rendering system

Page 77: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Normalized Device Coordinates

left/right x =+/- 1, top/bottom y =+/- 1, near/far z =+/- 1

--zz

xx

FrustumFrustum

z=z=--nn z=z=--ff

rightright

leftleft zz

xx

x= x= --11z=1z=1

x=1x=1

Camera coordinatesCamera coordinates NDCNDC

z= z= --11

Page 78: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Understanding Z

� z axis flip changes coord system handedness� RHS before projection (eye/view coords)� LHS after projection (clip, norm device coords)

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

x

z

NDCS

y

(-1,-1,-1)

(1,1,1)

Page 79: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Understanding Z

near, far always positive in OpenGL callsglOrthoglOrtho(left,right,(left,right,botbot,top,near,far);,top,near,far);glFrustumglFrustum(left,right,(left,right,botbot,top,near,far);,top,near,far);glPerspectiveglPerspective((fovyfovy,aspect,near,far);,aspect,near,far);

orthographic view volumeorthographic view volume

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

perspective view volumeperspective view volume

x=left

x=right

y=top

y=bottom z=-near z=-farxVCS

y

Page 80: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Understanding Z

� why near and far plane?� near plane:

� avoid singularity (division by zero, or very small numbers)

� far plane:� store depth in fixed-point representation

(integer), thus have to have fixed range of values (0…1)

� avoid/reduce numerical precision artifacts for distant objects

Page 81: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Orthographic Derivation

� scale, translate, reflect for new coord sys

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

x

z

NDCS

y

(-1,-1,-1)

(1,1,1)

Page 82: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Orthographic Derivation

� scale, translate, reflect for new coord sys

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

x

z

NDCS

y

(-1,-1,-1)

(1,1,1)

byay +⋅='1'

1'−=→=

=→=yboty

ytopy

Page 83: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Orthographic Derivation

� scale, translate, reflect for new coord sys

byay +⋅='1'

1'−=→=

=→=yboty

ytopy

bottopbottop

b

bottoptopbottop

b

bottoptop

b

btopbottop

−−−=

−⋅−−=

−⋅−=

+−

=

2)(

21

21

bbota

btopa

+⋅=−+⋅=

11

bottopa

topbota

topabota

botatopa

botabtopab

−=

+−=⋅−−⋅−=−−

⋅−−=⋅−⋅−−=⋅−=

2)(2

)()1(111

1,1

Page 84: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Orthographic Derivation

� scale, translate, reflect for new coord sys

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

byay +⋅='1'

1'−=→=

=→=yboty

ytopy

bottopbottop

b

bottopa

−+−=

−= 2

same idea for right/left, far/near same idea for right/left, far/near

Page 85: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Orthographic Derivation

� scale, translate, reflect for new coord sys

P

nearfarnearfar

nearfar

bottopbottop

bottop

leftrightleftright

leftright

P

����������

����������

−+−

−−

−+−

−+−

=

1000

200

02

0

002

'

Page 86: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Orthographic Derivation

� scale, translate, reflect for new coord sys

P

nearfarnearfar

nearfar

bottopbottop

bottop

leftrightleftright

leftright

P

����������

����������

−+−

−−

−+−

−+−

=

1000

200

02

0

002

'

Page 87: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Orthographic Derivation

� scale, translate, reflect for new coord sys

P

nearfarnearfar

nearfar

bottopbottop

bottop

leftrightleftright

leftright

P

����������

����������

−+−

−−

−+−

−+−

=

1000

200

02

0

002

'

Page 88: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Orthographic Derivation

� scale, translate, reflect for new coord sys

P

nearfarnearfar

nearfar

bottopbottop

bottop

leftrightleftright

leftright

P

����������

����������

−+−

−−

−+−

−+−

=

1000

200

02

0

002

'

Page 89: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Orthographic OpenGL

glMatrixModeglMatrixMode(GL_PROJECTION);(GL_PROJECTION);glLoadIdentityglLoadIdentity();();glOrthoglOrtho(left,right,(left,right,botbot,top,near,far);,top,near,far);

Page 90: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Projections II

Page 91: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

NDC to Viewport Transformation

� generate pixel coordinates� map x, y from range –1…1 (NDC) to pixel

coordinates on the display� involves 2D scaling and translation

xx

yy displaydisplay

viewportviewport

Page 92: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

NDC to Viewport Transformation

(-1,-1)

(1,1)(1,1)

(0,0)(0,0)

(w,h)(w,h)

NDCSNDCS DCSDCS

2)1( += NDCS

DCS

xwx

2)1( += NDCS

DCS

yhy

2)1( += NDCS

DCS

zz

glViewport(x,y,a,b);defaultdefault::

aa

bb

xx

yy

glViewport(0,0,w,h);

OpenGLOpenGL

� 2D scaling and translation

Page 93: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Origin Location

� yet more possibly confusing conventions� OpenGL: lower left� most window systems: upper left

� often have to flip your y coordinates� when interpreting mouse position

Page 94: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective Example

tracks in VCS:left x=-1, y=-1right x=1, y=-1

view volumeleft = -1, right = 1bot = -1, top = 1near = 1, far = 4

z=-1

z=-4

x

zVCS

top view

-1-1 1

1

-1NDCS

(z not shown)

realmidpoint

0 xmax-10DCS

(z not shown)

ymax-1

x=-1 x=1

Page 95: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Viewing Transformation

OCSOCS WCSWCS VCSVCSmodelingmodeling

transformationtransformationviewingviewing

transformationtransformation

Mmod Mcam

OpenGL ModelView matrix

object world viewing

y

x

VCS

Peyez

y xWCS

y

zOCS

imageplane

Page 96: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Projective Rendering Pipeline

OCS - object/model coordinate system

WCS - world coordinate system

VCS - viewing/camera/eye coordinate system

CCS - clipping coordinate system

NDCS - normalized device coordinate system

DCS - device/display/screen coordinate system

OCSOCS O2WO2W VCSVCS

CCSCCS

NDCSNDCS

DCSDCS

modelingmodelingtransformationtransformation

viewingviewingtransformationtransformation

projectionprojectiontransformationtransformation

viewportviewporttransformationtransformation

perspectiveperspectivedividedivide

object world viewing

device

normalizeddevice

clipping

W2VW2V V2CV2C

N2DN2D

C2NC2N

WCSWCS

Page 97: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective Projection

� specific example� assume image plane at z = -1� a point [x,y,z,1]T projects to [-x/z,-y/z,-z/z,1]T ≡

[x,y,z,-z]T

--zz

����

����

1z

y

x

����

����

− z

z

y

x

Page 98: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective Projection

����

����

−−−

����

����

=

����

����

����

����

=

�����

����

����

11//

10100010000100001

1

zy

zx

z

z

y

x

z

y

x

z

y

x

T

alter walter w / w/ w

projectionprojectiontransformationtransformation

perspectiveperspectivedivisiondivision

Page 99: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Canonical View Volumes

� standardized viewing volume representation

orthographic perspectiveorthogonalparallel

x or y

-z

x or y

-z1

-1

-1FrontPlane

frontplane

backplane

backplane

x or y = +/- z

Page 100: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Why Canonical View Volumes?

� permits standardization� clipping

� easier to determine if an arbitrary point is enclosed in volume

� consider clipping to six arbitrary planes of a viewing volume versus canonical view volume

� rendering� projection and rasterization algorithms can be

reused

Page 101: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Projection Normalization

� one additional step of standardization� warp perspective view volume to orthogonal

view volume� render all scenes with orthographic projection!

Z

x

z=α z=d

Z

x

z=0 z=d

Page 102: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Predistortion

Page 103: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Normalization

� perspective viewing frustum transformed to cube

� orthographic rendering of cube produces same image as perspective rendering of original frustum

Page 104: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Demos

� Tuebingen applets from Frank Hanisch� http://www.gris.uni-tuebingen.de/projects/grdev/doc/html/etc/

AppletIndex.html#Transformationen

Page 105: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Warp

� matrix formulation

� preserves relative depth (third coordinate)� what does mean?

��

−⋅−=

������

������

−⋅−

− dz

ddz

yx

dd

dddzyx ,

)(,,

000

100

00100001

)1,,,(α

α

αα

α

( , , )/

,/

,x y zx

z dy

z dd

d zp p p =−

−��

��

��

2

α

0=α

Page 106: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Warp

� matrix formulation

� preserves relative depth (third coordinate)� what does mean?

1 0 0 00 1 0 0

0 0d

d−α−α ⋅ dd−α

0 01d

0

� � � � �

� � � � �

xyz1

� � �

� � � =

xy

(z−α)⋅ dd−α

zd

� � � � �

� � � � �

( , , )/

,/

,x y zx

z dy

z dd

d zp p p =−

−��

��

��

2

α

0=α

Page 107: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Projection Normalization

� distort such that orthographic projection of distorted objects is desired persp projection� separate division from standard matrix

multiplies� clip after warp, before divide� division: normalization

CCSCCSNDCSNDCS

alter walter w / w/ w

VCSVCSprojectionprojection

transformationtransformation

viewing normalizeddevice

clipping

perspectiveperspectivedivisiondivision

V2CV2C C2NC2N

Page 108: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Projective Rendering Pipeline

OCS - object coordinate system

WCS - world coordinate system

VCS - viewing coordinate system

CCS - clipping coordinate system

NDCS - normalized device coordinate system

DCS - device coordinate system

OCSOCS WCSWCS VCSVCS

CCSCCS

NDCSNDCS

DCSDCS

modelingmodelingtransformationtransformation

viewingviewingtransformationtransformation

projectionprojectiontransformationtransformation

viewportviewporttransformationtransformation

alter walter w

/ w/ w

object world viewing

device

normalizeddevice

clipping

perspectiveperspectivedivisiondivision

glVertex3f(x,y,z)glVertex3f(x,y,z)

glTranslatefglTranslatef(x,y,z)(x,y,z)glRotatefglRotatef((thth,x,y,z),x,y,z)........

gluLookAtgluLookAt(...)(...)

glFrustumglFrustum(...)(...)

glutInitWindowSizeglutInitWindowSize(w,h)(w,h)glViewportglViewport(x,y,a,b)(x,y,a,b)

O2WO2W W2VW2V V2CV2C

N2DN2D

C2NC2N

Page 109: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Coordinate Systems

http://www.btinternet.com/~danbgs/perspective/

Page 110: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Derivation

x

z

NDCS

y

(-1,-1,-1)

(1,1,1)x=left

x=right

y=top

y=bottom z=-near z=-farx

VCS

y

z

Page 111: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Derivation

earlier:earlier:

complete: shear, scale, projectioncomplete: shear, scale, projection--normalizationnormalization

����

����

����

����

=

����

����

1010000

0000

''

''

z

y

x

DC

BF

AE

w

z

y

x

����

����

����

����

=

����

����

10/100010000100001

''''

z

y

x

dw

z

y

x

Page 112: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Derivation

����

����

����

����

=

����

����

1010000

0000

''''

z

y

x

DC

BF

AE

w

z

y

x

zw

DCzz

BzFyy

AzExx

−=+=+=+=

'''

'

,)(

1 ,1 ,1

,1 ,'

1 ,''

' ,'

Bnear

topFB

zy

Fz

zB

zy

F

zBzFy

wBzFy

wBzFy

wy

BzFyy

−−−

=−−

=−

+−

=

−+=+=+=+=

1'/'1'/'

1'/'1'/'

1'/'1'/'

−=→−==→−=

−=→==→=

−=→==→=

wzfarz

w znear z

wybottomy

w ytop y

wxrightx

w xleft x

Bneartop

F −=1

Page 113: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Derivation

� similarly for other 5 planes� 6 planes, 6 unknowns

�������

�������

−−

−−+−

−+

−+

0100

2)(00

02

0

002

nffn

nfnf

btbt

btn

lrlr

lrn

Page 114: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Example

�������

�������

−−

−−+−

−+

−+

0100

2)(00

02

0

002

nffn

nfnf

btbt

btn

lrlr

lrn

view volume� left = -1, right = 1� bot = -1, top = 1� near = 1, far = 4

����

����

−−−

01003/83/500

00100001

Page 115: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective Example

����

����

����

����

−−−

=

����

����

−−−

1

11

13/83/5

11

3/83/51

1

VCS

VCS

VCS z

z

z

VCSNDCS

VCSNDCS

VCSNDCS

zz

zy

zx

38

35

/1

/1

+=

=−=

/ w/ w

Page 116: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Asymmetric Frusta

� our formulation allows asymmetry� why bother?

--zz

xx

FrustumFrustumrightright

leftleft--zz

xx

FrustumFrustum

z=z=--nn z=z=--ff

rightright

leftleft

Page 117: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Simpler Formulation

� left, right, bottom, top, near, far� nonintuitive� often overkill

� look through window center� symmetric frustum

� constraints� left = -right, bottom = -top

Page 118: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Field-of-View Formulation

� FOV in one direction + aspect ratio (w/h)� determines FOV in other direction� also set near, far (reasonably intuitive)

--zz

xx

FrustumFrustum

z=z=--nn z=z=--ff

ααααααααfovxfovx/2/2

fovyfovy/2/2hh

ww

Page 119: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Perspective OpenGL

glMatrixMode(GL_PROJECTION);glLoadIdentity();

glFrustum(left,right,bot,top,near,far);orglPerspective(fovy,aspect,near,far);

Page 120: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Demo: Frustum vs. FOV

� Nate Robins tutorial (take 2):� http://www.xmission.com/~nate/tutors.html

Page 121: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Projection Taxonomyplanarplanar

projectionsprojections

perspective:perspective:1,2,31,2,3--pointpoint parallelparallel

obliqueoblique orthographicorthographic

cabinetcabinet cavaliercavalier

top,top,front,front,sideside

axonometric:axonometric:isometricisometricdimetricdimetrictrimetrictrimetric

http://ceprofs.tamu.edu/tkramer/ENGR%20111/5.1/20

Page 122: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Perspective Projections

oneone--pointpointperspectiveperspective

twotwo--pointpointperspectiveperspective threethree--pointpoint

perspectiveperspective

� classified by vanishing points

Page 123: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

Parallel Projection

� projectors are all parallel� vs. perspective projectors that converge� orthographic: projectors perpendicular to

projection plane� oblique: projectors not necessarily

perpendicular to projection plane

ObliqueOrthographic

Page 124: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Axonometric Projections

� projectors perpendicular to image plane� select axis lengths

http://ceprofs.tamu.edu/tkramer/ENGR%20111/5.1/20

Page 125: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Oblique Projections

xx

yy

zz

α

cavaliercavalier

dddd

xx

yy

zz

α

cabinetcabinet

dd

d / 2d / 2

� projectors oblique to image plane� select angle between front and z axis

� lengths remain constant� both have true front view

� cavalier: distance true� cabinet: distance half

Page 126: Viewing, Projections I/II Week 2, Tue May 17 · Week 2, Tue May 17. News extra lab coverage with TAs 12-2 Mondays, Wednesdays for rest of term just for answering questions, no presentations

��

Demos

� Tuebingen applets from Frank Hanisch� http://www.gris.uni-tuebingen.de/projects/grdev/doc/html/etc/

AppletIndex.html#Transformationen