Computer Graphics (CS 4731) Computer Graphics (CS 4731) Lecture 7: Building 3D Models (Part 1) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)
St Standard Unit Vectors d d U it V t y Define 1 , 0 , 0 i i i k k 0 , 1 , 0 j j 0 0 , 0 , 1 k z x So that any vector, , , v a b b c a i i b b j j c k k
C Cross Product (Vector product) P d t (V t d t) If , , , , a a a a b b b b x y z x y z Then ( ) ( ) ( ) a b a b a b i a b a b j a b a b k y z z y x z z x x y y x Remember using determinant i j k a a a a a a x y z b b b x y z Note: a x b is perpendicular to a and b
C Cross Product P d t Note: a x b is perpendicular to both a and b a x b 0 a a b b
C Cross Product P d t Calculate a x b if a = (3,0,2) and b = (4,1,8)
C Cross Product P d t Calculate a x b if a = (3,0,2) and b = (4,1,8) a x b = -2 i – 16 j + 3 k
Finding Vector Reflected From a Surface Fi di V R fl d F S f a = original vector a = original vector n = normal vector r = reflected vector m = projection of a along n j i f l e = projection of a orthogonal to n n Note: Θ 1 = Θ 2 a r r e m m -m Θ 1 e a m Θ 2 2 2 r r a a m m e e
Lines Li Consider all points of the form C id ll i t f th f P( )=P 0 + d Line: Set of all points that pass through P 0 in direction Li S t f ll i t th t th h P i di ti of vector d
P Parametric Form t i F Two ‐ dimensional forms of a line T di i l f f li Explicit: y = mx +h Implicit: ax + by +c =0 Implicit: ax + by +c =0 α P 1 Parametric: x( ) = x 0 + (1- )x 1 x( ) x 0 (1 )x 1 1 - α P P α y( ) = y 0 + (1- )y 1 P o Parametric form of line More robust and general than other forms Extends to curves and surfaces
C Convexity it An object is convex iff for any two points in the An object is convex iff for any two points in the object all points on the line segment between these points are also in the object these points are also in the object P P Q Q not convex t convex
Obj Objectives ti Introduce 3D set up Introduce simple data structures for 3D models Vertex lists Edge lists Deprecated OpenGL vertex arrays Drawing 3D objects
3D A 3D Applications li ti 2D points: (x y) coordinates 2D points: (x,y) coordinates 3D points: have (x,y,z) coordinates In OpenGL 2D graphics are special case of 3D graphics In OpenGL, 2D graphics are special case of 3D graphics
Setting up 3D Applications Programming 3D, not many changes from 2D Load representation of 3D object into data structure 1. Each vertex has (x,y,z) coordinates. Store as vec3, glUniform3f NOT vec2 Draw 3D object Draw 3D object 2 2. Set up Hidden surface removal: Correctly determine 3. order in which primitives (triangles, faces) are rendered (e.g Blocked faces NOT drawn)
3D C 3D Coordinate Systems di t S t All vertex (x,y,z) positions are with respect to a All vertex (x,y,z) positions are with respect to a coordinate system OpenGL uses right hand coordinate system p g y Y Y + z x + z x Left hand coordinate system Left hand coordinate system • Not used in OpenGL Right hand coordinate system Tip: sweep fingers x ‐ y: thumb is z
G Generating 3D Models: GLUT Models i 3D M d l GLUT M d l One way of generating 3D shapes is by using GLUT 3D models (Restrictive?) Note: Simply make GLUT 3D calls in OpenGL program to generate vertices describing different shapes generate vertices describing different shapes Two types of GLUT models: Wireframe Models Solid Models Solid models Wireframe models Wireframe models
3D M d li 3D Modeling: GLUT Models GLUT M d l Basic Shapes Basic Shapes Cone: glutWireCone( ), glutSolidCone( ) Sphere: glutWireSphere( ), glutSolidSphere( ) Cube: glutWireCube( ), glutSolidCube( ) Torus Cone More advanced shapes: Newell Teapot: (symbolic) Newell Teapot: (symbolic) Dodecahedron, Torus Sphere Sp e e
GLUT M d l GLUT Models: glutwireTeapot( ) l t i T t( ) Famous Utah Teapot: unofficial computer graphics mascot Famous Utah Teapot: unofficial computer graphics mascot glutWireTeapot(0 5) glutWireTeapot(0.5) - Create teapot of size 0.5, center positioned at (0,0,0) 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
3D M d li 3D Modeling: GLUT Models GLUT M d l Glut functions under the hood Glut functions under the hood generate sequence of points that define a shape Example: glutWireCone generates sequence of E l l tWi C t f vertices, and faces defining cone and connectivity Generated vertices and faces passed to OpenGL for Generated vertices and faces passed to OpenGL for rendering glutWireCone generates OpenGL program sequence of vertices, and receives vertices and faces defining cone Faces, renders them
P l Polygonal Meshes l M h Modeling with GLUT shapes (cube sphere etc) too restrictive Modeling with GLUT shapes (cube, sphere, etc) too restrictive Difficult to approach realism Other (preferred) way is using polygonal meshes: (p ) y g p yg Collection of polygons, or faces, that form “skin” of object More flexible, represents complex surfaces better Examples: Human face Animal structures Furniture, etc Each face of mesh is a polygon
P l Polygonal Mesh Example l M h E l Smoothed h d Mesh Out with (wireframe) Shading (later)
P l Polygonal Meshes l M h Meshes now standard in graphics 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) C l h i ( h f )
M Meshes at Different Resolutions h t Diff t R l ti Original: 424,000 60,000 triangles 1000 triangles triangles (14%). (0.2%) (courtesy of Michael Garland and Data courtesy of Iris Development.)
R Representing a Mesh ti M h v 5 e 2 v 6 e 3 3 Consider a mesh Consider a mesh e e 9 e 8 v 8 v 4 e 1 e 11 e 10 e v 7 v 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 ) ( )
Si Simple Representation l R t ti Define each polygon by (x y z) locations of its vertices Define each polygon by (x,y,z) locations of its vertices OpenGL code vertex[i] = vec3(x1, y1, z1); t [i] 3( 1 1 1) 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 Vertices shared by many polygons are declared multiple times Consider deleting vertex, moving vertex to new location Must search for all occurrences
I Issues with Simple Representation i h Si l R i v 5 Declaring face f1 Declaring face f1 v 6 vertex[i] = vec3(x1, y1, z1); v 8 v 4 vertex[i+1] = vec3(x7, y7, z7); f 1 f 1 vertex[i+2] = vec3(x8, y8, z8); vertex[i+3] = vec3(x6, y6, z6); v 7 Declaring face f2 v 1 f 2 v v 3 vertex[i] = vec3(x1, y1, z1); vertex[i] = vec3(x1 y1 z1); vertex[i+1] = vec3(x2, y2, z2); v 2 vertex[i+2] = vec3(x7, y7, z7); Inefficient and unstructured Inefficient and unstructured In example, vertices v1 and v7 repeated while declaring f1 and f2 Vertices shared by many polygons are declared multiple times y y p yg p Consider deleting vertex, moving vertex to new location Must search for all faces in which vertex occurs
G Geometry vs Topology t T l Better data structures separate geometry from topology Better data structures 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 Topology holds even if geometry changes (vertex moves) T l h ld if t h ( t ) v 6 v 5 v 8 v v v 4 f 1 v 7 Example: even if we move (x,y,z) location of v1, v1 still connected to v6, v7 and v2 v v 1 f 2 f v 3 v 1 v 2
P l Polygon Traversal Convention T l C i Use the right hand rule = counter clockwise encirclement Use the right ‐ hand rule = counter ‐ clockwise encirclement of outward ‐ pointing normal OpenGL can treat inward and outward p facing polygons differently The order {v 1 , v 0 , v 3 } and {v 3 , v 2 , v 1 } are equivalent in same polygon, rendered same way rendered by OpenGL But order of {v 1 , v 2 , v 3 } is different 4 The first two describe outwardly facing 3 5 polygons polygons 2 6 1
Recommend
More recommend