Project 4 - PowerPoint PPT Presentation

About This Presentation
Title:

Project 4

Description:

... 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. ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 25
Provided by: peopl93
Learn more at: https://people.hsc.edu
Category:

less

Transcript and Presenter's Notes

Title: Project 4


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

2
Relief Map
  • Read the handout.
  • Download the files.
  • ReliefMap.cpp.
  • point3.h.
  • vector3.h.
  • ThePriest.topo.
  • Run 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.

13
Computing Interior Normals
  • We may form two vectors and take their cross
    product.

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

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

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

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

18
Newells Algorithm
  • The textbook, on page 292, discusses Newells
    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 Newells algorithm instead of
    computing cross products.

19
Newells Algorithm for Quadrilaterals
  • Let the vertices be (x0, y0, z0), (x1, y1, z1),
    (x2, y2, z2), (x3, y3, z3).
  • Then the normal v (vx, vy, vz) is computed as
  • vx (y0 y1)(z0 z1) (y1 y2)(z1 z2)
  • (y2 y3)(z2 z3) (y3 y0)(z3 z0).
  • vy (z0 z1)(x0 x1) (z1 z2)(x1 x2)
  • (z2 z3)(x2 x3) (z3 z0)(x3 x0).
  • vz (x0 x1)(y0 y1) (x1 x2)(y1 y2)
  • (x2 x3)(y2 y3) (x3 x0)(y3 y0).

20
Newells Algorithm for Triangles
  • Let the vertices be (x0, y0, z0), (x1, y1, z1),
    (x2, y2, z2).
  • Then the normal v (vx, vy, vz) is computed as
  • vx (y0 y1)(z0 z1) (y1 y2)(z1 z2)
  • (y2 y0)(z2 z0).
  • vy (z0 z1)(x0 x1) (z1 z2)(x1 x2)
  • (z2 z0)(x2 x0).
  • vz (x0 x1)(y0 y1) (x1 x2)(y1 y2)
  • (x2 x0)(y2 y0).

21
Quadrilaterals vs. Triangles
  • If you use Newells 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.
Write a Comment
User Comments (0)
About PowerShow.com