Program 1 Part 1 - Computer Science
Transcription
Program 1 Part 1 - Computer Science
UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2015 Programming Assignment 1 – Part 1 Introduction Although there are more sophisticated approaches to displaying three-dimensional constructions, including surfaces (some of which we will see later), in this assignment we will consider a simple way to display three-dimensional information using only two-dimensional graphics tools. There are actually two parts to this assignment. In the first part we will do the basic mapping of a three-dimensional coordinate system to two dimensions, and display a surface. In the second part, we’ll use the mapping technique of the first part but add the elimination of surface lines (that is, parts of line segments) that would be hidden by “closer” parts of the surface. A Simple Surface Display Consider a function of two variables of the form ݑ(݂ = ݓ, )ݒ. We can assume that three coordinate axes (as shown in the left figure below) can be used to plot the points corresponding to a collection of (u, v, w) values that represent a surface. We can get a feel for the shape of this surface by plotting sample points and connecting them by line segments (as shown in the right figure below). w v u To display the three-dimensional points on our two-dimensional display we make the following observations: As the value of w increases, the point moves upward. As the value of u increases, the point moves to the right. As the value of v increases, the point moves both right and up. To achieve this effect, we map the coordinate values as follows: ݑ = ݔ+ ݒ/2 ݓ = ݕ+ ݒ/2 Computer Science 4620/8626 Programming Assignment 1 Spring 2015 An Example Here is a small set of w values that will be used to illustrate this approach: u = 0.1 u = 0.2 u = 0.3 u = 0.4 u = 0.5 v = 0.1 0.10 0.10 0.13 0.15 0.20 v = 0.2 0.10 0.12 0.15 0.20 0.25 v = 0.3 0.12 0.15 0.20 0.25 0.30 v = 0.4 0.11 0.15 0.20 0.25 0.30 v = 0.5 0.08 0.11 0.15 0.18 0.20 To display the corresponding “surface” use the following steps: 1. Compute the (x, y) values obtained from mapping the (u, v, w) values, and optionally display “points” (filled pixels of a reasonable size) at the corresponding display locations. These points do not necessarily need to be displayed, although the overall effect is more pronounced if these points are displayed. The display is shown in the leftmost figure below. [A sample C source program named points.c is available on the class web page that illustrates a particularly useful technique to display points without much effort.] 2. Connect the successive elements of each row of points by line segments. The middle figure below illustrates the result of this step. 3. Finally connect the successive points in each column with line segments. This yields the final result, as shown in the rightmost figure below. Computation of the x and y values can be done once and saved in separate arrays, or the appropriate x and y values can be recomputed as necessary. We’re not overly concerned about efficiency in this program, so either approach is acceptable. And steps 2 and 3 could be reversed. That is, the “vertical” line segments could be drawn first, then the “horizontal” line segments. Input The input data – that is, the set of (u, v, w) points – will be given in a form similar to that shown in the table used in the example. The file containing the data will be a text file. The first line will contain an integer nu and two real numbers umin and umax., with a guarantee that ݊݅ ݉ݑ > ݔܽ ݉ݑThe second line will contain an integer nv and two real numbers vmin and vmax. These lines define the number and range of u and v values for the data. nu will be the number of u values. The difference between adjacent u values will be ߜ= ݑ Computer Science 4620/8626 (௨ ௫ି௨ ) (௨ିଵ) . For example, if nu is 10, umin is 0.1, and umax is 1.0, ߜ= ݑ Programming Assignment 1 Spring 2015 ଵ.ି.ଵ = (ଵିଵ) v values. 0.1. nv, vmin, and vmax are used in the same way to determine the difference between adjacent After the u and v specifications are given there will appear ݊ ݒ݊ × ݑvalues for w. The first nu values will be those for v = vmin and u = umin through umax. The next nu values will be those for ݊݅ ݉ݒ = ݒ+ ߜ ݒand u = umin through umax. There will be nu values on each input line. Thus the input file for the example data shown above would look like this: 5 0.1 0.5 5 0.1 0.5 0.10 0.10 0.13 0.10 0.12 0.15 0.12 0.15 0.20 0.11 0.15 0.20 0.08 0.11 0.15 0.15 0.20 0.25 0.25 0.18 0.20 0.25 0.30 0.30 0.20 Details For simplicity, you may assume that neither nu nor nv will be larger than 100 – that is, there will be no more than 10,000 total points specified in the input. This will allow you to use a statically-allocated 100×100 element array to hold the w values. Before invoking glutInitWindowSize or gluOrtho2D, compute the minimum and maximum x and y values that will result from mapping the (u, v, w) points to two dimensions. Then assume there will be a “border” of 5 percent on each side of the window, making the width and height of the window (in world coordinates) 10 percent larger than the difference between the maximum and minimum x and y values, respectively. Make the local window size (that is, the window size specified to the glutInitWindowSize function) congruent with the size of the clipping window (that is, the one whose coordinates were increased by 10 percent to provide a border), with the larger dimension being 500 pixels. For the data shown in the example, the local window size will be 500 pixels wide and 350 pixels high. The world coordinates (specified to gluOrtho2D) will be approximately x = 0.12 to 0.78 and y = 0.109 to 0.571. There are several sample input data cases (including the one shown above) in the file data1a.zip found on the class web page. The zip file also includes a PDF document that illustrates the expected output. Part 2 of the Program The description of the second part of the program will appear here soon. In the meantime, you should be able to complete part 1 without too much difficulty. Computer Science 4620/8626 Programming Assignment 1 Spring 2015