Computer Graphics And Sphere .Docx Geometric 3D Objects Box Babylon University College of Info. Tech. Software Dep. 3d Class Ass. Lecturer. Wadhah R. Baiee Geometric 3D Objects THREE-DIMENSIONAL PRIMITIVES In a three-dimensional world, we can have a far greater variety of geometric objects than we can in two dimensions. When we worked in a two-dimensional plane in Chapter 2, we considered objects that were simple curves, such as line segments, and flat objects with well-defined interiors, such as simple polygons. In three dimensions, we retain these objects, but they are no longer restricted to lie in the same plane. Hence, curves become curves in space (Figure 4.18), and objects with interiors can become surfaces in space (Figure 4.19). In addition, we can have objects with volumes, such as parallelepipeds and ellipsoids (Figure 4.20). Three features characterize three-dimensional objects that fit well with existing graphics hardware and software: 1. The objects are described by their surfaces and can be thought of as being hollow. 2. The objects can be specified through a set of vertices in three dimensions. 3. The objects either are composed of or can be approximated by flat, convex polygons. 1 Computer Graphics And Sphere .Docx Geometric 3D Objects Box The first condition implies that we need only two-dimensional primitives to model three-dimensional objects because a surface is a two- rather than a three dimensional entity. The second condition is an extension of our observations in Chapters 1 and 2 of your textbox. If an object is defined by vertices, we can use a pipeline architecture to process these vertices at high rates, and we can use the hardware to generate the images of the objects only during rasterization. The final condition is an extension from our discussion of two-dimensional polygons. Most graphics systems are optimized for the processing of points and polygons. In three dimensions, a polygon can be defined by an ordered list of vertices. However, if there are more than three vertices, they do not have to lie in the same plane; if they do not, there is no simple way to define the interior of the object . MODELING A COLORED CUBE We now have most of the basic conceptual and practical knowledge we need to build three - dimensional graphical applications. We will use them to produce a program that draws a rotating cube. One frame of an animation might be as shown in Figure 4.28. However, before we can rotate the cube, we will consider how we can model it efficiently. Modeling the Faces The cube is as simple a three-dimensional object as we might expect to model and display. There are a number of ways, however, to model it. A CSG system would regard it as a single primitive. At the other extreme, the hardware processes the cube as an object defined by eight vertices. Our decision to use surface-based models implies that we regard a cube either as the intersection of six planes or as the six polygons, called facets, that define its faces. A 2 Computer Graphics And Sphere .Docx Geometric 3D Objects Box carefully designed data structure should support both the high-level application view of the cube and the low-level view needed for the implementation. We start by assuming that the vertices of the cube are available through an array of vertices; for example, we could use the following: float vertices[8] [3] = {{-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}}; We can then use the list of points to specify the faces of the cube. For example, one face is glBegin(GL_P0LYG0N); glVertex3fv(vertices[0]); glVertex3fv(vertices[3]); glVertex3fv(vertices[2]); glVertex3fv(vertices [1]); glEndO; And we can define the other five faces similarly. Data Structures for Object Representation We could now describe our cube through a set of vertex specifications. For example, we could use glBegin(GL_P0LYG0N) six times, each time followed by four vertices (via glVertex) and a glEnd, or we could use glBegin(GL_QUADS) followed by 24 vertices and a glEnd. Both of these methods work, but they both fail to capture the essence of the cube's topology, as opposed to the cube's geometry. If we think of the cube as a polyhedron, we have an object—the cube—that is composed of six faces. The faces are each quadrilaterals that meet at vertices; each vertex is shared by three faces. In addition, pairs of vertices define edges of the quadrilaterals; each edge is shared by two faces. The data specifying the location of the vertices contain the geometry and can be stored as a simple list or array, such as in ver t ices [8]—the vertex list. The toplevel entity is a cube; we regard it as being composed of six faces. Each 3 Computer Graphics And Sphere .Docx Geometric 3D Objects Box face consists of four ordered vertices. Each vertex can be specified indirectly through its index. This data structure is shown in Figure 4.30. One of the advantages of this structure is that each geometric location appears only once, instead of being repeated each time it is used for a facet. If, in an interactive application, the location of a vertex is changed, the application needs to change that location only once, rather than searching for multiple occurrences of the vertex. The Color Cube We can use the vertex list to define a color cube. We assign the colors of the vertices of the color solid of Chapter 2' (black, white, red, green, blue, cyan, magenta, yellow) to the vertices. We define a function quad to draw quadrilateral polygons specified by pointers into the vertex list. We assign a color for the face using the index of the first vertex. Finally, the colorcube specifies the six faces, taking care to make them all outward-facing as follows: 4 Computer Graphics And Sphere .Docx Geometric 3D Objects Box Sphere In Cartesian coordinates, a spherical surface with radius r centered on the coordinate origin is defined as the set of points (x, y, z) that satisfy the equation. 5 Computer Graphics And Sphere .Docx Geometric 3D Objects Box We can also describe the spherical surface in parametric form, using latitude and longitude angles , We can describe it by the following three equations: The parametric representation in Equations above provides a symmetric range for the angular parameters and . Alternatively, we could write the parametric equations using standard spherical coordinates, where angle is specified as the colatitude. Then, . is defined over the range 0 < < π, and is often taken in the range 0 < < 2π . Fans and strips allow us to approximate many curved surfaces simply. For example, one way to construct an approximation to a sphere is to use a set of polygons defined by lines of longitude and latitude as shown in Figure of sphere . 6 Computer Graphics And Sphere .Docx Geometric 3D Objects Box We can do so very efficiently using either quad strips or triangle strips. If we fix and draw curves as we change , we get circles of constant longitude. By generating points at fixed increments of and , we can define quadrilaterals as shown in Figure of sphere. Remembering that we must convert degrees to radians for the standard trigonometric functions, the code for the quadrilaterals corresponding to increments of 20 degrees in and to 20 degrees in is 7 Computer Graphics And Sphere .Docx 8 Geometric 3D Objects Box Computer Graphics And Sphere .Docx 9 Geometric 3D Objects Box