computer graphics cs 543 lecture 4 part 1 building 3d
play

Computer Graphics CS 543 Lecture 4 (Part 1) Building 3D Models (Part - PowerPoint PPT Presentation

Computer Graphics CS 543 Lecture 4 (Part 1) Building 3D Models (Part 1) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Objectives Introduce simple data structures for building polygonal models Vertex


  1. Computer Graphics CS 543 – Lecture 4 (Part 1) Building 3D Models (Part 1) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

  2. Objectives  Introduce simple data structures for building polygonal models  Vertex lists  Edge lists  Deprecated OpenGL vertex arrays  Drawing 3D objects

  3. 3D Applications  2D: points have (x,y) coordinates  3D: points have (x,y,z) coordinates  In OpenGL, 2D graphics are special case of 3D graphics

  4. Setting up 3D Applications  Programming 3D, not many changes from 2D Load representation of 3D object into data structure 1.  Note: Vertices stored as 3D points (x, y, z)  Use vec3, glUniform3f instead of vec2 Draw 3D object 2. Hidden surface removal: Correctly determine order 3. in which primitives (triangles, faces) are rendered (Blocked faces NOT drawn)

  5. 3D Coordinate Systems Tip: sweep fingers x ‐ y: thumb is z  Y Y + z x x + z Left hand coordinate system •Not used in this class and Right hand coordinate system •Not in OpenGL

  6. Generating 3D Models: GLUT Models One way of generating 3D shapes is by using GLUT 3D models (Restrictive?)  Note: Simply make GLUT 3D calls in application program (Not shaders)  Two main categories of GLUT models:  Wireframe Models  Solid Models  Solid m odels W irefram e m odels

  7. 3D Modeling: GLUT Models  Basic Shapes Cone: glutWireCone( ), glutSolidCone( )  Sphere: glutWireSphere( ), glutSolidSphere( )  Cube: glutWireCube( ), glutSolidCube( )  Torus  More advanced shapes: Cone Newell Teapot: (symbolic)  Dodecahedron, Torus  Sphere

  8. GLUT Models: glutwireTeapot( )  Famous Utah Teapot has become an unofficial computer graphics mascot glutWireTeapot(0.5) - Create teapot of size 0.5, center positioned at (0,0,0) Also glutSolidTeapot( ) You need to apply transformations to position, scale and rotate it

  9. 3D Modeling: GLUT Models  Glut functions under the hood  generate sequence of points that define a shape  centered at 0.0 Example: glutWireCone generates sequence of vertices, and faces defining cone  and connectivity Generated vertices and faces passed to OpenGL for rendering  glutWireCone generates OpenGL program sequence of vertices, and receives vertices, faces defining cone Faces and renders them

  10. Polygonal Meshes  Modeling with GLUT shapes (cube, sphere, etc) too restrictive  Difficult to approach realism  Other (preferred) way is using polygonal meshes:  Collection of polygons, or faces, that form “skin” of object  More flexible  Represents complex surfaces better  Examples:  Human face  Animal structures  Furniture, etc

  11. Polygonal Mesh Example Sm oothed Mesh Out w ith ( w irefram e) Shading ( later)

  12. Polygonal Meshes  Meshes now standard in graphics  OpenGL Good at drawing polygons, triangles  Mesh = sequence of polygons forming thin skin around object   Simple meshes exact. (e.g barn)  Complex meshes approximate (e.g. human face)  Use shading technique later to smoothen

  13. Meshes at Different Resolutions Original: 424,000 60,000 triangles 1000 triangles triangles (14%). (0.2%) (courtesy of Michael Garland and Data courtesy of Iris Development.)

  14. Representing a Mesh v 5 e 2 v 6 e 3  Consider a mesh e 9 e 8 v 8 v 4 e 1 e 11 e 10 v 7 e 4 e 7 v 1 e 12 e 6 v 3 e 5 v 2  There are 8 vertices and 12 edges  5 interior polygons  6 interior (shared) edges (shown in orange)  Each vertex has a location v i = (x i y i z i )

  15. Simple Representation  Define each polygon by (x,y,z) locations of its vertices  Leads to OpenGL code such as vertex[i] = vec3(x1, y1, z1); vertex[i+1] = vec3(x6, y6, z6); vertex[i+2] = vec3(x7, y7, z7); i+=3;  Inefficient and unstructured  Vertices shared by many polygons are declared multiple times  Consider deleting vertex, moving vertex to new location  Must search for all occurrences

  16. Geometry vs Topology  Better data structures should separate geometry from topology  Geometry: (x,y,z) locations of the vertices  Topology: How vertices and edges are connected  Example: a polygon is an ordered list of vertices with an edge connecting successive pairs of vertices and the last to the first  Topology holds even if geometry changes (vertex moves)

  17. Polygon Traversal Convention  Use the right ‐ hand rule = counter ‐ clockwise encirclement of outward ‐ pointing normal  OpenGL can treat inward and outward facing polygons differently  The order {v 1 , v 6 , v 7 } and {v 6 , v 7 , v 1 } are equivalent in that the same polygon will be rendered by OpenGL but the order {v 1 , v 7 , v 6 } is different 4  The first two describe outwardly facing 3 5 polygons 2 6 1

  18. Vertex Lists  Vertex list: (x,y,z) of vertices (its geometry) are put in array  Use pointers from vertices into vertex list  Polygon list: vertices connected to each polygon (face) Example: x 1 y 1 z 1 v 1 ‐ Polygon P1 of x 2 y 2 z 2 mesh is connected P1 v 7 x 3 y 3 z 3 to vertices (v1,v7,v6) P2 v 6 x 4 y 4 z 4 P3 ‐ Vertex v7 coordinates x 5 y 5 z 5. P4 v 8 are (x7,y7,z7) x 6 y 6 z 6 P5 v 5 v 6 x 7 y 7 z 7 topology x 8 y 8 z 8 geometry

  19. Shared Edges  Vertex lists draw filled polygons correctly  If each polygon is drawn by its edges, shared edges are drawn twice  Alternatively: Can store mesh by edge list

  20. Edge List Simply draw each edges once E.g e1 connects v1 and v6 v 5 e 2 v 6 e 3 x 1 y 1 z 1 e 9 e1 v1 e 8 v 8 x 2 y 2 z 2 e2 v6 e 11 e 1 e 10 e3 x 3 y 3 z 3 v 7 e 4 e 7 e4 v 1 x 4 y 4 z 4 e 12 v 3 e5 e 6 x 5 y 5 z 5. e 5 e6 v 2 x 6 y 6 z 6 e7 x 7 y 7 z 7 e8 Note polygons are x 8 y 8 z 8 e9 not represented

  21. Modeling a Cube • In 3D, declare vertices as (x,y,z) using point3 v[3] • Define global arrays for vertices and colors typedef vex3 point3 ; point3 vertices[] = {point3(-1.0,-1.0,-1.0), point3(1.0,-1.0,-1.0), point3(1.0,1.0,-1.0), point3(-1.0,1.0,-1.0), point3(-1.0,-1.0,1.0), point3(1.0,-1.0,1.0), point3(1.0,1.0,1.0), point3(-1.0,1.0,1.0)}; typedef vec3 color3; color3 colors[] = {color3(0.0,0.0,0.0), color3(1.0,0.0,0.0), color3(1.0,1.0,0.0), color(0.0,1.0,0.0), color3(0.0,0.0,1.0), color3(1.0,0.0,1.0), color3(1.0,1.0,1.0), color3(0.0,1.0,1.0});

  22. References  Angel and Shreiner  Hill and Kelley, appendix 4

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