2003cs hons rw778 graphics1 chapter 3: windows, viewports world coordinates rather than screen...

17
2003 CS Hons RW778 Graphics 1 Chapter 3: Windows, Chapter 3: Windows, viewports viewports World coordinates rather than screen World coordinates rather than screen coordinates. coordinates. World “window” defines which part of World “window” defines which part of world should be drawn, and which world should be drawn, and which clipped away. clipped away. Viewport defined in screen window Viewport defined in screen window mapping (scaling, shifting) between world mapping (scaling, shifting) between world window and viewport window and viewport draw in world window; automatically mapped draw in world window; automatically mapped to viewport to viewport

Upload: gervais-bartholomew-evans

Post on 29-Dec-2015

232 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 1

Chapter 3: Windows, viewportsChapter 3: Windows, viewports

World coordinates rather than screen coordinates.World coordinates rather than screen coordinates. World “window” defines which part of world World “window” defines which part of world

should be drawn, and which clipped away.should be drawn, and which clipped away. Viewport defined in screen windowViewport defined in screen window

– mapping (scaling, shifting) between world window and mapping (scaling, shifting) between world window and viewportviewport

– draw in world window; automatically mapped to draw in world window; automatically mapped to viewportviewport

Page 2: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 2

Chapter 3: Windows, viewportsChapter 3: Windows, viewports

3.2.1 Window to viewport mapping3.2.1 Window to viewport mapping– W, V: rectangles: left, right, top, bottomW, V: rectangles: left, right, top, bottom

– May have different ratios: distortionMay have different ratios: distortion

– A, B scale; C, D translateA, B scale; C, D translate

lAWlVC

A

DBxsy

CAxsx

lWrWlVrV

......

Page 3: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 3

Chapter 3: Windows, viewportsChapter 3: Windows, viewports

– Read: Example 3.2.1, exercise 3.2.1, example 3.2.2Read: Example 3.2.1, exercise 3.2.1, example 3.2.2

– Selfstudy: Selfstudy: » Ex. 3.2.3 Drawing polylines from a fileEx. 3.2.3 Drawing polylines from a file

» Ex. 3.2.4 Tiling a window with a motifEx. 3.2.4 Tiling a window with a motif

» Ex. 3.2.5 Clipping, zooming and roamingEx. 3.2.5 Clipping, zooming and roaming

» p. 91: smooth animations and double bufferingp. 91: smooth animations and double buffering

» Ex. 3.2.2 Whirling swirlsEx. 3.2.2 Whirling swirls

Page 4: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 4

Chapter 3: Windows, viewportsChapter 3: Windows, viewports

3.2.2 Setting Window and Viewport automatically3.2.2 Setting Window and Viewport automatically– Selfstudy.Selfstudy.

3.3 Clipping lines3.3 Clipping lines– OpenGL automatically; algorithmsOpenGL automatically; algorithms

Page 5: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 5

Chapter 3: Windows, viewportsChapter 3: Windows, viewports

3.3.2 Cohen-Sutherland clipping3.3.2 Cohen-Sutherland clipping– Checks for trivial accept or trivial rejectChecks for trivial accept or trivial reject

» Inside-outside code word for each endpointInside-outside code word for each endpoint

» Trivial accept: Both code words are FFFFTrivial accept: Both code words are FFFF

» Trivial reject: Code words have T in same positionTrivial reject: Code words have T in same position

Page 6: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 6

Chapter 3: Windows, viewportsChapter 3: Windows, viewports

– Chopping (no trivial accept/reject)Chopping (no trivial accept/reject)» Goal : A.x, A.y? Goal : A.x, A.y?

» A.x = W.rightA.x = W.right

» A.y?A.y? delx = Pdelx = P22.x – P.x – P11.x ; dely = P.x ; dely = P22.y – P.y – P11.y.y e = Pe = P11.x – W.right ; d/dely = e/delx.x – W.right ; d/dely = e/delx Therefore PTherefore P11.y = P.y = P11.y + (W.right – P.y + (W.right – P11.x) * dely /delx.x) * dely /delx

Page 7: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 7

Chapter 3: Windows, viewportsChapter 3: Windows, viewports

The Canvas Class: Selfstudy.The Canvas Class: Selfstudy.– 3.4 Developing the canvas class3.4 Developing the canvas class

– 3.5 Relative drawing3.5 Relative drawing

– 3.6 Figures based on regular polygons3.6 Figures based on regular polygons

– 3.7 Drawing circles and arcs3.7 Drawing circles and arcs

3.8 Parametric forms of curves3.8 Parametric forms of curves– Implicit : Point on line if F(x,y) = 0 (inside-outside form)Implicit : Point on line if F(x,y) = 0 (inside-outside form)

– Parametric: Position at time t is given by x(t), y(t) Parametric: Position at time t is given by x(t), y(t)

– Finding implicit form for parametric formFinding implicit form for parametric form

– NB! Practice exercises p. 122-123 : selfstudyNB! Practice exercises p. 122-123 : selfstudy

– Drawing parametric curves: Trivial.Drawing parametric curves: Trivial.

Page 8: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 8

Chapter 3: Windows, viewportsChapter 3: Windows, viewports

– 3.8.3 Super-ellipses3.8.3 Super-ellipses» Implicit : (x/W)Implicit : (x/W)nn + (y/H) + (y/H)nn =1 =1» Parametric:Parametric:

