5
1 CSC5870 Computer Graphics I Viewing and Projection in 3D CSC5870 Computer Graphics I Taking a picture with a camera Coordinates: Local, World, Viewing Rendering pipeline • ModelView – Matrix operations on models World coordinates to Viewing coordinates – Matrix operations (models or cameras) Projection with a camera CSC5870 Computer Graphics I Positioning the Camera By default, the camera is placed at the origin pointing in the negative z-axis. x z y CSC5870 Computer Graphics I Positioning the Camera OpenGL Look-At Function gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz) View-reference point (VRP) View-plane normal (VPN) View-up vector (VUP) x z y (atx, aty, atz) (eyex, eyey, eyez) (upx, upy, upz) CSC5870 Computer Graphics I View Transformation Matrix View Matrix = [ ux uy uz –u.X] [ vx vy vz –v.X] [nx ny nz -n.X CSC5870 Computer Graphics I Chalk Talk

Taking a picture with a camera Viewing and Projection in 3D

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Taking a picture with a camera Viewing and Projection in 3D

1

CSC5870 Computer Graphics I

Viewing and Projection in 3D

CSC5870 Computer Graphics I

Taking a picture with a camera• Coordinates: Local, World, Viewing• Rendering pipeline• ModelView

– Matrix operations on models

• World coordinates to Viewing coordinates– Matrix operations (models or cameras)

• Projection with a camera

CSC5870 Computer Graphics I

Positioning the Camera• By default, the camera is placed at the origin pointing in

the negative z-axis.

xz

y

CSC5870 Computer Graphics I

Positioning the Camera• OpenGL Look-At Function

gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz)• View-reference point (VRP)• View-plane normal (VPN)• View-up vector (VUP)

x

z

y

(atx, aty, atz)

(eyex, eyey, eyez)

(upx, upy, upz)

CSC5870 Computer Graphics I

View Transformation Matrix• View Matrix = [ ux uy uz –u.X]• [ vx vy vz –v.X]

[nx ny nz -n.X

CSC5870 Computer Graphics I

Chalk Talk

Page 2: Taking a picture with a camera Viewing and Projection in 3D

2

CSC5870 Computer Graphics I

Projection in 3D• Planar Geometric Projections• Parallel Orthographic Projections• Perspective Projections• Projections in OpenGL• Clipping

CSC5870 Computer Graphics I

Planar Geometric Projections• Maps points from camera coordinate system to

the screen (image plane of the virtual camera).Planar Geometric Projections

Parallel Perspective

Oblique Orthographic

Image Plane

Center of Projection (COP)Image Plane

CSC5870 Computer Graphics I

Parallel Orthographic Projection• Preserves X and Y coordinates.• Preserves both distances and angles.

Image Plane

CSC5870 Computer Graphics I

Parallel Orthographic Projection

x

(x, y, z)

z

y• xp = x • yp = y• zp = 0

(xp, yp, 0)z = 0

CSC5870 Computer Graphics I

Perspective Projection• Only preserves parallel lines that are parallel to

the image plane.• Line segments are shorten by distance.

Image Plane

Center of Projection (COP)

CSC5870 Computer Graphics I

Perspective Projection

x

(x, y, z)

z

y

(xp, yp, zp)z = d

Page 3: Taking a picture with a camera Viewing and Projection in 3D

3

CSC5870 Computer Graphics I

Perspective Projection

x

(x, z)

z

(xp, d)z = d

• zp = d• xp = (x• d) / z

CSC5870 Computer Graphics I

Perspective Projection

y

(y, z)

z(yp, d)

z = d

• zp = d• yp = (y• d) / z

CSC5870 Computer Graphics I

Perspective Projection• xp = (x• d) / z =x/(z/ d) • yp = (y• d) / z =y/(z/ d) • zp = d =z/(z/ d)

CSC5870 Computer Graphics I

Viewing in 3D• Planar Geometric Projections• Parallel Orthographic Projections• Perspective Projections• Projections in OpenGL

CSC5870 Computer Graphics I

Viewing in 3D• Planar Geometric Projections• Parallel Orthographic Projections• Perspective Projections• Projections in OpenGL

– Positioning of the Camera– Define the view volume

CSC5870 Computer Graphics I

Defining the Perspective View Volume

xz

y(xmax, ymax, -far)

(xmin, ymin, -near)

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

Page 4: Taking a picture with a camera Viewing and Projection in 3D

4

CSC5870 Computer Graphics I

Defining the Perspective View Volume

xz

yw

gluPerspective(fovy, aspect, near, far)

h

fov

CSC5870 Computer Graphics I

Defining the Parallel View Volume

xz

y(xmax, ymax, -far)

(xmin, ymin, -near)

glOrtho(xmin, xmax, ymin, ymax, near, far)

View Volume

CSC5870 Computer Graphics I

Clipping

CSC5870 Computer Graphics I

2D Line Clipping• Cohen-Sutherland algorithm

G

H

I

J

B

A

D

C

E

F

CSC5870 Computer Graphics I

Cohen-Sutherland algorithm

1001

0101

0001

1000

0000

0100

1010

0010

0110

• The space is divided into nine regions.• Each region is assigned a unique 4-bit binary number: outcode

CSC5870 Computer Graphics I

Cohen-Sutherland algorithm• Bit 1: left• Bit 2: right• Bit 3: below• Bit 4: above

1001

0101

0001

1000

0000

0100

1010

0010

0110

Page 5: Taking a picture with a camera Viewing and Projection in 3D

5

CSC5870 Computer Graphics I

Cohen-Sutherland algorithm• Each line has two endpoints with two outcodes o1= outcode (x1, y1) and o2= outcode (x2, y2).

• We can decide base on these two outcodes.

(x1, y1)

(x2, y2)

CSC5870 Computer Graphics I

Cohen-Sutherland algorithmFour cases:1. o1 = o2 = 0. Both endpoints are inside the window. Such as AB.2. o1 ¹ 0, o2 = 0, or vice versa. One endpoint is inside, the other is

outside. Such as CD.

GH

I

J

BA

D

CE

F

CSC5870 Computer Graphics I

Cohen-Sutherland algorithmFour cases:3. o1 & o2 ¹ 0. Whether or not the two endpoints lie on the same

outside of the window. Such as EF and GH .4. o1 & o2 = 0. Both endpoints are outside, but there are on the

outside of the different edges of the window. Such as IJ.

GH

I

J

BA

D

CE

F