OpenGL Super Bible! Page 471 * Range check (Web hosting unlimited bandwidth)
OpenGL Super Bible! Page 471 * Range check the terrain location */ if (x < 0 || x >= TERRAIN_SIZE || y < 0 || y >= TERRAIN_SIZE) return; if (TerrainType[y][x] == TerrainCurrent) return; /* Already the right type */ TerrainType[y][x] = TerrainCurrent; /* * Force a redraw */ InvalidateRect(SceneWindow, NULL, TRUE); /* * Set the height of the terrain ‘cell . For water, the * height is constant at WATER_HEIGHT. For 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; }; } /* * ‘DrawTerrain() - Draw a terrain cell at the given mouse * position. */ void DrawTerrain(int mousex, /* I - Horizontal mouse position */ int mousey) /* I - Vertical mouse position */ { int i, /* Looping var */
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.