Viewing/Projections IV Week 4, Fri Feb 2

Preview:

DESCRIPTION

http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007. Viewing/Projections IV Week 4, Fri Feb 2. Reading for Today. FCG Chapter 7 Viewing FCG Section 6.3.1 Windowing Transforms RB rest of Chap Viewing RB rest of App Homogeneous Coords. Reading for Next Time. RB Chap Color FCG Sections 3.2-3.3 - PowerPoint PPT Presentation

Citation preview

University of British ColumbiaCPSC 314 Computer Graphics

Jan-Apr 2007

Tamara Munzner

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

Viewing/Projections IV

Week 4, Fri Feb 2

2

Reading for Today

• FCG Chapter 7 Viewing

• FCG Section 6.3.1 Windowing Transforms

• RB rest of Chap Viewing

• RB rest of App Homogeneous Coords

3

Reading for Next Time

• RB Chap Color

• FCG Sections 3.2-3.3

• FCG Chap 20 Color

• FCG Chap 21 Visual Perception

4

News

• my office hours reminder (in lab): today 11-12• homework 1 due 3pm in box marked 314

• same hallway as lab

• project 1 due 6pm, electronic handin• no hardcopy required• demo signup sheet going around again

• Mon 1-12; Tue 10-12:30, 4-6; Wed 10-12, 2:30-4• arrive in lab 10 min before for your demo slot• be logged in and ready to go at your time• note to those developing in Windows/Mac

• your program must compile and run on lab machines• test before the last minute, no changes after handin

5

Homework 1 News

• don’t forget problem 11 (on back of page)

• Problem 3 is now extra credit• Write down the 4x4 matrix for shearing an object by

2 in y and 3 in z.

6

Correction (Transposed Before): 3D Shear

• shear in x• shear due to x

along y and z axes

• shear in y

• shear in z

• general shear

1000

010

001

0001

),(hxz

hxyhxzhxyxshear

1000

010

0010

001

),(hyz

hyx

hyzhyxyshear

1000

0100

010

001

),(hzy

hzx

hzyhzxzshear

1000

01

01

01

),,,,,(hyzhxz

hzyhxy

hzxhyx

hzyhzxhyzhyxhxzhxyshear

1000

0100

0010

01 szsy

1000

0100

01

0001

szsx

1000

01

0010

0001

sysx

7

News

• midterm Friday Feb 9• closed book

• no calculators

• allowed to have one page of notes• handwritten, one side of 8.5x11” sheet

• this room (DMP 301), 11-11:50

• material covered• transformations, viewing/projection

8

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

9

NDC to Device Transformation

• map from NDC to pixel coordinates on display• NDC range is x = -1...1, y = -1...1, z = -1...1

• typical display range: x = 0...500, y = 0...300• maximum is size of actual screen• z range max and default is (0, 1), use later for visibility

xxyy

viewportviewportNDCNDC

0 500

300

0

-1

1

1

-1

xx

yy

glViewport(0,0,w,h);glDepthRange(0,1); // depth = 1 by default

10

Origin Location

• yet more (possibly confusing) conventions• OpenGL origin: lower left

• most window systems origin: upper left

• then must reflect in y• when interpreting mouse position, have to flip your

y coordinates

xxyy

viewportviewportNDCNDC

0 500

300

0

-1

1

1

-1

xx

yy

11

N2D Transformation

• general formulation• reflect in y for upper vs. lower left origin

• scale by width, height, depth

• translate by width/2, height/2, depth/2• FCG includes additional translation for pixel centers at

(.5, .5) instead of (0,0)

xxyy

viewportviewportNDCNDC

0 500

300

0

-1

1

1

-1height

width

xx

yy

12

N2D Transformation

12

)1(2

1)1(2

1)1(

11000

0100

0010

0001

1000

02

00

002

0

0002

10002

100

2

1

2010

2

1

2001

1 N

N

N

N

N

N

D

D

D

zdepth

yheight

xwidth

z

y

x

depth

height

width

depth

height

width

z

yx

xxyy

viewportviewportNDCNDC

0 500

300

0

-1

1

1

-1height

width

xx

yy

13

Device vs. Screen Coordinates

• viewport/window location wrt actual display not available within OpenGL• usually don’t care

• use relative information when handling mouse events, not absolute coordinates

• could get actual display height/width, window offsets from OS

• loose use of terms: device, display, window, screen...

xx

displaydisplayviewportviewport

01024

768

0

300

500

displayheight

display width

x offset

y offsetyy

viewportviewport

xx00 yy

14

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)

glTranslatef(x,y,z)glTranslatef(x,y,z)glRotatef(a,x,y,z)glRotatef(a,x,y,z)........

gluLookAt(...)gluLookAt(...)

glFrustum(...)glFrustum(...)

glutInitWindowSize(w,h)glutInitWindowSize(w,h)glViewport(x,y,a,b)glViewport(x,y,a,b)

O2WO2W W2VW2V V2CV2C

N2DN2D

C2NC2N

15

Coordinate Systemsviewing

(4-space, W=1)

clipping

