cs488
play

CS488 More Geometric Transformations, Object Hierarchies, and some - PowerPoint PPT Presentation

CS488 More Geometric Transformations, Object Hierarchies, and some Fonts Luc R ENAMBOT 1 Previous Lectures Frame buffers Drawing a line (Midpoint Line Algorithm) Polygon Filling (Edge-table algorithm) Line Clipping


  1. CS488 More Geometric Transformations, Object Hierarchies, and some Fonts Luc R ENAMBOT 1

  2. Previous Lectures • Frame buffers • Drawing a line (Midpoint Line Algorithm) • Polygon Filling (Edge-table algorithm) • Line Clipping (Cohen-Sutherland algorithm) • Polygon Clipping • Circles • Geometric Transformations ‣ More Transformations 2

  3. Transformations • Last time we talked about 2D and 3D transformations and how those transformations affect objects in the scene • Today we will talk more about this, and discuss how polygons are usually formed into hierarchies of more meaningful objects • We will also briefly discuss how fonts are handled 3

  4. Changing Coordinate Systems • Last time we talked about transforms in terms of an object (polygon, line, point) in the same coordinate system of the world, that is (0,0) for the object is the same as (0,0) for the world • An alternative way is for each object to have its own local coordinate system separate from all of the other objects and the world coordinate system 4

  5. Local Coordinates • This allows each object to be created separately and then added into the world, using transformations to place the object at the appropriate point • Useful when you build larger objects out of reusable smaller objects 5

  6. Example (1,4) (3,4) (-1,1) (1,1) (1,2) (3,2) (-1,-1) (1,-1) Square of width 2, height 2 6

  7. Example Rotation 45 deg Scaling (2,2) 7

  8. Example (2,2) (0,0) Translation (2,2) 8

  9. Design • When we design the object we place the center of rotation/scaling where we wish it to be. For a wheel the center of rotation would be where the axle is to be attached, for a hinged gate the center would be at the hinge. • Each object must then be translated/rotated/scaled (from its local coordinate system) to place it at the proper location in the world (in the world coordinate system) 9

  10. Example • Say we are drawing an automobile and we want to draw the 4 tires. We can either draw each of the 4 tires independently at the appropriate location, or draw the same tire centered at its origin 4 times, and each time move it to the appropriate location in the world 10

  11. OpenGL Example • Create a solar system with a single sun and a single planet in orbit about it • Simplifications • circular orbit • plane of the solar system: Y=0 plane • Sun at 0,0,0 and sphere of radius 1 • Planet a radius of 0.2 and orbits at a radius of 2 • The planet rotates about its axis once per day • The planet revolves around the sun once each year 11

  12. Code • glLoadIdentity(); //reset the matrix to the identity matrix • glPushMatrix(); • drawSphere(1.0) // user defined function to draw the sun • glRotatef(yearPercentage, 0.0, 1.0, 0.0); • glTranslatef(2.0, 0.0, 0.0); • glRotatef(dayPercentage, 0.0, 1.0, 0.0); • drawSphere(0.2) // user defined function to draw the planet • glPopMatrix(); 12

  13. Single Coordinate System • If you think about the single coordinate system then the operations on the matrix are done in the REVERSE order from which they are called: • Initially the transformation matrix is the identity matrix • The sun is drawn as a circle with radius 1 at (0,0,0) • The planet is drawn as a circle with radius 0.2 at (0,0,0) • The planet is rotated about the Y-axis by the percentage of day that has passed. Since the planet is still at the origin this rotates the planet about its center. • The planet is translated 2 units on the X-axis moving its center to (2, 0, 0) • The planet is rotated about the Y-axis by the percentage of year that has passed. Since the planet is no longer at the origin it rotates about the origin at a radius of 2 13

  14. Local Coordinate System • If you think about each object having its own coordinate system then the operations on the matrix are done in the SAME order as they are called: • Initially the transformation matrix is the identity matrix • The sun is drawn as a circle with radius 1 at (0,0,0) • The planet is rotated about its Y-axis by the percentage of year that has passed turning its coordinate system in the process • The planet is translated 2 units on its now rotated X-axis to its position in orbit • The planet is rotated about its Y-axis by the percentage of day that has passed. Since the planet is still at (0,0,0) by its coordinate system, it rotates about its center. • The planet is drawn as a circle with radius 0.2 14

  15. Example • Say you have three polygonal drawing functions available to you: • Draw a square centered at the origin with sides of length 1 • Draw a circle centered at the origin with diameter of length 1 • Draw a equilateral triangle with the center of its base at the origin with sides of length 1 How can I draw the following scene? 15

  16. Object Hierarchies • Single polygons are generally too small to be of interest • Its hard to think of a single polygon as an 'object' unless you are writing Tetris(tm) • It is more convenient to think of objects which are a collection of polygons forming a recognizable shape: a car, a house • This object can then be moved/rotated/scaled as a single entity, at least at the conceptual level 16

  17. Object Hierarchies • Creating an object polygon by polygon is very slow when you want to create a very large complex object • It does give you much more control over the object than creating it from higher-level primitives (cube, cone, sphere) 17

  18. OpenInventor • Silicon Graphics (SGI) library • OpenInventor(tm) sits on top of OpenGL • Allows higher-level objects to be created • File format and runtime environment 18

  19. Example • Model: a ‘tree’ • Constructed from a cube and a cone • Constructed from triangular polygons 19

  20. With primitives #Inventor V2.1 ascii Separator { Separator { Separator { Translation { Translation { translation 0 0.75 0 translation 0 -2 0 } } Material { Material { diffuseColor 0 0.8 0 diffuseColor 0.8 0.2 0 } } Cone { Cube { bottomRadius 1.4 width 0.75 height 4.3 height 1.75 } depth 0.75 } } 20

  21. With polygons (1) #Inventor V2.1 ascii Separator { Separator { Material { diffuseColor 0 0.8 0 normal [ 0 0.309586 -0.950871, } 0.363883 0.309586 -0.878491, Separator { 0.672368 0.309586 -0.672368, IndexedTriangleStripSet { 0.878491 0.309586 -0.363883, 0.950871 0.309586 4.15639e-08, vertexProperty 0.878491 0.309586 0.363883, VertexProperty { 0.672368 0.309586 0.672368, vertex [ 0 -1.4 -1.4, 0.363883 0.309586 0.878491, 0 2.9 0, 1.43578e-07 0.309586 0.950871, 0.535757 -1.4 -1.29343, -0.363883 0.309586 0.878491, 0.989949 -1.4 -0.989949, -0.672367 0.309586 0.672368, 1.29343 -1.4 -0.535757, -0.878491 0.309586 0.363883, 1.4 -1.4 6.11959e-08, -0.950871 0.309586 -1.1339e-08, 1.29343 -1.4 0.535757, -0.878491 0.309586 -0.363883, 0.989949 -1.4 0.989949, -0.672367 0.309586 -0.672368, 0.535757 -1.4 1.29343, -0.363882 0.309586 -0.878491, 2.11394e-07 -1.4 1.4, 0 -1 0 ] -0.535756 -1.4 1.29343, materialBinding OVERALL normalBinding PER_VERTEX_INDEXED -0.989949 -1.4 0.98995, } -1.29343 -1.4 0.535757, -1.4 -1.4 -1.66948e-08, -1.29343 -1.4 -0.535757, -0.989949 -1.4 -0.98995, -0.535756 -1.4 -1.29343, 0 -1.4 0 ] 21

  22. With polygons (2) Material { coordIndex [ 16, 0, 17, 2, 3, -1, 3, 4, diffuseColor 0.8 0.2 0 17, 5, 6, -1, 6, 7, 17, 8, } 9, -1, 9, 10, 17, 11, 12, -1, IndexedTriangleStripSet { 12, 13, 17, 14, 15, -1, 16, 17, vertexProperty VertexProperty { 15, -1, 1, 1, 0, 2, -1, 1, vertex [ -0.375 -1.125 0.375, 1, 2, 3, -1, 1, 1, 3, 4, -0.375 -2.875 0.375, -1, 1, 1, 4, 5, -1, 1, 1, 0.375 -1.125 0.375, 5, 6, -1, 1, 1, 6, 7, -1, 0.375 -2.875 0.375, 1, 1, 7, 8, -1, 1, 1, 8, 0.375 -1.125 -0.375, 9, -1, 1, 1, 9, 10, -1, 1, 0.375 -2.875 -0.375, 1, 10, 11, -1, 1, 1, 11, 12, -0.375 -1.125 -0.375, -1, 1, 1, 12, 13, -1, 1, 1, -0.375 -2.875 -0.375 ] 13, 14, -1, 1, 1, 14, 15, -1, normal [ 0 0 1, 1, 1, 15, 16, -1, 1, 1, 16, 0 0 -1, 0, -1 ] -1 0 0, normalIndex [ 16, 16, 16, 16, 16, -1, 16, 16, 1 0 0, 16, 16, 16, -1, 16, 16, 16, 16, 0 1 0, 16, -1, 16, 16, 16, 16, 16, -1, 0 -1 0 ] 16, 16, 16, 16, 16, -1, 16, 16, texCoord [ ] 16, -1, 15, 0, 0, 1, -1, 0, orderedRGBA [ ] 1, 1, 2, -1, 1, 2, 2, 3, materialBinding OVERALL -1, 2, 3, 3, 4, -1, 3, 4, normalBinding PER_VERTEX_INDEXED 4, 5, -1, 4, 5, 5, 6, -1, } 5, 6, 6, 7, -1, 6, 7, 7, 8, -1, 7, 8, 8, 9, -1, 8, coordIndex [ 5, 3, 7, 1, -1, 2, 4, 0, 9, 9, 10, -1, 9, 10, 10, 11, 6, -1, 5, 4, 3, 2, -1, 1, -1, 10, 11, 11, 12, -1, 11, 12, 0, 7, 6, -1, 7, 6, 5, 4, 12, 13, -1, 12, 13, 13, 14, -1, -1, 3, 2, 1, 0, -1 ] 13, 14, 14, 15, -1, 14, 15, 15, normalIndex [ 5, 5, 5, 5, -1, 4, 4, 4, 0, -1 ] 4, -1, 3, 3, 3, 3, -1, 2, } 2, 2, 2, -1, 1, 1, 1, 1, } -1, 0, 0, 0, 0, -1 ] } } } 22

  23. Polygons • Triangular polygons are often used instead of 4-sided ones because the 3 vertices in the triangle are guaranteed to form a plane, while the 4 vertices of a 4-sided polygon may not all fall in the same plane which may cause problems later on. 23

  24. Hierarchies • Hierarchies are typically stored as Directed Acyclic Graphs (DAG) • They are trees where a node can have multiple parents as long as no cycle is generated. 24

  25. Hierarchies • Hierarchies store all information necessary to draw an object: • Polygon information • Material information • Transformation information • An object hierarchy gives a high degree of encapsulation 25

Recommend


More recommend