Presentation is loading. Please wait.

Presentation is loading. Please wait.

Project 4 Relief Map Fri, Oct 24, 2003 Due Fri, Oct 31, 2003.

Similar presentations


Presentation on theme: "Project 4 Relief Map Fri, Oct 24, 2003 Due Fri, Oct 31, 2003."— Presentation transcript:

1 Project 4 Relief Map Fri, Oct 24, 2003 Due Fri, Oct 31, 2003

2 Relief Map Read the handout.handout Download the files. ReliefMap.cpp. ReliefMap.cpp point3.h. point3.h vector3.h. vector3.h ThePriest.topo. ThePriest.topo Run ReliefMap.exe.ReliefMap.exe

3 Relief Map The primary purpose of this project is to compute normals to a mesh so that the lighting models creates the right effects. A secondary purpose is to learn how to render the mesh.

4 The Grid The grid of terrain points extends from a beginning to an ending longitude and from a beginning to an ending latitude. Each grid point is represented by three coordinates, expressed in miles. x – the distance from the west edge. y – the elevation. z – the distance from the north edge.

5 The Grid You may render the grid as a grid of rectangles.

6 The Grid Or you may render it as a grid of triangles.

7 The Topo Structure The data from the file ThePriest.topo is read into a Topo structure. typedef struct { int lngCnt; int latCnt; Point3** pt; Vector3** norm; double min; double max; } Topo;

8 The Topo Structure lngCnt (“longitude count”) is the number of grid points in an east-west direction. latCnt (“latitude count”) is the number of grid points in a north-south direction. pt is a pointer to a 2-dimensional array of Point3 objects. norm is a pointer to 2-dimensional array of Vector3 objects. min and max are the minimum and maximum elevations in the file.

9 The Project Your job is to compute the normals at the grid points and to render the surface. This will involve writing parts or all of three functions setNormals() drawTerrain() computeNormal()

10 The setNormals() Function The setNormals() function should compute a unit normal for each grid point by calling on computeNormal(). The direction of the normal should represent the general slope of the land. The normals should be stored in the Topo structure as they are computed.

11 Computing Normals To compute normals, we consider three cases. Interior grid points – 4 neighbors. Edge grid points – 3 neighbors. Corner grid points – 2 neighbors.

12 Computing Interior Normals The four neighbors are north, south, east, and west. N S E W P

13 Computing Interior Normals We may form two vectors and take their cross product. N S E W P

14 Computing Edge Normals For edge points, use a similar method, but use the grid point itself as one of the four points. P W E S

15 Computing Edge Normals For edge points, use a similar method, but use the grid point itself as one of the four points. P W E S

16 Computing Corner Normals For corner points, again use a similar idea, but based on only three points. P S E

17 Computing Corner Normals For corner points, again use a similar idea, but based on only three points. P S E

18 Newell’s Algorithm The textbook, on page 292, discusses Newell’s Algorithm for computing a normal to a (possibly) non-planar polygon. It is based on the concept of the cross product, but it is more efficient. You may use Newell’s algorithm instead of computing cross products.

19 Newell’s Algorithm for Quadrilaterals Let the vertices be (x 0, y 0, z 0 ), (x 1, y 1, z 1 ), (x 2, y 2, z 2 ), (x 3, y 3, z 3 ). Then the normal v = (v x, v y, v z ) is computed as: v x = (y 0 – y 1 )(z 0 + z 1 ) + (y 1 – y 2 )(z 1 + z 2 ) + (y 2 – y 3 )(z 2 + z 3 ) + (y 3 – y 0 )(z 3 + z 0 ). v y = (z 0 – z 1 )(x 0 + x 1 ) + (z 1 – z 2 )(x 1 + x 2 ) + (z 2 – z 3 )(x 2 + x 3 ) + (z 3 – z 0 )(x 3 + x 0 ). v z = (x 0 – x 1 )(y 0 + y 1 ) + (x 1 – x 2 )(y 1 + y 2 ) + (x 2 – x 3 )(y 2 + y 3 ) + (x 3 – x 0 )(y 3 + y 0 ).

20 Newell’s Algorithm for Triangles Let the vertices be (x 0, y 0, z 0 ), (x 1, y 1, z 1 ), (x 2, y 2, z 2 ). Then the normal v = (v x, v y, v z ) is computed as: v x = (y 0 – y 1 )(z 0 + z 1 ) + (y 1 – y 2 )(z 1 + z 2 ) + (y 2 – y 0 )(z 2 + z 0 ). v y = (z 0 – z 1 )(x 0 + x 1 ) + (z 1 – z 2 )(x 1 + x 2 ) + (z 2 – z 0 )(x 2 + x 0 ). v z = (x 0 – x 1 )(y 0 + y 1 ) + (x 1 – x 2 )(y 1 + y 2 ) + (x 2 – x 0 )(y 2 + y 0 ).

21 Quadrilaterals vs. Triangles If you use Newell’s algorithm, you may write a separate function to deal with triangles. Or you may use the function designed for quadrilaterals by repeating the first point as the fourth point. The results will be the same.

22 The drawTerrain() Function The drawTerrain() function will draw render the grid with each polygon properly colored. To draw a vertex, we must first Color the vertex. Give it a normal vector.

23 The drawTerrain() Function This uses the functions glColor*(). glNormal*(). glBegin(GL_POLYGON); glColor3f(1.0, 0.0, 0.0);// Red glNormal3f(0.0, 1.0, 0.0);// Up glVertex3f(1.0, 2.0, 3.0);// Coordinates : glEnd();

24 The setColor() Function The setColor() function is provided, but you should understand how it works. The elevation of the point is compared to each elevation that was read from the file, starting with the smallest. As soon as a higher elevation is found, the corresponding color is set. If no higher elevation is found, then the last color is set.


Download ppt "Project 4 Relief Map Fri, Oct 24, 2003 Due Fri, Oct 31, 2003."

Similar presentations


Ads by Google