Simple Geometric Modeling

Size: px
Start display at page:

Download "Simple Geometric Modeling"

Transcription

1 Simple Geometric Modeling Prerequisites This module requires an understanding of simple 3-dimensional geometry, knowledge of how to represent points in 3-space, and enough programming experience to be comfortable writing code that calls functions to do the required tasks. Introduction In order to create any kind of image, one must first model the image in a way that can be understood by the computer and that is appropriate for the graphics API being used. For most graphics programming, particularly when is beginning to learn the field, one models an image using a few simple graphics primitives points, line segments, and polygons. A point is simply a single location in 3-space, specified by its coordinates. It is drawn by lighting a single pixel at the screen location that best represents the location of that point in space. To draw the point you specify that you want to draw points and specify the point s coordinates. A line segment is determined by its two endpoints, so to draw the line you indicate that you want to draw lines and specify the two endpoints. A polygon is determined by a sequence of points (called the vertices of the polygon), so to draw the polygon you indicate that you want to draw polygons and specify the sequence of vertex points. Figure 2.1 illustrates the distinction between a point, a line segment, and a polygon. Figure 2.1: determining a point, a line segment, and a polygon Perhaps the most difficult or at least the most time-consuming part of beginning graphics programming is creating the models of the image you want to create so that the image can be drawn. This may require you to create hand-drawn sketches of your image so you can determine the correct values for the points used in defining it, for example, or it may be possible to determine the values for points from some other technique. But until you get the points right, you will not be able to get the image right. Definitions There are some terms we need to talk about modeling. Modeling is defining the objects that are part of the scene you want to view in an image. There are many ways to model a scene for an image; in fact, there are a number of commercial programs you can buy that let you model scenes with very high-level tools. For much graphics programming, and certainly as you are beginning in this field, you will do your modeling by defining your geometry in terms of relatively simple primitive terms. While it is possible to think about graphics in two dimensions, these modules consider graphics entirely in three-dimensional terms. Because of this, we will think about 3D graphics primitives. Probably the most important of these is the concept of a polyghedron a 3D object which is bounded by polygons. In turn, a polygon is a plane region bounded by edges, and an edge is a line segment determined by vertices. Finally, a vertex is a point in 3-spacexxx. Because figures in 3-space determined by more than three vertices cannot be guaranteed to line in a plane, polyhedra 5/29/00 Page 2.1

