Modelling Representation Representation of Objects in 3 D
Modelling & Representation
Representation of Objects in 3 D l Parametric Surface: (R 2 ->R 3) Polygon mesh l High-order surface patch l l Implicit: (Solid/Volumetric: R 3 ->0) implicit l Volxels l CSG l
Polygon Mesh must be convex l better be planar or triangulation is required l can be represented either be a loop of vertices or edges l l mostly be a loop of vertices l l the order can be either clockwise or counter-clockwise two popular representations l l polygon soup indexed-face mesh
Polygon Soup l face = a list of vertex coordinates l object= a list of faces
Indexed-face Mesh l All vertex coordinates are placed in an array l Faces = a list of indices to the vertex coordinate array l Objects=a list of such indexed faces
Example
Example) in Polygon Soup l Pyramid={{{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}, . . . , {{0, 0, 1}, {-1, 0, 0}, {0, 0, -1}, {1, 0, 0}}}
Example) in Indexed-face Mesh l l l V 1 V 2 V 3 V 4 V 5 (0, 1, 0) (1, 0, 0) (0, 0, 1) (-1, 0, 0) (0, 0, -1) V[0] V[1] V[2] V[3] V[4] l F 1 l F 2 l F 3 l F 4 l F 5 l F 6 (v 1, v 3, v 2) F[0] (v 1, v 4, v 3) F[1] (v 1, v 5, v 4) F[2] (v 1, v 2, v 5) F[3] (v 3, v 4, v 5) F[4] (v 2, v 3, v 5) F[5] (0, 2, 1) (0, 3, 2) (0, 4, 3) (0, 1, 4) (2, 3, 4) (1, 2, 4)
Draw Methods l Geometric primitives Begin-end structure l Vertex specifying order l l Array l Display List
Geometric primitives l l l l l GL_POINTS: Individual points GL_LINES: Vertices pairs, individual line segments GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES: Vertices triplets interpreted as triangles GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS: Vertices quadruples, 4 sided polygons GL_QUAD_STRIP GL_POLYGON: Boundary of a simple, convex polygon
Begin-end structure l. A Primitive is started by l gl. Begin(GLenum l And mode); ended using l gl. End(); l Between them you can specify the primitive coordinates, color, normal etc.
Vertex specifying order GL_TRIANGLE_FAN GL_TRIANGLE_STRIP GL_QUAD_STRIP GL_TRIANGLES GL_QUADS
Example gl. Begin(GL_QUADS); gl. Normal 3 f(-1, 0, 0); gl. Vertex 3 d(0. 0, 1. 0, 0. 0); gl. Vertex 3 d(0. 0, -1. 0); gl. Vertex 3 d(0. 0, 1. 0, -1. 0); gl. Normal 3 f(0, 1, 0); gl. Vertex 3 d(0. 0, 0. 0); gl. Vertex 3 d(1. 0, 0. 0, -1. 0); gl. Vertex 3 d(0. 0, -1. 0); gl. Normal 3 f(1, 0, 0); gl. Vertex 3 d(1. 0, 0. 0); gl. Vertex 3 d(1. 0, -1. 0); gl. Vertex 3 d(1. 0, 0. 0, -1. 0; ( l gl. End; () l
Display Lists l Create a display list: l GLuint id; l void init( void ){ l l id = gl. Gen. Lists( 1 ); gl. New. List( id, GL_COMPILE ); … gl. End. List(); } l Call a created list: l void display( void ){ l l l } gl. Call. List( id );
Display Lists Not all Open. GL routines can be stored in display lists l State changes persist, even after a display list is finished l Display lists can call other display lists l Display lists are not editable, but you can fake it l l l make a list (A) which calls other lists (B, C, and D) delete and replace B, C, and D, as needed
Vertex Arrays l Enable the client states: l l ) Setup the pointers: l l gl. Enable. Client. State( GL_VERTEX_ARRAY Vertex array : gl. Vertex. Pointers() Color array: gl. Color. Pointers() Normal array: gl. Normal. Pointers() Draw with the arrays: l gl. Draw. Arrays( GL_TRIANGLE_STRIP, 0, num. Verts ); l void gl. Draw. Elements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
gl. Enable. Client. State() l l void gl. Enable. Client. State( GLenum array ); Parameters l array l l A symbolic constant for the array you want to enable or disable. This parameter can assume one of the following values: GL_COLOR_ARRAY l l GL_EDGE_FLAG_ARRAY l l If enabled, use normal arrays with calls to gl. Array. Element, gl. Draw. Elements, or gl. Draw. Arrays. See also gl. Normal. Pointer. GL_TEXTURE_COORD_ARRAY l l If enabled, use index arrays with calls to gl. Array. Element, gl. Draw. Elements, or gl. Draw. Arrays. See also gl. Index. Pointer. GL_NORMAL_ARRAY l l If enabled, use edge flag arrays with calls to gl. Array. Element, gl. Draw. Elements, or gl. Draw. Arrays. See also gl. Edge. Flag. Pointer. GL_INDEX_ARRAY l l If enabled, use color arrays with calls to gl. Array. Element, gl. Draw. Elements, or gl. Draw. Arrays. See also gl. Color. Pointer. If enabled, use texture coordinate arrays with calls to gl. Array. Element, gl. Draw. Elements, or gl. Draw. Arrays. See also gl. Tex. Coord. Pointer. GL_VERTEX_ARRAY l If enabled, use vertex arrays with calls to gl. Array. Element, gl. Draw. Elements, or gl. Draw. Arrays. See also gl. Vertex. Pointer.
gl. Vertex. Pointer() The gl. Vertex. Pointer function defines an array of vertex data. l void gl. Vertex. Pointer( GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer ); l Parameters l l size l l type l l The byte offset between consecutive vertices. When stride is zero, the vertices are tightly packed in the array. count l l The data type of each coordinate in the array using the following symbolic constants: GL_SHORT, GL_INT, GL_FLOAT, and GL_DOUBLE. stride l l The number of coordinates per vertex. The value of size must be 2, 3, or 4. The number of vertices, counting from the first, that are static. pointer l A pointer to the first coordinate of the first vertex in the array.
gl. Color. Pointer() The gl. Color. Pointer function defines an array of colors. void gl. Color. Pointer( GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer ); l Parameters l l l size l l type l l The byte offset between consecutive colors. When stride is zero, the colors are tightly packed in the array. count l l The data type of each color component in a color array. Acceptable data types are specified with the following constants: GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT, or GL_DOUBLE. stride l l The number of components per color. The value must be either 3 or 4. The number of static colors, counting from the first color. pointer l A pointer to the first component of the first color element in a color array.
gl. Normal. Pointer() The gl. Normal. Pointer function defines an array of normals. l void gl. Normal. Pointer( GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer ); l Parameters l l type l l stride l l The byte offset between consecutive normals. When stride is zero, the normals are tightly packed in the array. count l l The data type of each coordinate in the array using the following symbolic constants: GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, and GL_DOUBLE. The number of normals, counting from the first, that are static. pointer l A pointer to the first normal in the array.
gl. Draw. Arrays() The gl. Draw. Arrays function specifies multiple primitives to render. l void gl. Draw. Arrays( GLenum mode, GLint first, GLsizei count ); l Parameters l l mode l l first l l The kind of primitives to render. The following constants specify acceptable types of primitives: GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS, and GL_POLYGON. The starting index in the enabled arrays. count l The number of indexes to render.
gl. Draw. Elements void gl. Draw. Elements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices ); l Parameters l mode l l l count l l The number of elements to be rendered. type l l The kind of primitives to render. It can assume one of the following symbolic values: GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS, and GL_POLYGON. The type of the values in indices. Must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT. indices l A pointer to the location where the indices are stored.
Display Lists & Vertex Arrays l Better performance than immediate mode rendering l Display lists can be shared between multiple Open. GL context l reduce memory usage for multi-context applications l Vertex arrays may format data for better memory access
Appearance l Color l l Vertex color: Specified on a per-vertex basis Face color: Specified on a per-primitive basis using gl. Color 3 f(). l Must enable color material for color tracking: l l gl. Enable(GL_COLOR_MATERIAL); Material: l l AMBIENT DIFFUSE SPECULAR SHININESS
Color format – RGBA
Color format – color index
Material Properties l Define the surface properties of a primitive gl. Materialfv(face, property, value ); l separate materials for front and back
- Slides: 27