void TerrainManager::terrainInit(Ogre::String file, OgreManager* o) { _OgreManager = o; initialiseResources(); createLight(); setGlobalOptions(); _TerrainGroup = OGRE_NEW Ogre::TerrainGroup(_OgreManager->getSceneManager(), Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f); _TerrainGroup->setFilenameConvention(Ogre::String("GameTerrain"), Ogre::String("dat")); _TerrainGroup->setOrigin(Ogre::Vector3::ZERO); setDefaultImportSettings(); bool lTerrainsImported = false; for (long x = 0; x <= 0; ++x) { for (long y = 0; y <= 0; ++y) { //Define terrain function Ogre::String filename = _TerrainGroup->generateFilename(x, y); if (Ogre::ResourceGroupManager::getSingleton().resourceExists(_TerrainGroup->getResourceGroup(), filename)) { _TerrainGroup->defineTerrain(x, y); } else { Ogre::Image img; //Get terrain image Ogre::String tempFile = Ogre::StringConverter::toString(x * 10 + y); tempFile.append(".bmp"); img.load("terrain.bmp", Ogre::String("TerrainResources")); if (x % 2 != 0) img.flipAroundY(); if (y % 2 != 0) img.flipAroundX(); //Get terrain image end _TerrainGroup->defineTerrain(x, y, &img); lTerrainsImported = true; } //Define terrain function end } } _TerrainGroup->loadAllTerrains(true); if (lTerrainsImported) { Ogre::TerrainGroup::TerrainIterator ti = _TerrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; //Init blend maps function start Ogre::TerrainLayerBlendMap* blendMap0 = t->getLayerBlendMap(1); Ogre::TerrainLayerBlendMap* blendMap1 = t->getLayerBlendMap(2); Ogre::Real minHeight0 = -10; Ogre::Real fadeDist0 = 0;//40; Ogre::Real minHeight1 = -10; Ogre::Real fadeDist1 = 0;//15; float* pBlend0 = blendMap0->getBlendPointer(); float* pBlend1 = blendMap1->getBlendPointer(); for (Ogre::uint16 y = 0; y < t->getLayerBlendMapSize(); ++y) { for (Ogre::uint16 x = 0; x < t->getLayerBlendMapSize(); ++x) { Ogre::Real tx, ty; blendMap0->convertImageToTerrainSpace(x, y, &tx, &ty); Ogre::Real height = t->getHeightAtTerrainPosition(tx, ty); Ogre::Real val = (height - minHeight0) / fadeDist0; val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1); *pBlend0++ = val; val = (height - minHeight1) / fadeDist1; val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1); *pBlend1++ = val; } } blendMap0->dirty(); blendMap1->dirty(); blendMap0->update(); blendMap1->update(); //Init blend maps end } } _TerrainGroup->freeTemporaryResources(); _OgreManager->getSceneManager()->setSkyBox(true, "Examples/EarlyMorningSkyBox", 5000, true, Ogre::Quaternion::IDENTITY, "GameResources"); }
float terrain_get_height_at_terrain_position(CoiHandle terrain_handle, float x, float y) { Ogre::Terrain* terrain = reinterpret_cast<Ogre::Terrain*>(terrain_handle); return terrain->getHeightAtTerrainPosition(x, y); }