2 are often defined to have triangular faces; a triangle always lies in a plane (because three points in 3-space determine a plane. All modeling requires that you know the coordinates of the points you need to create your image. Once you have chosen the simple components that the image will have, and you know the coordinates of all the vertex points for these components, you will use functions such as those below to create the image: glbegin(mode); // vertex list: point data to create a primitive object in // the drawing mode you have indicated The vertex list is interpreted differently for each drawing mode, and both the drawing modes and the interpretation of the vertex list are described in the discussions below. This pattern of glbegin(mode) - vertex list - glend uses different values of the mode to establish the way the vertex list is used in creating the image. Because you may use a number of different kinds of components in an image, you may use this pattern several times for different kinds of drawing. We will see a number of examples of this pattern in this module. Besides defining a single point, line segment, or polygon, there are techniques for defining larger objects that are made up of several simple objects. These can involve disconnected sets of objects, such as points, line segments, quads, or triangles, or can build images from connected objects, such as lines, quad strips, triangle strips, or triangle fans. Look at the discussions and examples below to build your repetoire of techniques you can use for your modeling. Point (or vertex) information is presented to the computer through a set of functions that go under the general name of glvertex( ). These functions transform raw numeric information into a form that the system can use. We say that glvertex( )is a set of functions because there are many functions that differ only in the way they define their point data. You may want or need to specify your vertex coordinate data in any standard numertic type, and these functions allow the system to respond to your needs. For full details, see the manuals on OpenGL; here we will use only those versions of the glvertex function that we believe are most useful. If you want to specify your vertex data as three separate floats (we'll call them x, y, and z, though they could also be float constants), you can use glvertex3f(x,y,z) (note that the letter f is appended to the glvertex name; if you wanted to use three integers, you would use glvertex3i and if you wanted to use doubles you would use glvertex3d. Moreover if you wanted to do 2-dimensional graphics you would replace the 3 by 2. If you want to specify your data as an array you could declare your data as glfloat x[3] and thenuse glvertex3fv(x) to specify the vertex. This adds the letter v to say that the data is a vector (actually a pointer to an array, but an array s name is really such a pointer). As before, you can use 2, 3, or 4 for the dimension and can use any of several letters besides f if your data is another type besides float. You will see this used in the code examples at the end of this module. One of the most important things to realize about modeling in OpenGL is that you can call your own functions between a glbegin(mode) and glend() pair to determine vertices for your vertex list. Any vertices these functions define by making a glvertex*( ) function call will be added to the vertex list for this drawing mode. This allows you to do whatever computation you need to calculate vertex coordinates instead of creating them by hand, saving yourself significant effort and possibly allowing you to create images that you could not generate by hand. For example, you may include various kind of loops to calculate a sequence of vertices, or you may include logic to decide which vertices to generate. An example of this way to generate vertices is given among the first of the code examples toward the end of this module. 5/29/00 Page 2.2

3 Another important point about modeling is that a great deal of other information can go between a glbegin(mode) and glend() pair. We will see the importance of including information about vertex normals in the chapters on lighting and shading, and of including information on texture coordinates in the chapter on texture mapping. So this simple construct can be used to do much more than just specify vertices. Some examples We will begin with very simple objects and proceed to more useful ones. With each kind of primitive object, we will describe how that object is specified, and in later examples, we will create a set of points and will then show the function call that draws the object we have defined. Point and points This is perhaps the simplest of all the drawings. In the glbegin function, the mode we use is GL_POINTS, and the data between glbegin and glend is the set of coordinates of each point we wish to draw. As noted above, each point s coordinates are presented using some form of the glvertex*( ) function, and the number of points drawn is the number of vertices that are specified. If we want to draw only one point, we provide only one vertex between glbegin and glend; if we want to draw more points, we provide more vertices between them. Line segments To draw a line segment, we use the GL_LINES mode for glbegin. For each segment we wish to draw, the data we need to provide is the two endpoints of the segment. Thus between glbegin and glend we must provide two vertices in the vertex list for each segment, using some form of the glvertex*( ) function. Connected lines Connected lines line segments that are joined head to tail to form a longer connected group are available by using the mode GL_LINE_STRIP for glbegin. The vertex list defines the line segments by using the first two vertices for the first line segment, and then by using each new vertex and its predecessor to define each additional segment. Thus if you have N vertices, you will have N-1 line segments. Triangle If you want to draw one or more unconnected triangles, you can use glbegin with the mode GL_TRIANGLES. In this mode, the vertex list is taken three at a time, and each set of three vertices defines an individual triangle. The triangle may seem to be the most simple of the polygons, but as we noted earlier, it is probably the most important because no matter how you use it, and no matter what points form its vertices, it always lies in a plane. Because of this, most polygon-based modeling really comes down to triangle-based modeling in the end. So treat this humblest of polygons well. Sequence of triangles Triangles are the foundation of most truly useful polygon-based graphics, and they have some very useful capabilities. OpenGL provides two different techniques to assemble sequences of triangles into your image: triangle strips and triangle fans. Each has its own mode for glbegin: 5/29/00 Page 2.3

4 GL_TRIANGLE_STRIP and GL_TRIANGLE_FAN respectively. The behavior of each is shown in Figure 2.2 below. Figure 2.2: triangle strip and triangle fan To create a triangle strip, the first three vertices in the vertex list create the first triangle, and each vertex after that creates a new triangle with the two vertices immediately before it. To create a triangle fan, the first three vertices create the first triangle and each vertex after that creates a new triangle with the point immediately before it and the first point in the list. Quadrilateral A quadrilateral (actually a quad, because a general quadrilateral need not be convex) is any convex 4-sided figure, and to create a set of one or more distinct quadrilaterals you can use the GL_QUADS mode with glbegin( ) - glend. Each quadrilateral requires four vertices in the vertex list, so the first four vertices define the first quadrilateral, the next four the second quadrilateral, and so on. The sequence of vertices is that of the points in the quadrilateral. In an example below, we use six quadrilaterals to define a cube that will be used very often (with modifications and expansion as needed) in later examples. Sequence of quadrilaterals To create a sequence of quadrilaterals, the mode for glbegin( ) is GL_QUAD_STRIP. This specifies that the vertices in the vertex list are to be taken as vertices of a sequence of quadrilaterals that share come common sides the first four vertices define the first quadrilateral and the last two of these, together with the next two, define the next vertex. However, the order in which the vertices are presented is different from that in the GL_QUADS mode, as noted in Figure Figure 2.3: sequence of points in a quad strip Note the order of the vertices; instead of the expected sequence around the quads, the points in each pair have the same order. Thus the sequence 3-4 is the opposite order than would be expected, and this same sequence goes on in each additional pair of extra points. This difference is critical to note when you are implementing quad strip constructions. It might be helpful to think of this in terms of triangles, because a quad strip acts as though it were really a triangle strip. 5/29/00 Page 2.4

5 General polygon Some images need to include more general kinds of polygons. While these can be created by constructing them manually as collections of triangles and/or quads, it might be easier to define and display a single polygon. The GL_POLYGON mode for glbegin allows you to define and display a single convex polygon. The vertices in the vertex list are taken as the vertices of the polygon in sequence order. As we noted in the early mathematical discussions, OpenGL can only handle convex polygons polygons for which any two points in the polygon also have the entire line segment between them in the polygon. We refer you to that earlier discussion for more details. Data structures to hold objects There are many ways to hold the information that describes a graphic object. One of the simplest is the triangle list an array of triples, and each set of three triples represents a separate triangle. Drawing the object is then a simple matter of reading three triples from the list and drawing the triangle. A more effective, though a bit more complex, approach is to create two lists. The first is a vertex list, and it is simply an array of triples that contains all the vertices that would appear in the object. If the object is a polyhedron, the second is a face list, containing information on each of the faces in the polyhedron. Each face is indicated by listing the indices of all the vertices of the face, in the order needed by the orientation of the face. You can then draw the face by using the indices as an indirect reference to the actual vertices. This is the basic approach taken by the discussion of the classic cube below; there is a vertex array, and the actual drawing takes place by referring to the vertices by their indices, not their values. (We should point out quickly, however, that the code in that example does not use actual face lists but rather is organized rather informally.) It is also possible to include one more step and include an edge list, a list of all the edges of the object, each stored as a pair of indices into the vertex list. Neither of these approaches takes into account the very significant savings in memory you can get by using triangle strips, triangle fans, or quad strips as discussed below. These approaches not only save space, but they are more effective for the graphics system as well because they allow the system to retain some of the information it generates in rendering one triangle or quad when it goes to generate the next one. However, it is difficult to have a model stored in a file contain all the information you would need to set up these compressed forms, so we will not pursue these further here. Additional sources of graphic objects Interesting and complex graphic objects can be difficult to create, because it can take a lot of work to measure or calculate the detailed coordinates of each vertex needed. There are more automatic techniques being developed, including 3D scanning techniques and detailed laser rangefinding to measure careful distances and angles to points on an object that is being measured, but they are out of the reach of most college classrooms. So what do we do to get interesting objects? There are four approaches. The first way to get models is to buy them: to go is to the commercial providers of 3D models. There is a serious market for some kinds of models, such as medical models of human structures, from the medical and legal worlds. This can be expensive, but it avoids having to develop the expertise to do professional modeling and then putting in the time to create the actual models. If you are interested, an excellent source is viewpoint.com; they can be found on the Web. 5/29/00 Page 2.5

6 A second way to get models is to find them in places where people make them available to the public. If you have friends in some area of graphics, you can ask them about any models they know of. If you are interested in molecular models, the protein data bank (URL has a wide range of structure models available at no charge. If you want models of stuff, try avalon.viewpoint.com; this site contains a large number of public-domain models contributed to the community by friendly people over the years. A third way to get models is to digitize them yourself with appropriate kinds of digitizing devices. There are a number of these available with their accuracy often depending on their cost, so if you need to digitize some physical objects you can compare the cost and accuracy of a number of possible kinds of equipment. A fourth way to get models is to create them yourself. There are a number of tools that support high-quality interactive 3D modeling, and it is no shame to create your models with such tools. It is also possible to create interesting models analytically, using mathematical approaches to generate the vertices. This is perhaps slower than getting them from other sources, but you have final control over the form and quality of the model, so perhaps it might be worth the effort. One problem may present itself if you find models from a public-domain source or from some kind of modeling software. These models are usually stored in a file format that is specific to the tools used to create them, and it may take some work to write filters that will read these formats into the kind of data structures you want for your program. Perhaps things that are free might cost more than things you buy if you can save the work of the conversion but that s up to you to decide. Additional objects Most OpenGL systems also include the OpenGL Utility Library (GLU), and you can take advantage of this to use additional primitive objects in your images. Among these are general quadric objects: objects defined by quadric equations (polynomial equations in three variables with degree no higher than two in any term). Spheres (glusphere), cylinders (glucylinder), and disks (gludisk) are pre-defined in the GLU system. There are a number of additional details involved in using GLU objects that are more complex than we believe belong in a simple modeling module, and we refer you to your system s GLU manual for these details. A word to the wise... As we said above, modeling can be the most time-consuming part of creating an image, but you simply aren t going to create a useful or interesting image unless the modeling is done carefully and well. If you are concerned about the programming part of the modeling for your image, it might be best to create a simple version of your model and get the programming (or other parts that we haven t talked about yet) done for that simple version. Once you are satisfied that the programming works and that you have gotten the other parts right, you can replace the simple model the one with just a few polygons in it with the one that represents what you really want to present. And don't forget that you can use all your programming tools to determine the vertices for your models, working between the glbegin( ) and glend() functions and setting vertices with the glvertex*( ) functions. Code examples The examples below illustrate how to define objects using the glbegin( ) - glend delimiters and vertex lists defined by various kinds of glvertex***( ) functions. These examples are anything but exhaustive of all the possible combinations, but they should be good starting points. 5/29/00 Page 2.6

7 In addition, this module is accompanied by a set of short example programs that use the kinds of object definitions below to show you how the modeling is used in context. You will probably be surprised to see how primitive the images are that the example programs create. This is because these simple programs do not include any kind of lighting information. For better images, look at the examples of these same kinds of modeling that use lighting. A set of points While it would be interesting to create a 3D space with points scattered in it as a model of a starfield, it s probably more useful to define an orderly set of points that is easier to see in a sample program. We will define a set of points that lie on the line x = y = -z using a simple for loop as kind of a third-grade graphing exercise. These points are initially defined by specifying the point coordinates directly. glbegin(gl_points); for (i=0; i<10; i++) glvertex3f( (float)i, (float)i, (float)-i ); As we noted above, however, we can take advantage of the computational capabilities of ordinary programming to define our models, so it is absolutely not necessary to hand-calculate points when we can determind them by an algorithmic approach. So this example can be re-phrased as follows. and this is the version in the sample program with this module. void pointat(int i) { glvertex3f(0.2*(float)(i-5),0.2*(float)(i-5),0.2*(float)(5-i)); void pointset( void ) { int i; glbegin(gl_points); for ( i=0; i<10; i++ ) pointat(i); A line loop Parametric curves in 3-space are often interesting objects of study. The glbegin( ) glend() pair and the vertex list below define a rough spiral in 3-space that is a good (though simple) example of using a single parameter to define points on a parametric curve so it can be drawn for study. glbegin(gl_line_strip); for ( i=0; i<=10; i++ ) glvertex3f(2.0*cos( *(float)i/5.0), 2.0*sin( *(float)i/5.0),0.5*(float)(i-5)); 5/29/00 Page 2.7

8 This can be made much more sophisticated by increasing the number of line segments, and the code can be cleaned up a bit as described in the code fragment below. Simple experiments with the step and zstep variables will let you create other versions of the spiral as experiments. #define PI #define N 100 step = 2.0*PI/(float)N; zstep = 2.0/(float)N; glbegin(gl_line_strip); for ( i=0; i<=n; i++) glvertex3f(2.0*sin(step*(float)i),2.0*cos(step*(float)i), -1.0+zstep*(float)i); The example program that draws this spiral includes more than just drawing the spiral; it also includes some simple keyboard-driven rotations that let you see the spiral from many points in 3- space. Among the things you can see are the simple sine and cosine curves, as well as one period of the generic shifted sine curve. A single polygon with many sides Probably the simplest kind of convex polygon is the regular N-gon, an N-sided figure with all edges of equal length and all interior angles between edges of equal size. This is simply created, again using trigonometric functions to determine the vertices. #define PI #define N 7 step = 2.0*PI/(float)N; glbegin(gl_polygon); for ( i=0; i<=n; i++) glvertex3f(2.0*sin(step*(float)i),2.0*cos(step*(float)i),0.0);; Note that this polygon lives in the XY-plane; all the Z-values are zero. This polygon is also in the default color (white) for simple models. This is an example of a canonical object an object defined not primarily for its own sake, but as a template that can be used as the basis of building another object as noted later, when transformations and object color are available. An interesting application of regular polygons is to create regular polyhedra closed solids whose faces are all regular N-gons. These polyhedra are created by writing a function to draw a simple N-gon and then using transformations to place these properly in 3-space to be the boundaries of the polyhedron. We will see this later in the module on transformations. Two objects made of triangles Because there are two different modes for drawing sequences of triangles, we ll consider two examples in this section. The first is a triangle fan, used to define an approximation to a cone that can be used for such applications as a pointer in 3-space. The second is a triangle strip, often used to define surfaces when the surface has the kind of curvature that keeps rectangles from being planar. Triangle strips are a better basis for curved surfaces that need to show their surface properties when lighted. The triangle fan is defined in a canonic al way, with a circular base of radius 1.0 in the XZ-plane centered at the origin and a vertex at point (0.0,2.0,0.0) so the cone points upwards in space. When the cone is actually used, it will be transformed to have the size, orientation, and location you need. 5/29/00 Page 2.8

9 glbegin(gl_triangle_fan); glvertex3f(0,2.0,0); for (i=0; i < numstrips-1;i++) { angle = 2 * i * PI / numstrips; glvertex3f(cos(angle),0.0,sin(angle)); glvertex3f(cos(0.0),0.0,sin(0.0)); The triangle strip example is probably easier to see if you refer first to the quadrilaterals section. There we show how to define a mathematical surface as a set of quads. But for many such surfaces, quads are not planar and so do not show the surface properties correctly. Instead of taking the quad approach, the glbegin(gl_quads) glend() section could be replaced by a small quad strip: glbegin(gl_triangle_strip); glvertex3f(xx(i),vertices[i][j],zz(j)); glvertex3f(xx(i+1),vertices[i+1][j],zz(j)); glvertex3f(xx(i),vertices[i][j+1],zz(j+1)); glvertex3f(xx(i+1),vertices[i+1][j+1],zz(j+1)); Note that the sequence of points is slightly different here than it is in the example below; we have a triangle with the points with indices (i,j), (i+1,j), (i,j+1) and another with the points with indices (i+1,j), (i,j+1), (i+1,j+1). Thus instead of one quad, we will have two triangles and if you are clever enough to use quad strips instead of simple quads to re-do the mathematical surface below, it is simple to make the change noted here and do the surface with triangle strips. An object made from a sequence of quadrilaterals Quadrilaterals (usually called quads in OpenGL) are sometimes a more natural basis to build models on than are triangles. In one of the example programs for this module we create long, narrow tubes with rectangular cross-section as the basis for drawing a 3-D coordinate system. The quad strip defined below creates the tube for the Z-axis, and the other two axes are created by using transformations with this tube. #define RAD 0.03 glbegin(gl_quad_strip); glvertex3f( RAD, RAD, 3.0 ); // start of first side glvertex3f( RAD, RAD, -3.0 ); glvertex3f(-rad, RAD, 3.0 ); glvertex3f(-rad, RAD, -3.0 ); glvertex3f(-rad,-rad, 3.0 ); // start of second side glvertex3f(-rad,-rad, -3.0 ); glvertex3f( RAD,-RAD, 3.0 ); // start of third side glvertex3f( RAD,-RAD, -3.0 ); glvertex3f( RAD, RAD, 3.0 ); // start of fourth side glvertex3f( RAD, RAD, -3.0 ); Another example of an object based on quadrilaterals would be a parametric surface, a surface defined by two parameters. In the same way a single parameter defined a curve in the spiral example above, two parameters can define a surface that is approximated by a set of of quads. The 5/29/00 Page 2.9

10 code below defines such an approach to a mathematical surface defined by an equation in two variables. The student is encouraged to try this same kind of surface based on quad strips. // This example computes Y as a function of X and Z, but the principle // of parametric surfaces is supported by viewing the surface as points // (X,Y,Z) with two parameters, i and j #define XSIZE 125 // larger than this for best results #define ZSIZE XSIZE #define MINX -3.0 // define the range of each parameter #define MAXX 3.0 #define MINZ -3.0 #define MAXZ 3.0 // functions return X and Z values for parameters i and j respectively GLfloat XX(int i) { return (MINX+((MAXX-MINX)/(float)(XSIZE-1))*(float)(i)); GLfloat ZZ(int j) { return (MINZ+((MAXZ-MINZ)/(float)(ZSIZE-1))*(float)(j)); // function defines the parametric surface based on the function // cos(x*x+z*z+t). This is actually a family of surfaces parametrized // by the value of t, which needs to be defined before this is actually // drawn. Substituting other functions is encouraged! void surface(void) { point3 vec1, vec2, trinormal; int i, j; float x, z; #define EPSILON.001; for ( i=0; i<xsize; i++ ) for ( j=0; j<zsize; j++ ) { x = XX(i); z = ZZ(j); vertices[i][j] = (x*x+2.0*z*z)/exp(x*x+2.0*z*z+t); // define the surface */ for ( i=0; i<xsize-1; i++ ) for ( j=0; j<zsize-1; j++ ) { // quad sequence: points (i,j),(i+1,j),(i+1,j+1),(i,j+1) glbegin(gl_quads); glvertex3f(xx(i),vertices[i][j],zz(j)); glvertex3f(xx(i+1),vertices[i+1][j],zz(j)); glvertex3f(xx(i+1),vertices[i+1][j+1],zz(j+1)); glvertex3f(xx(i),vertices[i][j+1],zz(j+1)); Note that this surface is not going to look very good yet because it does not yet contain any lighting or color information. These will be added in later chapters as this surface is re-visited when we discuss lighting and color. The cube we will use in many later examples 5/29/00 Page 2.10

11 Because a cube is made up of six square faces, it is very tempting to try to make the cube from a single quad strip. Looking at the geometry, though, it is impossible to make a single quad strip go around the cube; in fact, the largest quad strip you can create from a cube s faces has only four quads. It is possible to create two quad strips of three faces each for the cube (think of how a baseball is stitched together), but here we will only use a set of six quads whose vertices are the eight vertex points of the cube. Below we show the vertex declarations (we use an array of arrays; it may be new to you but it s a very effective way to define an object) and show how the cube is specified. With this option, we use the glvertex3fv( ) vertex specification function. In an example program we will show how this looks without any lighting specifications, but it will need lights and lighting in order to really look like a cube. point3 vertices[8]={{-1.0, -1.0, -1.0, {-1.0, -1.0, 1.0, {-1.0, 1.0, -1.0, {-1.0, 1.0, 1.0, { 1.0, -1.0, -1.0, { 1.0, -1.0, 1.0, { 1.0, 1.0, -1.0, { 1.0, 1.0, 1.0 ; glbegin(gl_quads); // glnormal3fv(normals[0]); // normals will be used for later work glvertex3fv(vertices[1]); // first quad: positive Z face glvertex3fv(vertices[5]); glvertex3fv(vertices[7]); glvertex3fv(vertices[3]); // glnormal3fv(normals[5]); glvertex3fv(vertices[7]); // second quad: positive Y face glvertex3fv(vertices[6]); glvertex3fv(vertices[2]); glvertex3fv(vertices[3]); // glnormal3fv(normals[2]); glvertex3fv(vertices[2]); // third quad: negative Z face glvertex3fv(vertices[6]); glvertex3fv(vertices[4]); glvertex3fv(vertices[0]); // glnormal3fv(normals[3]); glvertex3fv(vertices[5]); // fourth quad: positive X face glvertex3fv(vertices[4]); glvertex3fv(vertices[6]); glvertex3fv(vertices[7]); // glnormal3fv(normals[4]); glvertex3fv(vertices[4]); // fifth quad: negative Y face glvertex3fv(vertices[5]); glvertex3fv(vertices[1]); glvertex3fv(vertices[0]); // glnormal3fv(normals[1]); glvertex3fv(vertices[0]); // sixth quad: negative X face glvertex3fv(vertices[1]); glvertex3fv(vertices[3]); glvertex3fv(vertices[2]); This approach specifically identifies all the vertices of each face of the cube, which is the way a simple modeling approach would work. But as we noted earlier, the cube is a regular polyhedron with four edges and 90 degree interior angles for each face, and it is possible to define the cube by 5/29/00 Page 2.11

12 defining a standard square and then using transformations to create the faces from this master square. We will see this approach later on when we work with transformations. Source codes The source codes for these examples may be found in the files points.c code that includes the drawing of a set of 10 points on a line in 3-space poly.c code that includes the drawing of a simple regular N-gon in the XZ-plane spiral.c code that includes the drawing of a spiral as 100 connected line segments These examples also include other features that make it easier to see the nature of the object that is being modeled and displayed. The main additions are a set of coordinate axes to give you an orientation in the space (Z-axis towards you, Y-axis up, X-axis to the right) and a user-controlled set of rotations based on the Q/W, A/S, and Z/X keys that will allow you to move the object (and its space) around so you can see the objects from all sides. 5/29/00 Page 2.12

13 Modeling with GLU and GLUT Prerequisites An understanding of the simple modeling with polygon primitives. Introduction Modeling with polygons alone would require you to write many standard graphics elements that are so common, any reasonable graphics system should include them. OpenGL includes the OpenGL Utility Library, GLU, with many useful functions, and most releases of OpenGL also include the OpenGL Utility Toolkit, GLUT. We saw in the first module that GLUT includes window management functions, and both GLU and GLUT include a number of built-in graphical elements that you can use. This module describes a number of these elements. Definitions The primitives that GLU provides to you are defined with some parameters that define the primitive and some that define the resolution with which the primitive is modeled. The former are elementspecific and will be described when we describe each primitive, but the latter are general and are described here. Each GLU primitive is declared as a GLUqadric and is allocated with the function GLUquadric* glunewquadric( void ) Each is a surface of revolution defined with the z-axis as the rotation axis. Each is modeled in terms of subdivisions around the z-axis, called slices, and subdivisions along the z-axis, called stacks. Figure 2.4 shows an example of a typical pre-built quadric, a GLUT wireframe sphere, modeled with a small number of slices and stacks so you can see the basis of this definition. Figure 2.4: A GLUT wireframe sphere with 10 slices and 10 stacks Below we describe the GLU primitives by listing the function prototype for each; more details may be found in the GLU section of your OpenGL manual. 5/29/00 Page 2.13

14 GLU cylinder: void glucylinder( GLUquadric* quad, GLdouble base, GLdouble top, GLdouble height, GLint slices, GLint stacks ) quad identifies the quadrics object you previously created with glunewquadric base is the radius of the cylinder at z = 0, the base of the cylinder top is the radius of the cylinder at z = height, and height is the height of the cylinder. GLU disk: The GLU disk is different from the other GLU primitives because it is two-dimensional, lying entirely within the X-Y plane. Thus instead of being defined in terms of stacks, the second granularity parameter is loops, the number of concentric rings that define the disk. void gludisk( GLUquadric* quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops ) quad identifies the quadrics object you previously created with glunewquadric inner is the inner radius of the disk (may be 0). outer isthe outer radius of the disk. GLU sphere: void glusphere( GLUquadric* quad, GLdouble radius, GLint slices, GLint stacks ) quad identifies the quadrics object you previously created with glunewquadric radius is the radius of the sphere. The GLUT primitives are more complex than the GLU primitives, including both solid and wireframe versions of many interesting solids. They include a cone, a cube, a dodecahedron (12- sided regular polyhedron), an icosahedron (20-sided regular polyhedron), an octahedron (8-sided regular polyhedron), a sphere, a teapot (the canonical Utah teapot, an icon of computer graphics), a tetrahedron (4-sided regular polyhedron), and a torus (doughnut). Each has a canonical position and orientation, typically centered at the origin and within a standard volume and, if it has an axis, the axis is aligned with the z-axis. As with the GLU standard primitives, some of the GLUT primitives allow you to specify the granularity of the primitive s modeling, but some do not; the example program will show you the differences. If you have GLUT with your OpenGL, you should check the GLUT manuals for the details. Some examples Our example for this module is quite simple, initiallly displaying a medium-quality GLU sphere and using a menu to let you select another GLU or GLUT primitive, to zoom in or out on that primitive, and to increase or decrease the quality of the modeling when that is possible. Menus are provided by the GLUT toolkit and will be discussed later in the module on event-driven programming, but the example is much more interesting if we allow you to see most of the primitives in one function. The heart of the example is the following code that responds to a menu selection to change the primitive you are displaying, change the resolution on your primitive, or to zoom in or zoom out on your primitive. This code depends on the menu, so the fundamentals of the menu definition are also shown, though this is getting somewhat ahead of ourselves. 5/29/00 Page 2.14

15 // menu functions in main() glutcreatemenu(options_menu); glutaddmenuentry("glu sphere", 1); glutaddmenuentry("glu cylinder", 2); glutaddmenuentry("glut dodecahedron", 3); glutaddmenuentry("glut torus", 4); glutaddmenuentry("glut teapot", 5); glutaddmenuentry("more detail", 6); glutaddmenuentry("less detail", 7); glutaddmenuentry("move in", 8); glutaddmenuentry("move out", 9); glutattachmenuname(glut_right_button, "Selections"); // function to be called to handle mouse inputs void options_menu(int input) { if ((input >= 1) && (input <=5 )) { selectedobject = input; else { if ( input == 6 ) resolution *= 2; // higher resolution if ( input == 7 ) // lower resolution if (resolution > 2 ) resolution = (resolution+1)/2; if ( input == 8 ) distance -= 1.0; // move in if ( input == 9 ) distance += 1.0; // move out glutpostredisplay(); // function to manage the display that responds to the menu options void display( void ) { GLUquadric *myquad; GLdouble radius = 1.0; GLint slices, stacks; GLint nsides, rings; glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glmatrixmode(gl_projection); glloadidentity(); gluperspective(60.0,1.0,1.0,30.0); glmatrixmode(gl_modelview); glloadidentity(); // eye point center of view up glulookat(distance,distance,distance,0.0,0.0,0.0,0.0,1.0,0.0); switch (selectedobject) { case (1): { myquad=glunewquadric(); slices = stacks = resolution; glusphere( myquad, radius, slices, stacks ); break; case (2): { myquad=glunewquadric(); slices = stacks = resolution; glucylinder( myquad, 1.0, 1.0, 1.0, slices, stacks ); break; 5/29/00 Page 2.15

16 case (3): { glutsoliddodecahedron(); break; case (4): { nsides = rings = resolution; glutsolidtorus( 1.0, 2.0, nsides, rings); break; case (5): { glutsolidteapot(2.0); break; glutswapbuffers(); A word to the wise... One of the differences between student programming and professional programming is that students are often asked to create applications or tools for the sake of learning creation, not for the sake of creating working, useful things. The graphics primitives that are the subject of the first section of this module are the kind of tools that students are often asked to use, because they require more analysis of fundamental geometry and are good learning tools. However, working programmers developing real applications will often find it useful to use pre-constructed templates and tools such as the GLU or GLUT graphics primitives. You are encouraged to use the GLU and GLUT primitives whenever they can save you time and effort in your work, and when you cannot use them, you are encouraged to create your own primitives in a way that will let you re-use them as your own library and will let you share them with others. Code examples * graphicsprimitivesmenu.c 5/29/00 Page 2.16

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives Geometry Primitives Sandro Spina Computer Graphics and Simulation Group Computer Science Department University of Malta 1 The Building Blocks of Geometry The objects in our virtual worlds are composed

More information

Computer graphic -- Programming with OpenGL I

Computer graphic -- Programming with OpenGL I Computer graphic -- Programming with OpenGL I A simple example using OpenGL Download the example code "basic shapes", and compile and run it Take a look at it, and hit ESC when you're done. It shows the

More information

Graphics Programming

Graphics Programming Graphics Programming 3 rd Week, 2011 OpenGL API (1) API (application programming interface) Interface between an application program and a graphics system Application Program OpenGL API Graphics Library

More information

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL Today s Agenda Basic design of a graphics system Introduction to OpenGL Image Compositing Compositing one image over another is most common choice can think of each image drawn on a transparent plastic

More information

2D Drawing Primitives

2D Drawing Primitives THE SIERPINSKI GASKET We use as a sample problem the drawing of the Sierpinski gasket an interesting shape that has a long history and is of interest in areas such as fractal geometry. The Sierpinski gasket

More information

Rendering. Part 1 An introduction to OpenGL

Rendering. Part 1 An introduction to OpenGL Rendering Part 1 An introduction to OpenGL Olivier Gourmel VORTEX Team IRIT University of Toulouse gourmel@irit.fr Image synthesis The Graphics Processing Unit (GPU): A highly parallel architecture specialized

More information

CS 4204 Computer Graphics

CS 4204 Computer Graphics CS 4204 Computer Graphics OpenGL Basics Yong Cao Virginia Tech References: 2001 Siggraph, An Interactive Introduction to OpenGL Programming, Dave Shreiner,Ed Angel, Vicki Shreiner Official Presentation

More information

Modeling with Transformations

Modeling with Transformations Modeling with Transformations Prerequisites This module requires some understanding of 3D geometry, particularly a sense of how objects can be moved around in 3-space. The student should also have some

More information

Precept 2 Aleksey Boyko February 18, 2011

Precept 2 Aleksey Boyko February 18, 2011 Precept 2 Aleksey Boyko February 18, 2011 Getting started Initialization Drawing Transformations Cameras Animation Input Keyboard Mouse Joystick? Textures Lights Programmable pipeline elements (shaders)

More information

Programming of Graphics

Programming of Graphics Peter Mileff PhD Programming of Graphics Introduction to OpenGL University of Miskolc Department of Information Technology OpenGL libraries GL (Graphics Library): Library of 2D, 3D drawing primitives and

More information

How shapes are represented in 3D Graphics. Aims and objectives By the end of the lecture you will be able to describe

How shapes are represented in 3D Graphics. Aims and objectives By the end of the lecture you will be able to describe Today s lecture Today we will learn about The mathematics of 3D space vectors How shapes are represented in 3D Graphics Modelling shapes as polygons Aims and objectives By the end of the lecture you will

More information

Introduction to Computer Graphics with OpenGL/GLUT

Introduction to Computer Graphics with OpenGL/GLUT Introduction to Computer Graphics with OpenGL/GLUT What is OpenGL? A software interface to graphics hardware Graphics rendering API (Low Level) High-quality color images composed of geometric and image

More information

Computer Graphics. OpenGL

Computer Graphics. OpenGL Computer Graphics OpenGL What is OpenGL? OpenGL (Open Graphics Library) is a library for computer graphics It consists of several procedures and functions that allow a programmer to specify the objects

More information

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++ Computer Graphics Graphics Programming August 31, 2005 Contents Our Goal in This Chapter Programming of the Sierpinski gasket How To? Programming with OpenGL and C/C++ OpenGL API (Application Programmer

More information

RECITATION - 1. Ceng477 Fall

RECITATION - 1. Ceng477 Fall RECITATION - 1 Ceng477 Fall 2007-2008 2/ 53 Agenda General rules for the course General info on the libraries GLUT OpenGL GLUI Details about GLUT Functions Probably we will not cover this part 3/ 53 General

More information

Answer Key: Three-Dimensional Cross Sections

Answer Key: Three-Dimensional Cross Sections Geometry A Unit Answer Key: Three-Dimensional Cross Sections Name Date Objectives In this lesson, you will: visualize three-dimensional objects from different perspectives be able to create a projection

More information

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling Welcome to the lectures on computer graphics. We have

More information

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University OpenGL Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University Background Software interface to graphics hardware 250+ commands Objects (models) are built from geometric primitives

More information

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3) Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1 http://www.cs.columbia.edu/~cs4160 To Do Start thinking (now) about HW 3. Milestones are due soon. Course Course 3D Graphics Pipeline 3D Graphics

More information

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Computer Graphics. Making Pictures. Computer Graphics CSC470 1 Computer Graphics Making Pictures Computer Graphics CSC470 1 Getting Started Making Pictures Graphics display: Entire screen (a); windows system (b); [both have usual screen coordinates, with y-axis y

More information

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Teacher Assistant : Tamir Grossinger   Reception hours: by  - Building 37 / office -102 Assignments: 4 programing using Teacher Assistant : Tamir Grossinger email: tamirgr@gmail.com Reception hours: by email - Building 37 / office -102 Assignments: 4 programing using C++ 1 theoretical You can find everything you need in

More information

1. CONVEX POLYGONS. Definition. A shape D in the plane is convex if every line drawn between two points in D is entirely inside D.

1. CONVEX POLYGONS. Definition. A shape D in the plane is convex if every line drawn between two points in D is entirely inside D. 1. CONVEX POLYGONS Definition. A shape D in the plane is convex if every line drawn between two points in D is entirely inside D. Convex 6 gon Another convex 6 gon Not convex Question. Why is the third

More information

CSCI 4620/8626. Coordinate Reference Frames

CSCI 4620/8626. Coordinate Reference Frames CSCI 4620/8626 Computer Graphics Graphics Output Primitives Last update: 2014-02-03 Coordinate Reference Frames To describe a picture, the world-coordinate reference frame (2D or 3D) must be selected.

More information

CS 465 Program 4: Modeller

CS 465 Program 4: Modeller CS 465 Program 4: Modeller out: 30 October 2004 due: 16 November 2004 1 Introduction In this assignment you will work on a simple 3D modelling system that uses simple primitives and curved surfaces organized

More information

Question. Why is the third shape not convex?

Question. Why is the third shape not convex? 1. CONVEX POLYGONS Definition. A shape D in the plane is convex if every line drawn between two points in D is entirely inside D. Convex 6 gon Another convex 6 gon Not convex Question. Why is the third

More information

CSC 8470 Computer Graphics. What is Computer Graphics?

CSC 8470 Computer Graphics. What is Computer Graphics? CSC 8470 Computer Graphics What is Computer Graphics? For us, it is primarily the study of how pictures can be generated using a computer. But it also includes: software tools used to make pictures hardware

More information

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II Emmanuel Agu Recall: OpenGL Skeleton void main(int argc, char** argv){ // First initialize toolkit, set display mode and create window glutinit(&argc,

More information

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CSE528 Computer Graphics: Theory, Algorithms, and Applications CSE528 Computer Graphics: Theory, Algorithms, and Applications Hong Qin State University of New York at Stony Brook (Stony Brook University) Stony Brook, New York 11794--4400 Tel: (631)632-8450; Fax: (631)632-8334

More information

Assignment 1. Simple Graphics program using OpenGL

Assignment 1. Simple Graphics program using OpenGL Assignment 1 Simple Graphics program using OpenGL In this assignment we will use basic OpenGL functions to draw some basic graphical figures. Example: Consider following program to draw a point on screen.

More information

Drawing Primitives. OpenGL basics

Drawing Primitives. OpenGL basics CSC 706 Computer Graphics / Dr. N. Gueorguieva 1 OpenGL Libraries Drawing Primitives OpenGL basics OpenGL core library OpenGL32 on Windows GL on most unix/linux systems (libgl.a) OpenGL Utility Library

More information

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013 CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013 Reading: See any standard reference on OpenGL or GLUT. Basic Drawing: In the previous lecture, we showed how to create a window in GLUT,

More information

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

GEOMETRIC OBJECTS AND TRANSFORMATIONS I Computer UNIT Graphics - 4 and Visualization 6 Hrs GEOMETRIC OBJECTS AND TRANSFORMATIONS I Scalars Points, and vectors Three-dimensional primitives Coordinate systems and frames Modelling a colored cube

More information

Planar Graphs and Surfaces. Graphs 2 1/58

Planar Graphs and Surfaces. Graphs 2 1/58 Planar Graphs and Surfaces Graphs 2 1/58 Last time we discussed the Four Color Theorem, which says that any map can be colored with at most 4 colors and not have two regions that share a border having

More information

We have set up our axioms to deal with the geometry of space but have not yet developed these ideas much. Let s redress that imbalance.

We have set up our axioms to deal with the geometry of space but have not yet developed these ideas much. Let s redress that imbalance. Solid geometry We have set up our axioms to deal with the geometry of space but have not yet developed these ideas much. Let s redress that imbalance. First, note that everything we have proven for the

More information

Computer Graphics (Basic OpenGL)

Computer Graphics (Basic OpenGL) Computer Graphics (Basic OpenGL) Thilo Kielmann Fall 2008 Vrije Universiteit, Amsterdam kielmann@cs.vu.nl http://www.cs.vu.nl/ graphics/ Computer Graphics (Basic OpenGL, Input and Interaction), ((57))

More information

The radius for a regular polygon is the same as the radius of the circumscribed circle.

The radius for a regular polygon is the same as the radius of the circumscribed circle. Perimeter and Area The perimeter and area of geometric shapes are basic properties that we need to know. The more complex a shape is, the more complex the process can be in finding its perimeter and area.

More information

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO SANTA BARBARA SANTA CRUZ EECS 104 Fundamentals of Computer Graphics OpenGL Slides courtesy of Dave Shreine, Ed Angel and Vicki Shreiner

More information

Lecture 4 of 41. Lab 1a: OpenGL Basics

Lecture 4 of 41. Lab 1a: OpenGL Basics Lab 1a: OpenGL Basics William H. Hsu Department of Computing and Information Sciences, KSU KSOL course pages: http://snipurl.com/1y5gc Course web site: http://www.kddresearch.org/courses/cis636 Instructor

More information

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI) Computer Graphics CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Recall: OpenGL Skeleton void main(int argc, char** argv){ // First initialize

More information

11.4 Three-Dimensional Figures

11.4 Three-Dimensional Figures 11. Three-Dimensional Figures Essential Question What is the relationship between the numbers of vertices V, edges E, and faces F of a polyhedron? A polyhedron is a solid that is bounded by polygons, called

More information

11/1/13. Polygon Meshes and Implicit Surfaces. Shape Representations. Polygon Models in OpenGL. Modeling Complex Shapes

11/1/13. Polygon Meshes and Implicit Surfaces. Shape Representations. Polygon Models in OpenGL. Modeling Complex Shapes CSCI 420 Computer Graphics Lecture 7 and Constructive Solid Geometry [Angel Ch. 12.1-12.3] Jernej Barbic University of Southern California Modeling Complex Shapes An equation for a sphere is possible,

More information

Computer Graphics and Visualization. Graphics Systems and Models

Computer Graphics and Visualization. Graphics Systems and Models UNIT -1 Graphics Systems and Models 1.1 Applications of computer graphics: Display Of Information Design Simulation & Animation User Interfaces 1.2 Graphics systems A Graphics system has 5 main elements:

More information

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued CS 543 - Computer Graphics: OpenGL, Continued by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Last time. OpenGL set up Basic structure OpenGL skeleton Callback functions, etc. R.W.

More information

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued CS 543 - Computer Graphics: OpenGL, Continued by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Last time. OpenGL set up Basic structure OpenGL skeleton Callback functions, etc. R.W.

More information

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction: Graphics Programming Chapter 2 Introduction: - Our approach is programming oriented. - Therefore, we are going to introduce you to a simple but informative problem: the Sierpinski Gasket - The functionality

More information

Explore Solids

Explore Solids 1212.1 Explore Solids Surface Area and Volume of Solids 12.2 Surface Area of Prisms and Cylinders 12.3 Surface Area of Pyramids and Cones 12.4 Volume of Prisms and Cylinders 12.5 Volume of Pyramids and

More information

COMP 371/4 Computer Graphics Week 1

COMP 371/4 Computer Graphics Week 1 COMP 371/4 Computer Graphics Week 1 Course Overview Introduction to Computer Graphics: Definition, History, Graphics Pipeline, and Starting Your First OpenGL Program Ack: Slides from Prof. Fevens, Concordia

More information

INSTRUCTIONS FOR THE USE OF THE SUPER RULE TM

INSTRUCTIONS FOR THE USE OF THE SUPER RULE TM INSTRUCTIONS FOR THE USE OF THE SUPER RULE TM NOTE: All images in this booklet are scale drawings only of template shapes and scales. Preparation: Your SUPER RULE TM is a valuable acquisition for classroom

More information

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science CSC 307 1.0 Graphics Programming Department of Statistics and Computer Science Graphics Programming 2 Common Uses for Computer Graphics Applications for real-time 3D graphics range from interactive games

More information

Glossary of dictionary terms in the AP geometry units

Glossary of dictionary terms in the AP geometry units Glossary of dictionary terms in the AP geometry units affine linear equation: an equation in which both sides are sums of terms that are either a number times y or a number times x or just a number [SlL2-D5]

More information

Computer Graphics. This Week. Meshes. Meshes. What is a Polygon Mesh? Meshes. Modelling Shapes with Polygon Meshes.

Computer Graphics. This Week. Meshes. Meshes. What is a Polygon Mesh? Meshes. Modelling Shapes with Polygon Meshes. 1 This Week Computer Graphics Modeling Shapes Modelling Shapes with Polygon Solid Modelling Extruded Shapes Mesh Approximations 2 What is a Polygon Mesh? A surface made up of a collection of polygon faces.

More information

Computer Graphics Course 2005

Computer Graphics Course 2005 Computer Graphics Course 2005 Introduction to GLUT, GLU and OpenGL Administrative Stuff Teaching Assistant: Rony Goldenthal Reception Hour: Wed. 18:00 19:00 Room 31 (Ross 1) Questions: E-mail: cg@cs Newsgroups:

More information

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science CSC 307 1.0 Graphics Programming Department of Statistics and Computer Science Graphics Programming OpenGL 3D Drawing 2 3D Graphics Projections Getting 3D to 2D 3D scene 2D image 3 Projections Orthographic

More information

(Section 6.2: Volumes of Solids of Revolution: Disk / Washer Methods)

(Section 6.2: Volumes of Solids of Revolution: Disk / Washer Methods) (Section 6.: Volumes of Solids of Revolution: Disk / Washer Methods) 6.. PART E: DISK METHOD vs. WASHER METHOD When using the Disk or Washer Method, we need to use toothpicks that are perpendicular to

More information

Exercise 1 Introduction to OpenGL

Exercise 1 Introduction to OpenGL Exercise 1 Introduction to OpenGL What we are going to do OpenGL Glut Small Example using OpenGl and Glut Alexandra Junghans 2 What is OpenGL? OpenGL Two Parts most widely used and supported graphics API

More information

Graphics Pipeline & APIs

Graphics Pipeline & APIs Graphics Pipeline & APIs CPU Vertex Processing Rasterization Fragment Processing glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); glpushmatrix (); gltranslatef (-0.15, -0.15, solidz); glmaterialfv(gl_front,

More information

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1 Chapter 8 Three-Dimensional Object Representations 8-1 8.1 Overview The main goal of three-dimensional computer graphics is to generate two-dimensional images of a scene or of an object based on a a description

More information

Lectures OpenGL Introduction

Lectures OpenGL Introduction Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma State University Rohnert Park, California 2004, Tom Duff and George Ledin Jr 1 What is

More information

Meshing and Geometry

Meshing and Geometry Meshing and Geometry Points in OpenGL glbegin(gl_points); glvertex2fv(p0); glvertex2fv(p1); p7 p0 p1 glvertex2fv(p2); glvertex2fv(p3); p6 p2 glvertex2fv(p4); glvertex2fv(p5); p5 p3 glvertex2fv(p6); glvertex2fv(p7);

More information

Key Concept Euler s Formula

Key Concept Euler s Formula 11-1 Space Figures and Cross Sections Objectives To recognize polyhedrons and their parts To visualize cross sections of space figures Common Core State Standards G-GMD.B.4 Identify the shapes of two-dimensional

More information

11. Quadrics in OpenGL

11. Quadrics in OpenGL 11. Quadrics in OpenGL GLU provides routines to model and render tessellated, polygonal approximations of spheres, cylinders, disks and parts of disks These quadric surfaces are described by the following

More information

GL_MODELVIEW transformation

GL_MODELVIEW transformation lecture 3 view transformations model transformations GL_MODELVIEW transformation view transformations: How do we map from world coordinates to camera/view/eye coordinates? model transformations: How do

More information

Introduction to OpenGL. CSCI 4229/5229 Computer Graphics Fall 2012

Introduction to OpenGL. CSCI 4229/5229 Computer Graphics Fall 2012 Introduction to OpenGL CSCI 4229/5229 Computer Graphics Fall 2012 OpenGL by Example Learn OpenGL by reading nehe.gamedev.net Excellent free tutorial Code available for many platforms and languages OpenGL:

More information

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3 OpenGL Introduction Introduction OpenGL OpenGL is an API for computer graphics. Hardware-independent Windowing or getting input is not included in the API Low-level Only knows about triangles (kind of,

More information

4: Polygons and pixels

4: Polygons and pixels COMP711 Computer Graphics and Image Processing 4: Polygons and pixels Toby.Howard@manchester.ac.uk 1 Introduction We ll look at Properties of polygons: convexity, winding, faces, normals Scan conversion

More information

Graphics Pipeline & APIs

Graphics Pipeline & APIs 3 2 4 Graphics Pipeline & APIs CPU Vertex Processing Rasterization Processing glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); glpushmatrix (); gltranslatef (-0.15, -0.15, solidz); glmaterialfv(gl_front,

More information

Models and Architectures

Models and Architectures Models and Architectures Objectives Learn the basic design of a graphics system Introduce graphics pipeline architecture Examine software components for an interactive graphics system 1 Image Formation

More information

Curvature Berkeley Math Circle January 08, 2013

Curvature Berkeley Math Circle January 08, 2013 Curvature Berkeley Math Circle January 08, 2013 Linda Green linda@marinmathcircle.org Parts of this handout are taken from Geometry and the Imagination by John Conway, Peter Doyle, Jane Gilman, and Bill

More information

Programming using OpenGL: A first Introduction

Programming using OpenGL: A first Introduction Programming using OpenGL: A first Introduction CMPT 361 Introduction to Computer Graphics Torsten Möller Machiraju/Zhang/Möller 1 Today Overview GL, GLU, GLUT, and GLUI First example OpenGL functions and

More information

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics. Bing-Yu Chen National Taiwan University Computer Graphics Bing-Yu Chen National Taiwan University Introduction to OpenGL General OpenGL Introduction An Example OpenGL Program Drawing with OpenGL Transformations Animation and Depth Buffering

More information

Course Number: Course Title: Geometry

Course Number: Course Title: Geometry Course Number: 1206310 Course Title: Geometry RELATED GLOSSARY TERM DEFINITIONS (89) Altitude The perpendicular distance from the top of a geometric figure to its opposite side. Angle Two rays or two line

More information

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York API Background Prof. George Wolberg Dept. of Computer Science City College of New York Objectives Graphics API history OpenGL API OpenGL function format Immediate Mode vs Retained Mode Examples The Programmer

More information

Draw the basic Geometry Objects. Hanyang University

Draw the basic Geometry Objects. Hanyang University Draw the basic Geometry Objects Hanyang University VERTEX ATTRIBUTE AND GEOMETRIC PRIMITIVES Vertex Vertex A point in 3D space, or a corner of geometric primitives such as triangles, polygons. Vertex attributes

More information

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives Programming with OpenGL Part 1: Background Early History of APIs Objectives Development of the OpenGL API OpenGL Architecture - OpenGL as a state machine Functions - Types -Formats Simple program IFIPS

More information

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers 1. How long would it take to load an 800 by 600 frame buffer with 16 bits per pixel

More information

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms Chater : Grahics Outut Primitives Primitives: functions in grahics acage that we use to describe icture element Points and straight lines are the simlest rimitives Some acages include circles, conic sections,

More information

Beaumont Middle School Design Project April May 2014 Carl Lee and Craig Schroeder

Beaumont Middle School Design Project April May 2014 Carl Lee and Craig Schroeder Beaumont Middle School Design Project April May 2014 Carl Lee and Craig Schroeder 1 2 SketchUp 1. SketchUp is free, and you can download it from the website www.sketchup.com. For some K12 use, see www.sketchup.com/3dfor/k12-education.

More information

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into 2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into the viewport of the current application window. A pixel

More information

Grade VIII. Mathematics Geometry Notes. #GrowWithGreen

Grade VIII. Mathematics Geometry Notes. #GrowWithGreen Grade VIII Mathematics Geometry Notes #GrowWithGreen Polygons can be classified according to their number of sides (or vertices). The sum of all the interior angles of an n -sided polygon is given by,

More information

Example: The following is an example of a polyhedron. Fill the blanks with the appropriate answer. Vertices:

Example: The following is an example of a polyhedron. Fill the blanks with the appropriate answer. Vertices: 11.1: Space Figures and Cross Sections Polyhedron: solid that is bounded by polygons Faces: polygons that enclose a polyhedron Edge: line segment that faces meet and form Vertex: point or corner where

More information

SHAPE AND STRUCTURE. Shape and Structure. An explanation of Mathematical terminology

SHAPE AND STRUCTURE. Shape and Structure. An explanation of Mathematical terminology Shape and Structure An explanation of Mathematical terminology 2005 1 POINT A dot Dots join to make lines LINE A line is 1 dimensional (length) A line is a series of points touching each other and extending

More information

Programming with OpenGL Part 1: Background

Programming with OpenGL Part 1: Background Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Objectives Development of the OpenGL API

More information

CMSC427 Final Practice v2 Fall 2017

CMSC427 Final Practice v2 Fall 2017 CMSC427 Final Practice v2 Fall 2017 This is to represent the flow of the final and give you an idea of relative weighting. No promises that knowing this will predict how you ll do on the final. Some questions

More information

Lecture 3. Understanding of OPenGL programming

Lecture 3. Understanding of OPenGL programming Lecture 3 Understanding of OPenGL programming What is OpenGL GL: stands for Graphic Library Software interface for rendering purposes for 2D or 3D geometric data objects. Various Pieces gl: The basic libraries.

More information

Geometry Vocabulary. acute angle-an angle measuring less than 90 degrees

Geometry Vocabulary. acute angle-an angle measuring less than 90 degrees Geometry Vocabulary acute angle-an angle measuring less than 90 degrees angle-the turn or bend between two intersecting lines, line segments, rays, or planes angle bisector-an angle bisector is a ray that

More information

Computer Graphics: Programming, Problem Solving, and Visual Communication

Computer Graphics: Programming, Problem Solving, and Visual Communication Computer Graphics: Programming, Problem Solving, and Visual Communication Dr. Steve Cunningham Computer Science Department California State University Stanislaus Turlock, CA 95382 copyright 2002, Steve

More information

Introduction to OpenGL

Introduction to OpenGL Introduction to OpenGL Banafsheh Azari http://www.uni-weimar.de/cms/medien/cg.html What You ll See Today What is OpenGL? Related Libraries OpenGL Command Syntax B. Azari http://www.uni-weimar.de/cms/medien/cg.html

More information

1. Introduction to Constructive Solid Geometry (CSG)

1. Introduction to Constructive Solid Geometry (CSG) opyright@010, YZU Optimal Design Laboratory. All rights reserved. Last updated: Yeh-Liang Hsu (010-1-10). Note: This is the course material for ME550 Geometric modeling and computer graphics, Yuan Ze University.

More information

void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend();

void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend(); CSC 706 Computer Graphics Primitives, Stippling, Fitting In OpenGL Primitives Examples: GL_POINTS GL_LINES GL_LINE_STRIP GL_POLYGON GL_LINE_LOOP GL_ TRIANGLES GL_QUAD_STRIP GL_TRIANGLE_STRIP GL_TRIANGLE_FAN

More information

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs 91.427 Computer Graphics I, Fall 2008 1 1 Objectives Refine first program Alter default values Introduce standard program structure Simple viewing 2-D

More information

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL OpenGL: Open Graphics Library Introduction to OpenGL Part II CS 351-50 Graphics API ( Application Programming Interface) Software library Layer between programmer and graphics hardware (and other software

More information

Indiana State Math Contest Geometry

Indiana State Math Contest Geometry Indiana State Math Contest 018 Geometry This test was prepared by faculty at Indiana University - Purdue University Columbus Do not open this test booklet until you have been advised to do so by the test

More information

COMPUTER GRAPHICS LAB # 3

COMPUTER GRAPHICS LAB # 3 COMPUTER GRAPHICS LAB # 3 Chapter 2: COMPUTER GRAPHICS by F.S HILLs. Initial steps in drawing figures (polygon, rectangle etc) Objective: Basic understanding of simple code in OpenGL and initial steps

More information

Homework #2 and #3 Due Friday, October 12 th and Friday, October 19 th

Homework #2 and #3 Due Friday, October 12 th and Friday, October 19 th Homework #2 and #3 Due Friday, October 12 th and Friday, October 19 th 1. a. Show that the following sequences commute: i. A rotation and a uniform scaling ii. Two rotations about the same axis iii. Two

More information

Computer Graphics. Chapter 3 Computer Graphics Software

Computer Graphics. Chapter 3 Computer Graphics Software Computer Graphics Chapter 3 Computer Graphics Software Outline Graphics Software Packages Introduction to OpenGL Example Program 2 3 Graphics Software Software packages General Programming Graphics Packages

More information

UNIT 4 GEOMETRIC OBJECTS AND TRANSFORMATIONS-1

UNIT 4 GEOMETRIC OBJECTS AND TRANSFORMATIONS-1 UNIT 4 GEOMETRIC OBJECTS AND TRANSFORMATIONS-1 1. Explain the complete procedure of converting a world object frame into camera or eye frame, using the model view matrix. (Jun2012) 10M Ans: World Space

More information

9. Three Dimensional Object Representations

9. Three Dimensional Object Representations 9. Three Dimensional Object Representations Methods: Polygon and Quadric surfaces: For simple Euclidean objects Spline surfaces and construction: For curved surfaces Procedural methods: Eg. Fractals, Particle

More information

Luiz Fernando Martha André Pereira

Luiz Fernando Martha André Pereira Computer Graphics for Engineering Numerical simulation in technical sciences Color / OpenGL Luiz Fernando Martha André Pereira Graz, Austria June 2014 To Remember Computer Graphics Data Processing Data

More information

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40) 11(40) Information Coding / Computer Graphics, ISY, LiTH OpenGL where it fits what it contains how you work with it 11(40) OpenGL The cross-platform graphics library Open = Open specification Runs everywhere

More information

Lecture 3 Advanced Computer Graphics (CS & SE )

Lecture 3 Advanced Computer Graphics (CS & SE ) Lecture 3 Advanced Computer Graphics (CS & SE 233.420) Programming with OpenGL Program Structure Primitives Attributes and States Programming in three dimensions Inputs and Interaction Working with Callbacks

More information