Web site designers - OpenGL Super Bible! Page 469 /* * ‘UpdateNormals()

OpenGL Super Bible! Page 469 /* * ‘UpdateNormals() - Update the lighting normals for the * terrain */ void UpdateNormals(void) { int x, y; /* Terrain (x,y) location */ GLfloat (*n)[3], /* Current terrain normal */ nx, ny, nz, /* Normal components */ d, /* Normal magnitude */ *height; /* Current terrain heig ht */ /* * Loop through the terrain arrays and regenerate the * lighting normals based on the terrain height. */ n = TerrainNormal[0]; height = TerrainHeight[0]; for (y = 0; y < (TERRAIN_SIZE - 1); y ++, n ++, height ++) { for (x = 0; x < (TERRAIN_SIZE - 1); x ++, n ++, height ++) { /* * Compute the cross product of the vectors above and to * the right (simplified for this special case). */ nx = height[0] - height[1]; ny = -1.0; nz = height[0] - height[TERRAIN_SIZE]; d = -sqrt(nx * nx + ny * ny + nz * nz); n[0][0] = nx / d; /* Normalize the normal vector */ n[0][1] = ny / d; n[0][2] = nz / d; }; /* * Compute the cross product of the vectors above and to * the left (simplified for this special case) for the last * column in the grid. */ nx = height[0] - height[-1]; ny = -1.0; nz = height[0] - height[TERRAIN_SIZE]; d = -sqrt(nx * nx + ny * ny + nz * nz); n[0][0] = nx / d; /* Normalize the normal vector */
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply