lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized...
Transcript of lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized...
![Page 1: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/1.jpg)
lecture 5
- projective transformation- normalized view volume- GL_PROJECTION matrix- clip coordinates- normalized device coordinates
- planes and normals in projective space- Assignment 1 (python and pyopengl)
![Page 2: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/2.jpg)
Recall last lecture: view volume (view frustum)
gluPerspective( y, x / y , near, far)
glFrustrum( left, right, bottom, top, near, far)
![Page 3: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/3.jpg)
Recall last lecture: projection
f = -near
![Page 4: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/4.jpg)
But that is not what glFrustrum and gluPerspective do.
Why not ? What do they do?
You might think.....
![Page 5: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/5.jpg)
The problem with projection:
If we discard the z information, then we don't know whichobjects are in front of which.
![Page 6: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/6.jpg)
Projective Transformation
projection plane (near)
![Page 7: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/7.jpg)
Projective Transformation
![Page 8: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/8.jpg)
Objects that are further away look smaller.
![Page 9: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/9.jpg)
How to define a projective transformation that does this?
Previously, we considered projection :
But a projection matrix is not invertible(3rd and 4th rows are linearly dependent)
![Page 10: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/10.jpg)
Projective Transformation
z = -near z = - far
![Page 11: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/11.jpg)
We choose and to satisfy desired mapillustrated on previous slide.
where
![Page 12: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/12.jpg)
In Appendix to lecture notes, I derive (easy) :
where
![Page 13: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/13.jpg)
![Page 14: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/14.jpg)
![Page 15: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/15.jpg)
Where do various regions map to ?
![Page 16: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/16.jpg)
![Page 17: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/17.jpg)
![Page 18: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/18.jpg)
![Page 19: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/19.jpg)
![Page 20: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/20.jpg)
Curious ! The JKL flipping is analogous to aMobius strip.
![Page 21: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/21.jpg)
Why is the above detail important ?
We decide whether or not points lie in the view volumeusing projective space representation.
To make these decisions correctly, we need to be carefulabout inequalities and signs.
More about this later...
![Page 22: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/22.jpg)
Another (surprisingly) important detail:
OpenGL uses the 2nd matrix above, not the first.Why ?
![Page 23: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/23.jpg)
Soon we will see why this is desirable.
![Page 24: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/24.jpg)
"Normalized view volume"
?
See next slide
![Page 25: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/25.jpg)
Map to normalized view volume
1) translate (left, bottom, -near) to (0,0,0)2.) rescale x, y, z so volume is 2 x 2 x 2 and flip z axis (into left handed coordinates !)3.) translate so volume is centered at origin
![Page 26: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/26.jpg)
(w x, w y, w z, w)
is in the
normalized view volume if :
w > 0 (Recall a few slides ago)
- w <= w x <= w
- w <= w y <= w
- w <= w z <= w
![Page 27: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/27.jpg)
Putting in all together ...
![Page 28: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/28.jpg)
![Page 29: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/29.jpg)
"Clip Coordinates"Object Coordinates
![Page 30: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/30.jpg)
"ClipCoordinates"
ObjectCoordinates "Normalized
Device Coordinates"
"Perspective Division"In OpenGL, this happens after clipping (next lecture)
![Page 31: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/31.jpg)
![Page 32: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/32.jpg)
![Page 33: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/33.jpg)
![Page 34: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/34.jpg)
The surface normal of a plane (triangle) does notnecessarily get mapped to the surface normal of themapped plane (triangle).
Why not ? (Space is deformed, and so right anglesare not preserved.)
![Page 35: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/35.jpg)
![Page 36: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/36.jpg)
![Page 37: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/37.jpg)
![Page 38: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/38.jpg)
except inspecialsituations
![Page 39: lecture 5 - McGill CIMlanger/557/5-slides.pdf · lecture 5 - projective transformation - normalized view volume - GL_PROJECTION matrix - clip coordinates - normalized device coordinates](https://reader034.fdocuments.us/reader034/viewer/2022051910/6000085dcce17f6029327bf0/html5/thumbnails/39.jpg)
Announcements
Today is ADD/DROP deadlinehttp://www.mcgill.ca/importantdates/key-dates
For the Assignments, we will use PyOpenGL (Python). It isalready installed on the lab computers.
Fahim (T.A.) has posted instructions for you to install it onyour computer:http://cim.mcgill.ca/~fmannan/comp557/Python%20and%20PyOpenGL%20Installation.html
If you need help with the installation, see him (or help eachother -- please use the discussion board).
We will try to get the assignment out Thursday as originallyplanned.