Geocities web hosting - Page 450 OpenGL Super Bible! /* * Set
Page 450 OpenGL Super Bible! /* * Set the height of the terrain ‘cell . For water, the * height is constant at WATER_HEIGHT. Other other types, * we add a random pertubation to make the terrain more * interesting/realistic. */ switch (TerrainCurrent) { case IDC_WATER : TerrainHeight[y][x] = WATER_HEIGHT; break; case IDC_GRASS : TerrainHeight[y][x] = GRASS_HEIGHT + 0.1 * (rand() % 5); break; case IDC_TREES : TerrainHeight[y][x] = TREES_HEIGHT + 0.1 * (rand() % 5); break; case IDC_ROCKS : TerrainHeight[y][x] = ROCKS_HEIGHT + 0.1 * (rand() % 5); break; case IDC_MOUNTAINS : TerrainHeight[y][x] = MOUNTAINS_HEIGHT + 0.15 * (rand() % 5); break; }; } For the IDC_WATER terrain type, the point height is just set to WATER_HEIGHT (0.0). For other types, we add a small amount of random jitter to make the terrain look more realistic. Once the selected cell is drawn, we recompute the lighting normals using the new height values in UpdateNormals. Each lighting normal is calculated using the points above and to the right of the current point with the following formula: N = lighting normal H = height of current point Hu = height of point above Hr = height of point to the right Nx = (Hr - H) / |N| Ny = 1 / |N| Nz = (Hu - H) / |N| This is just a simplification of the cross product of adjacent terrain grid- cells. Once all the normals are recalculated, the scene is redrawn. Drawing the Scene Now that we ve taken care of the drudge work, we can concentrate on displaying the terrain. You ll remember that besides displaying a pretty textured image, we also want to fly through this terrain. To accomplish this, we need to draw the terrain without textures
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.