(4-space parallelepiped, with COP moved backwards to infinity

normalized device

(3-space parallelepiped)

device

(3-space parallelipiped)

projection matrix

divide by w

scale &

translate

projection matrix

16

Perspective To NDCS 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

17

Perspective Derivation

simple example earlier:simple example earlier:

complete: shear, scale, projection-normalizationcomplete: shear, scale, projection-normalization

10100

00

00

00

'

'

'

'

z

y

x

DC

BF

AE

w

z

y

x

10/100

0100

0010

0001

'

'

'

'

z

y

x

dw

z

y

x

18

Perspective Derivation

earlier:earlier:

complete: shear, scale, projection-normalizationcomplete: shear, scale, projection-normalization

10100

00

00

00

'

'

'

'

z

y

x

DC

BF

AE

w

z

y

x

10/100

0100

0010

0001

'

'

'

'

z

y

x

dw

z

y

x

19

Perspective Derivation

earlier:earlier:

complete: shear, scale, projection-normalizationcomplete: shear, scale, projection-normalization

10100

00

00

00

'

'

'

'

z

y

x

DC

BF

AE

w

z

y

x

10/100

0100

0010

0001

'

'

'

'

z

y

x

dw

z

y

x

20

Perspective Derivation

10100

00

00

00

'

'

'

'

z

y

x

DC

BF

AE

w

z

y

x

zw

DCzz

BzFyy

AzExx

'

'

'

'

,)(

1 ,1 ,1

,1 ,'

1 ,''

' ,'

Bnear

topFB

z

yF

z

zB

z

yF

z

BzFy

w

BzFy

w

BzFy

w

yBzFyy

1'/'

1'/'

1'/'

1'/'

1'/'

1'/'

wzfarz

w znear z

wybottomy

w ytop y

wxrightx

w xleft x

Bnear

topF 1

21

Perspective Derivation

• similarly for other 5 planes

• 6 planes, 6 unknowns

0100

2)(00

02

0

002

nf

fn

nf

nfbt

bt

bt

nlr

lr

lr

n

22

Perspective Example

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

view volume left = -1, right = 1 bot = -1, top = 1 near = 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

23

Perspective Example

0100

2)(00

02

0

002

nf

fn

nf

nfbt

bt

bt

nlr

lr

lr

n

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

0100

3/83/500

0010

0001

24

Perspective Example

1

1

1

1

3/83/5

1

1

3/83/5

1

1

VCS

VCS

VCS z

z

z

VCSNDCS

VCSNDCS

VCSNDCS

zz

zy

zx

3

8

3

5

/1

/1

/ w/ w

25

OpenGL Example

glMatrixMode( GL_PROJECTION );

glLoadIdentity();

gluPerspective( 45, 1.0, 0.1, 200.0 );

glMatrixMode( GL_MODELVIEW );

glLoadIdentity();

glTranslatef( 0.0, 0.0, -5.0 );

glPushMatrix()

glTranslate( 4, 4, 0 );

glutSolidTeapot(1);

glPopMatrix();

glTranslate( 2, 2, 0);

glutSolidTeapot(1);OCS2OCS2

O2WO2W VCSVCSmodelingmodeling

transformationtransformationviewingviewing

transformationtransformation

projectionprojectiontransformationtransformation

object world viewingW2VW2V V2CV2CWCSWCS

• transformations that are applied first are specified last

OCS1OCS1

WCSWCS

VCSVCS

W2OW2O

W2OW2O

CCSCCSclipping

CCSCCS

OCSOCS

26

Projection Taxonomyplanarplanar

projectionsprojections

perspective:perspective:1,2,3-point1,2,3-point

parallelparallel

obliqueobliqueorthographicorthographic

cabinetcabinet cavaliercavalier

top,top,front,front,sideside

axonometric:axonometric:isometricisometricdimetricdimetrictrimetrictrimetric

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

• perspective: projectors converge• orthographic, axonometric:

projectors parallel and perpendicular to projection plane

• oblique: projectors parallel, but not perpendicular to projection plane

27

Perspective Projections• projectors converge on image plane • select how many vanishing points

• one-point: projection plane parallel to two axes• two-point: projection plane parallel to one axis• three-point: projection plane not parallel to any axis

one-pointone-pointperspectiveperspective

two-pointtwo-pointperspectiveperspective

three-pointthree-pointperspectiveperspective

Tuebingen demo: vanishingpoints

28

Orthographic Projections

• projectors parallel, perpendicular to image plane• image plane normal parallel to one of principal axes• select view: top, front, side• every view has true dimensions, good for measuring

http://www.cs.fit.edu/~wds/classes/cse5255/thesis/images/proj/orthoProj.gif

29

Axonometric Projections• projectors parallel, perpendicular to image plane• image plane normal not parallel to axes• select axis lengths• can see many sides at once

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

30

Oblique Projections

xx

yy

zz

cavaliercavalier

dd

dd

xx

yy

zz

cabinetcabinet

dd

d / 2d / 2

• projectors parallel, 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

Tuebingen demo: oblique projections

Recommended