Presentation is loading. Please wait.

Presentation is loading. Please wait.

Viewing and Projection

Similar presentations


Presentation on theme: "Viewing and Projection"— Presentation transcript:

1 Viewing and Projection
Images were taken from the book: “Interactive Computer Graphics” by Angel and Shreiner

2 Graphics Pipeline Consider our program as a pipeline
At each step, we manipulate the data Our goal is to output the data in screen coordinates חלק מהשלבים יכולים להיות טריוויאליים – כלומר מטריצת היחידה

3 Graphics Pipeline Object coordinates Camera coordinates Clip
Vertices 𝑃 Projection transformation 𝑇 𝑚 𝑇 𝑤 𝑇 𝑐 −1 Model-view transformation

4 Positioning the Camera
Initially, the object and camera frames are the same (the identity matrix) The camera is located at the origin and points in the negative 𝑧 direction We place the camera through the Model-view matrix המצלמה והאובייקט נמצאים שניהם בראשית מערכת הצירים, ולכן צריך להזיז את המצלמה/האובייקט כדאי שנראה משהו

5 The LookAt Function eye: The position of the camera
mat4 LookAt(vec4& eye, vec4& at, vec4& up) eye: The position of the camera at: The position the camera looks at Up: The upside (𝑦) direction of the camera

6 The LookAt Function Translate the camera to eye and change frame
mat4 LookAt(vec4& eye, vec4& at, vec4& up ) { vec4 n = normalize(eye - at); vec4 u = normalize(cross(up,n)); vec4 v = normalize(cross(n,u)); vec4 t = vec4(0.0, 0.0, 0.0, 1.0); mat4 c = mat4(u, v, n, t); return c * Translate( -eye ); }

7 Viewing Perspective vs. Orthographic DOP COP
אפשר להסתכל על הטלה אורתוגרפית כמקרה הגבול של הטלה פרספקטיבית – מרכז ההטלה עובר לאינסוף

8 Orthogonal Projections
How can we construct 𝑃? 𝑥 𝑝 =𝑥, 𝑦 𝑝 =𝑦, 𝑧 𝑝 =0 In matrix form: 𝑥 𝑝 , 𝑦 𝑝 , 𝑧 𝑝 ,1 𝑇 =𝑀I 𝑥,𝑦,𝑧,1 𝑇

9 Orthogonal Projections
How can we construct 𝑃=𝑀I? 𝑥 𝑝 , 𝑦 𝑝 , 𝑧 𝑝 ,1 𝑇 =𝑀I 𝑥,𝑦,𝑧,1 𝑇 Where I is the identity matrix and 𝑀=

10 Orthogonal Projections
Take a finite portion of the projection plane The default view volume is a cube with sides of length 2 centered at the origin Namely, the planes 𝑥=±1, 𝑦=±1, 𝑧=±1, determine the clipping volume

11 Orthogonal Viewing We can specify a different view volume
mat4 Ortho(left, right, bottom, top, near, far) Values are in Camera coordinates

12 Projection Normalization
The graphics card has a fixed viewing volume Thus, we transform our viewing volume into the canonical one

13 Projection Normalization
How to normalize the viewing volume? Translate: 𝑇 − 𝑟𝑖𝑔ℎ𝑡+𝑙𝑒𝑓𝑡 2 ,− 𝑏𝑜𝑡𝑡𝑜𝑚+𝑡𝑜𝑝 2 , 𝑛𝑒𝑎𝑟+𝑓𝑎𝑟 2 Scale: 𝑆 2 𝑟𝑖𝑔ℎ𝑡−𝑙𝑒𝑓𝑡 , 2 𝑡𝑜𝑝−𝑏𝑜𝑡𝑡𝑜𝑚 , 2 𝑛𝑒𝑎𝑟−𝑓𝑎𝑟 In matrix form: לשים לב לסימנים! 𝑆𝑇= 2 𝑟𝑖𝑔ℎ𝑡−𝑙𝑒𝑓𝑡 𝑡𝑜𝑝−𝑏𝑜𝑡𝑡𝑜𝑚 − 2 𝑓𝑎𝑟−𝑛𝑒𝑎𝑟 0 − 𝑙𝑒𝑓𝑡+𝑟𝑖𝑔ℎ𝑡 𝑟𝑖𝑔ℎ𝑡−𝑙𝑒𝑓𝑡 − 𝑡𝑜𝑝+𝑏𝑜𝑡𝑡𝑜𝑚 𝑡𝑜𝑝−𝑏𝑜𝑡𝑡𝑜𝑚 − 𝑓𝑎𝑟+𝑛𝑒𝑎𝑟 𝑓𝑎𝑟−𝑛𝑒𝑎𝑟 1

14 Summary: Orthogonal Projection
𝑃 Translate Scale Normalize 𝑇 𝑆 𝑀 Orthographic projection Project Projection transformation

15 Perspective Projections
How can we construct 𝑃 for 𝑑=−1? 𝑥 𝑝 = 𝑥 𝑧/−1 , 𝑦 𝑝 = 𝑦 𝑧/−1 , 𝑧 𝑝 =−1

16 Perspective Projections
How can we construct 𝑃? 𝑃= − Perspective division לחשב על הלוח, להראות שמקבלים מה שרוצים אחרי חלוקה בקומפוננטה הרביעית

17 Perspective Projections
𝑃 corresponds to a frustum with COP at the origin, 90 degrees FOV and bounded by the planes 𝑥=±𝑧, 𝑦=±𝑧.

18 Perspective Viewing We can specify a different viewing frustum
mat4 Frustum(left, right, bottom, top, near, far)

19 Perspective Viewing We can specify a different viewing frustum
mat4 Perspective(fovy, aspect, near, far) aspect = 𝑤/ℎ

20 Perspective Normalization
𝑃 is independent of the far clipping plane We take 𝑃= 𝛼 − 𝛽 0 Thus, 𝑥,𝑦,𝑧,1 T goes (after division) to − 𝑥 𝑧 ,− 𝑦 𝑧 ,−𝛼− 𝛽 𝑧 T

21 Perspective Normalization
We choose 𝛼=− 𝑛𝑒𝑎𝑟+𝑓𝑎𝑟 𝑛𝑒𝑎𝑟−𝑓𝑎𝑟 , 𝛽=− 2∗𝑛𝑒𝑎𝑟∗𝑓𝑎𝑟 𝑛𝑒𝑎𝑟−𝑓𝑎𝑟 Then, our frustum is transformed into the default viewing volume (i.e., bounded by the planes 𝑥=±1, 𝑦=±1, 𝑧=±1)

22 Viewport Transformation
How to transform into screen coordinates? 𝑟= 𝑤 2 𝑥+1 , 𝑠= ℎ 2 𝑦+1 .

23 Complete Graphics Pipeline
Object coordinates Camera coordinates Clip coordinates Normalized device coordinates Screen coordinates Model-view Projection Perspective division Viewport 𝑉 𝑉

24 Suggested Readings Interactive Computer Graphics, Chapter 4


Download ppt "Viewing and Projection"

Similar presentations


Ads by Google