x(t) = W cos(t) |cos(t)x(t) = W cos(t) |cos(t)2/n-12/n-1||

y(t) = H sin(t) |sin(t)y(t) = H sin(t) |sin(t)2/n-12/n-1| |

» Also superhyperbolaAlso superhyperbola

– 3.8.4 Polar Coordinate Shapes3.8.4 Polar Coordinate Shapes» x(t) = r(t) cos (x(t) = r(t) cos ((t))(t))» x(t) = r(t) cos (x(t) = r(t) cos ((t))(t))» Given point (r, Given point (r, ), Cartesian point (x,y) ), Cartesian point (x,y)

is given by is given by x = f (x = f () cos () cos ())y = f (y = f () sin () sin ())

Page 9: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 9

Chapter 3: Windows, viewportsChapter 3: Windows, viewports

» Note conic sections, logarithmic spiralNote conic sections, logarithmic spiral

– 3.8.5 3D Curves3.8.5 3D Curves» Helix, toroidal spiralHelix, toroidal spiral

Read Case Studies pp. 130 – 142Read Case Studies pp. 130 – 142

Page 10: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 10

Chapter 4: Vector ToolsChapter 4: Vector Tools

Vector arithmetic allows to express geometric Vector arithmetic allows to express geometric concepts algebraically.concepts algebraically.

4.2 Review of vectors4.2 Review of vectors– Vector is object with length and directionVector is object with length and direction

– Think of vector as displacementThink of vector as displacement

– The difference between two points is a vector: The difference between two points is a vector: vv = Q-P = Q-P

Page 11: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 11

Chapter 4: Vector ToolsChapter 4: Vector Tools

4.2.1 Operations with vectors4.2.1 Operations with vectors– vector addition, scalar multiplicationvector addition, scalar multiplication

4.2.2 Linear combination of vectors4.2.2 Linear combination of vectors– ww = a = a11vv11 + a + a22vv22 + ... + a + ... + ammvvmm

– Affine combination: aAffine combination: a11+a+a22+...+a+...+amm = 1 = 1

Page 12: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 12

Chapter 4: Vector ToolsChapter 4: Vector Tools

– Convex combination: Convex combination: aa11+a+a22+...+a+...+amm = 1 = 1

aai i 0, for i = 1, ..., m 0, for i = 1, ..., m

– Set of all convex combinations of a vector Set of all convex combinations of a vector vv::v v = (1-a) = (1-a) vv11 + a + avv2 2 , for 0 , for 0 a a 1 1

Page 13: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 13

Chapter 4: Vector ToolsChapter 4: Vector Tools

4.2.3 Magnitude of a vector; unit vectors4.2.3 Magnitude of a vector; unit vectors– ||ww| is distance from head to tail, so that| is distance from head to tail, so that

||ww| = (w| = (w1122+w+w22

22+...+w+...+wnn22))0.50.5

– Scaling vector to unit length known as normalizing and obtain unit Scaling vector to unit length known as normalizing and obtain unit vector vector ŵ ŵ = (= (ww/|/|ww|)|)

4.3 Dot product4.3 Dot product– d = d = v . w v . w = =

– Properties:Properties:» aa . . bb = = bb . . aa

» ((aa++cc) . ) . bb = = aa . . bb + + cc . . bb

» (s(saa) . ) . bb = s ( = s (aa . . bb))

» ||bb||22 = = bb . . bb

n

i

iiwv1

Page 14: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 14

Chapter 4: Vector ToolsChapter 4: Vector Tools

4.3.2 Angle between two vectors4.3.2 Angle between two vectors– cos (cos (θ) = (θ) = (bb/|/|bb|).(|).(cc/|/|cc|)|)

The cosine between two vectors is the The cosine between two vectors is the dot product of the normalized vectors.dot product of the normalized vectors.

4.3.3 The sign of 4.3.3 The sign of b.cb.c, and perpendicularity, and perpendicularityperpendicular – normal – orthogonalperpendicular – normal – orthogonal

standard unit vectorsstandard unit vectors

Page 15: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 15

Chapter 4: Vector ToolsChapter 4: Vector Tools

4.3.4 The 2D Perp Vector4.3.4 The 2D Perp Vector– Let Let aa=(a=(axx,a,ayy). Then ). Then aa = (-a = (-ayy,a,axx) is the counterclockwise ) is the counterclockwise

perpendicular to perpendicular to aa (the (the perpperp).).

– Selfstudy: Practice exercises p. 157.Selfstudy: Practice exercises p. 157.

4.3.5 Orthogonal projections and distances4.3.5 Orthogonal projections and distances– How far? Where? Decompose?How far? Where? Decompose?

Page 16: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 16

Chapter 4: Vector ToolsChapter 4: Vector Tools

4.3.6 Applications of projection: Reflections4.3.6 Applications of projection: ReflectionsSelfstudySelfstudy..

4.4 The Cross Product of Two Vectors4.4 The Cross Product of Two Vectors i j ki j k

a a x x b b == aaxx a ayy a azz

b bxx b byy b bzz

– Examples; practice exercises: Selfstudy.Examples; practice exercises: Selfstudy.

Page 17: 2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates

2003 CS Hons RW778 Graphics 17

Chapter 3: Windows, ViewportsChapter 3: Windows, Viewports

Programming Task 2Programming Task 2 : Implement Case : Implement Case Study 3.6.1 (Basic tilings), p. 138, in Hill.Study 3.6.1 (Basic tilings), p. 138, in Hill.