opengl shapes SURFACES -------- a small tutorial about 3D stuff. opengl provides to primitives to draw meshes. meshes are discrete (sampled) 2 dimensional surfaces. it is important to distinguish between two kinds of surfaces. * POLYHEDRA * SMOOTH SURFACES polyhedra are built out of a finite number of vertices (0D points), edges (1D lines), and faces (2D flat surfaces). http://mathworld.wolfram.com/Polyhedron.html on the other hand, smooth surface don't have "sharp points". examples: * a bathtub * a sphere * a teapot to represent smooth surfaces on a computer, they have to be made discrete somehow (sampled). this is done by converting them to polyhedra. to be correct i should say i'm talking about closed surfaces, i.e. surfaces without edges. in practice surfaces don't have to be closed. now, in order to get realistic lighting (shading) effects, opengl can associate to each vertex a normal vector. this represents the orientation of the 'real' surface at a vertex. suppose we have a sampled version of a smooth surface, i.e. a triangular mesh. each triangle in a mesh is in principle a flat surface, but by associating a normal to each vertex, the transition from one triangle to another can be made to appear smoother. effectively this associates some form of curvature to the triangle, which is used by shading algorithms to compute the colour and intensity of a triangle when it is rendered. the thing to remember is that when drawing meshes, it is important to make the distinction: * does my surface have real flat segments * or does it approximate a smooth surface what this boils down to for normal vectors: * SEGMENTED -> 1 normal vector associated to each face, vertices have more * SMOOTH -> 1 normal associated to each vertex, surfaces have more COLOUR, TEXTURE and ORIENTATION ------------------------------- in addition to geometrical data, there is also * vertex color: the colour of a surface at a point, used for interpolating the colour of a surface between vertices * texture coordinate: additional (colour,bump,...) information about a vertex, looked up in an 1D,2D,3D,... table (=texture) * surface orientation: looking at a polygon, you face the outside if the vertices are arranged counterclockwize. this is important for culling and shading. VERTEX ARRAYS ------------- in PF you'll have full control over meshes at a low level, since drawing is at the same level as opengl: using the primitives "points, lines, linestrip, lineloop, polygon, quads, quadstrip, triangles, trianglestrip, trianglefan" these take the arguments: if is a single matrix, each row will be interpreted according to , for example ((1. 0. 0) (0. 1. 0) (1. 1. 0)) >matrix "v3" triangles interprets each row as a 3--component vertex. adding colour gives ((1. 0. 0. 1. 0. 0) (1. 1. 0. 0. 1. 0) (1. 1. 1. 1. 1. 0)) >matrix "c3v3" triangles if is a list of matrices, they are interpreted in a similar way, where the rows of the matrices are interpreted according to . for example ((1. 0. 0) (0. 1. 0) (1. 1. 0)) >matrix ((1. 0. 0) (1. 1. 0) (1. 1. 1)) >matrix 2 pack "cv" triangles The different types of vectors in are c color t texture coordinate n normal v vertex x don't use (to skip columns) POLAR BLOBS One interesting way of making shapes is to use uniform blobs: an array of numbers specifying the radius to a point. This can be easily translated into a 2D matrix for use as a polygon.