computer graphics cs 543
play

Computer Graphics (CS 543) Lecture 4a: Introduction to - PowerPoint PPT Presentation

Computer Graphics (CS 543) Lecture 4a: Introduction to Transformations Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Hidden-Surface Removal If multiple surfaces overlap, we want to see only closest


  1. Computer Graphics (CS 543) Lecture 4a: Introduction to Transformations Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

  2. Hidden-Surface Removal  If multiple surfaces overlap, we want to see only closest  OpenGL uses hidden-surface technique called the z-buffer algorithm  Z-buffer compares objects distances from viewer (depth) to determine closer objects If overlap, Draw face A (front face) Do not draw faces B and C

  3. Using OpenGL’s z -buffer algorithm  Z-buffer uses an extra buffer, (the z-buffer), to store depth information, compare distance from viewer  3 steps to set up Z-buffer: In main( ) function 1. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH) Enabled in init( ) function 2. glEnable(GL_DEPTH_TEST) Clear depth buffer whenever we clear screen 3. glClear(GL_COLOR_BUFFER_BIT | DEPTH_BUFFER_BIT)

  4. 3D Mesh file formats  3D meshes usually stored in 3D file format  Format defines how vertices, edges, and faces are declared  Over 400 different file formats  Polygon File Format (PLY) used a lot in graphics  Originally PLY was used to store 3D files from 3D scanner  We will use PLY files in this class

  5. Sample PLY File ply format ascii 1.0 comment this is a simple file obj_info any data, in one line of free form text element vertex 3 property float x property float y property float z element face 1 property list uchar int vertex_indices end_header -1 0 0 0 1 0 1 0 0 3 0 1 2

  6. Georgia Tech Large Models Archive

  7. Stanford 3D Scanning Repository Happy Buddha: 9 million faces Lucy: 28 million faces

  8. Introduction to Transformations  May also want to transform objects by changing its:  Position (translation)  Size (scaling)  Orientation (rotation)  Shapes (shear)

  9. Translation  Move each vertex by same distance d = (d x , d y , d z ) object translation: every point displaced along same vector

  10. Scaling Expand or contract along each axis (about origin) x’=s x x y’=s y y z’=s z z p ’= Sp where S = S (s x , s y , s z )

  11. Introduction to Transformations  We can transform (translation, scaling, rotation, shearing, etc) object by applying matrix multiplications to object vertices       P ' m m m m P       x 11 12 13 14 x       P ' m m m m P  y 21 22 23 24 y       P ' m m m m P       z 31 32 33 34 z             1 0 0 0 1 1 Original Vertex Transformed Vertex Transform Matrix  Note: point (x,y,z) needs to be represented as (x,y,z,1), also called Homogeneous coordinates

  12. Why Matrices?  Multiple transform matrices can be pre-multiplied  One final resulting matrix applied (efficient!)  For example: transform 1 x transform 2 x transform 3 ….         Q m m m m m m m m P         x 11 12 13 14 11 12 13 14 x         Q m m m m m m m m P  y 21 22 23 24 21 22 23 24 y         Q m m m m m m m m P         z 31 32 33 34 31 32 33 34 z                 1 0 0 0 1 0 0 0 1 1 Transform Matrices can Original Point Transformed Point Be pre-multiplied

  13. 3D Translation Example object Translation of object Example: If we translate a point (2,2,2) by displacement (2,4,6), new  location of point is (4,6,8) Using matrix multiplication for translation   2     4 1 0 0 2 Translate(2,4,6)         2     0 1 0 4 6      Translate x: 2 + 2 = 4     2 0 0 1 6 8            Translate y: 2 + 4 = 6         0 0 0 1 1 1  Translate z: 2 + 6 = 8 Translated Original point Translation Matrix point

  14. 3D Translation Translate object = Move each vertex by same distance d = (d x , d y , d z )  object Translation of object       x x ' 1 0 0 d       Translate(dx,dy,dz) x       y *  0 1 0 y ' d y    Where:     z 0 0 1 d   z '       z  x’= x + dx       1     0 0 0 1 1  y’= y + dy Translation Matrix  z’= z + dz

  15. Scaling Example If we scale a point (2,4,6) by scaling factor (0.5,0.5,0.5) Scaled point position = (1, 2, 3)  Scale x: 2 x 0.5 = 1  Scale y: 4 x 0.5 = 2  Scale z: 6 x 0.5 = 3       1 0 . 5 0 0 0 2             2 0 0 . 5 0 0 4         3 0 0 0 . 5 0 6                   1 0 0 0 1 1 Scale Matrix for Scale(0.5, 0.5, 0.5)

  16. Scaling Scale object = Move each object vertex by scale factor S = (S x , S y , S z ) Expand or contract along each axis (relative to origin) x’=s x x y’=s y y z’=s z z Using matrix multiplication for scaling       ' 0 0 0 x S x       x       ' 0 0 0 y S y   y       z ' 0 0 S 0 z       z             1 0 0 0 1 1 Scale Matrix Scale(Sx,Sy,Sz)

  17. Shearing y*h x (x,y) (x + y*h, y) Y coordinates are unaffected, but x cordinates are translated linearly  with y That is:         y’ = y x 1 h 0 x        x’ = x + y * h           y 0 1 0 y             1 0 0 1 1  h is fraction of y to be added to x

  18. 3D Shear

  19. Reflection   S 0 0 0   x   0 S 0 0 y   0 0 S 0  corresponds to negative scale factors   z     0 0 0 1 s x = -1 s y = 1 original s x = -1 s y = -1 s x = 1 s y = -1

  20. References  Angel and Shreiner, Chapter 3  Hill and Kelley, Chapter 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend