1 91.427 computer graphics i, fall 2010 computer viewing

21
1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

Upload: kathleen-banks

Post on 04-Jan-2016

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

191.427 Computer Graphics I, Fall 2010

Computer Viewing

Page 2: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

291.427 Computer Graphics I, Fall 2010

Objectives

•Introduce mathematics of projection•Introduce OpenGL viewing functions•Look at alternate viewing APIs

Page 3: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

391.427 Computer Graphics I, Fall 2010

Computer Viewing

•Three aspects of viewing process•All implemented in pipeline

Position camera•Set model-view matrix

Select lens•Set projection matrix

Clip•Set view volume

Page 4: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

491.427 Computer Graphics I, Fall 2010

The OpenGL Camera

•In OpenGL, initially object and camera frames same

Default model-view matrix = identity

•Camera located at originpoints in negative z direction

•OpenGL also specifies default view volume cube with sides of length 2 centered at origin

Default projection matrix = identity

Page 5: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

591.427 Computer Graphics I, Fall 2010

Default Projection

Default projection is orthogonal

clipped out

z = 0

2

Page 6: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

691.427 Computer Graphics I, Fall 2010

Moving the Camera Frame•If want to visualize object with both positive and negative z values can either Move camera in positive z direction

•Translate camera frame

Move objects in negative z direction•Translate world frame

•Both views equivalent and determined by model-view matrix Want translation (glTranslatef(0.0,0.0,-d);)­d > 0

Page 7: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

791.427 Computer Graphics I, Fall 2010

Moving Camera back from Origin

default frames frames after translation by –d d > 0

Page 8: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

891.427 Computer Graphics I, Fall 2010

Moving the Camera

•Can move camera to any desired position by sequence of Rs and Ts

•Example: side view Rotate camera Move it away from origin Model-view matrix C = TR

Page 9: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

991.427 Computer Graphics I, Fall 2010

OpenGL code

•Remember that last transformation specified is first to be applied

glMatrixMode(GL_MODELVIEW)glLoadIdentity();glTranslatef(0.0, 0.0, -d);glRotatef(90.0, 0.0, 1.0, 0.0);

Page 10: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1091.427 Computer Graphics I, Fall 2010

The LookAt Function•GLU library contains function gluLookAt

form required modelview matrix through simple interface

•Note: need to set an up direction•Still need to initialize

Can concatenate with modeling transformations

•Example: isometric view of cube aligned w/ axesglMatrixMode(GL_MODELVIEW):glLoadIdentity();gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0. 0.0);

------eye------ -------at------- -------up-------

Page 11: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1191.427 Computer Graphics I, Fall 2010

glLookAt

glLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz)

Page 12: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1291.427 Computer Graphics I, Fall 2010

Other Viewing APIs

•LookAt function only one possible API for positioning camera

•Others include View reference point, view plane normal, view up (PHIGS, GKS-3D)

Yaw, pitch, roll Elevation, azimuth, twist Direction angles

Page 13: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1391.427 Computer Graphics I, Fall 2010

Projections and Normalization

•Default projection in eye (camera) frameorthogonal

•For points within default view volume

•Most graphics systems use view normalization All other views converted to default view by

transformations that determine projection matrix Allows use of same pipeline for all views

xp = xyp = yzp = 0

Page 14: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1491.427 Computer Graphics I, Fall 2010

Homogeneous Coordinate Representation

xp = xyp = yzp = 0wp = 1

pp = Mp

M =

⎥⎥⎥⎥

⎢⎢⎢⎢

1000

0000

0010

0001

In practice, can let M = I and set z term to zero later

default orthographic projection

Page 15: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1591.427 Computer Graphics I, Fall 2010

Simple Perspective

•Center of projection at origin•Projection plane z = d, d < 0

Page 16: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1691.427 Computer Graphics I, Fall 2010

Perspective Equations

Consider top and side views

xp =

dz

x

/

dz

x

/yp =

dz

y

/zp = d

Page 17: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1791.427 Computer Graphics I, Fall 2010

Homogeneous Coordinate Form

M =

⎥⎥⎥⎥

⎢⎢⎢⎢

0/100

0100

0010

0001

d

consider q = Mp where

⎥⎥⎥⎥

⎢⎢⎢⎢

1

z

y

x

⎥⎥⎥⎥

⎢⎢⎢⎢

dz

z

y

x

/

q = p =

Page 18: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1891.427 Computer Graphics I, Fall 2010

Perspective Division

•However w 1, so must divide by w to return from homogeneous coordinates

•perspective division ==>

desired perspective equations •Will consider corresponding clipping volume with OpenGL functions

xp =dz

x

/yp =

dz

y

/zp = d

Page 19: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

1991.427 Computer Graphics I, Fall 2010

OpenGL Orthogonal Viewing

glOrtho(left,right,bottom,top,near,far)

near and far measured from camera

Page 20: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

2091.427 Computer Graphics I, Fall 2010

OpenGL Perspective

glFrustum(left,right,bottom,top,near,far)

Page 21: 1 91.427 Computer Graphics I, Fall 2010 Computer Viewing

2191.427 Computer Graphics I, Fall 2010

Using Field of View

•With glFrustum often difficult to get desired view•gluPerpective(fovy, aspect, near, far) often provides better interface

aspect = w/h

front plane