13
Introduction to Computer Graphics 4. Viewing in 3D (Example) National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor Textbook: E.Angel, Interactive Computer Graphics, 5 th Ed., Addison Wesley Ref:Hearn and Baker, Computer Graphics, 3rd Ed., Prentice Hall

Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Embed Size (px)

Citation preview

Page 1: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Introduction to Computer

Graphics4. Viewing in 3D (Example)

National Chiao Tung Univ, Taiwan

By: I-Chen Lin, Assistant Professor

Textbook: E.Angel, Interactive Computer Graphics, 5th Ed., Addison Wesley

Ref:Hearn and Baker, Computer Graphics, 3rd Ed., Prentice Hall

Page 2: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Pipeline View

Modeling

Transformation

Viewing

Transformation

Projection

TransformationNormalization

and

clipping

Viewport

Transformation

MC WC VC

PC NC DC

Mmodel= TmRmSm… Mview= (TvRv)-1= Rv

tTv-1

Mnorm,perspective

Mnorm,oblique

Mnorm,ortho

(xo, yo, zo, 1)t (xm, ym, zm, 1)t (xv, yv, zv, 1)t

(xh, yh, zh, h)t

Divide h

(xp, yp, zp, 1)t (xd, yd)t

Mvp= TvpSvp…

Page 3: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Loading an Object

(xo, yo, zo, 1)t

Object coord.

Xoaxis

Yoaxis

Zoaxis

Page 4: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Modeling Transformation

(xm, ym, zm, 1)t = Mm(xo, yo, zo, 1)t

where Mm = ….TmRmSm ….

Xwaxis

Ywaxis

Zwaxis

Mm = ….TmRmSm ….

Page 5: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Put a Virtual Camera

Xwaxis

Ywaxis

Zwaxis Xvaxis

Yvaxis

Zvaxis

Move a camera from the origin (by TvRv)

TvRv

(xm, ym, zm, 1)t

Page 6: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Virtual camera’s Coordinate

Change the object’s coordinate

(xv, yv, zv, 1)t = Mview (xm, ym, zm, 1)t

Mview = (TvRv)-1 = Rv

-1 Tv-1

Xwaxis

Ywaxis

Zwaxis Xvaxis

Yvaxis

Zvaxis

(xv, yv, zv, 1)t =Mview(xm, ym, zm, 1)t

Page 7: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Virtual camera’s Coordinate

Xvaxis

Zvaxis

Zfar

Znear

xwmin, ywmin

xwmax, ywmax

Yvaxis

Page 8: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Perspective

Projection

Xvaxis

Zvaxis

Zfar

Znear

xwmin, ywmin

xwmax, ywmax

0100

200

000

000

farnear

farnear

farnear

farnear

near

near

pers

zz

zz

zz

zz

z

z

M

This matrix is usually combined

with the normalization matrix.

(xv, yv, zv, 1)t

Xvaxis

Zvaxis

xwmin, ywmin

xwmax, ywmax

(xv, yv, zv, 1)t

Yvaxis

Z=-1

Z=1

Xppaxis

Yppaxis

Zppaxis

Page 9: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Projection + Normalization

pers

farnear

farnear

farnear

farnear

near

near

normpers

Mywyw

xwxw

zz

zz

zz

zz

ywywz

xwxwz

M

1000

0100

002

0

0002

0100

200

002

0

0002

minmax

minmax

minmax

minmax

Xwmax

Ywmax

1

1

Xwmin

Ywmin

-1

1 1

1

-1

1-1

-1

-1

1

Scaling

Page 10: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Projection+

Normalization

(xh, yh, zh, h)t = Mnormpers(xv, yv, zv, 1)t

Don’t divide h at this step.

0100

200

002

0

0002

minmax

minmax

farnear

farnear

farnear

farnear

near

near

normpers

zz

zz

zz

zz

ywywz

xwxwz

M

Xvaxis

Zvaxis

-1, -1

1,1

Mnormpers(xv, yv, zv, 1)t

=(xh, yh, zh, h)t

Z=-1

Z=1

Xhxis

Yhaxis

Zhaxis

Xvaxis

Zvaxis

Zfar

Znear

xwmin, ywmin

xwmax, ywmax

(xv, yv, zv, 1)t

Yvaxis

Page 11: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Clipping

Xvaxis

Zvaxis

-1, -1

1,1

(xh, yh, zh, h)t

Z=-1

Z=1

Xhxis

Yhaxis

Zhaxis

Perform clipping with (xh, yh, zh, h)t

Avoid unnecessary division

Use parametric forms for intersection

xh = xha + (xhb - xha)u

yh = yha + (yhb - yha)u

zh = zha + (zhb - zha)u

h = ha + (hb - ha)u

, , hzhhyhhxh hhh

Page 12: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Viewport

Transformation

(xd, yd, zd, 1)t = Mviewport (xh, yh, zh, h)t

OR

(xd, yd)t = SUBMviewport (xP, yP)

t, (xP, yP)t= (xh/h, yh/h)t

Xvaxis

Zvaxis

-1, -1

1,1

(xh, yh, zh, h)t

Z=-1

Z=1

Xhxis

Yhaxis

Zhaxis

(xdmin, ydmin)

(xdmax, ydmax)

(xd , yd)

1000

01002

02

0

200

2

minmaxminmax

minmaxminmax

dddd

dddd

viewport

yyyy

xxxx

M

Page 13: Introduction to Computer Graphics - National Chiao Tung ...caig.cs.nctu.edu.tw/course/cg10/cg_4_viewingeg_s10.pdf · Introduction to Computer Graphics 4. Viewing in 3D (Example) National

Rasterization

Line drawing or polygon filling with

(xd, yd, zd, 1)t or (xd, yd)t and zh

(xdmin, ydmin)

(xdmax, ydmax)

(xd, yd)