41STerrain::STerrain(
SScene* parent,
const std::string& resName) :
SData(resName)
45 mGlobals = OGRE_NEW Ogre::TerrainGlobalOptions();
48 mResourceGroup = SO3_INTERNAL_RESOURCE_GROUP + std::string(
"/TERRAIN/") + std::string(resName);
49 Ogre::ResourceGroupManager::getSingletonPtr()->createResourceGroup(
mResourceGroup);
51 mGlobals->setCompositeMapDistance(2000);
53 mGlobals->setCompositeMapDiffuse(Ogre::ColourValue(1.0f, 1.0f, 1.0f, 1.0f));
55 mGlobals->setCastsDynamicShadows(
true);
56 Ogre::TerrainMaterialGenerator::Profile* matProfile =
mGlobals->getDefaultMaterialGenerator()->getActiveProfile();
86bool STerrain::DefineHeightMap(std::string heightmap, Ogre::Real worldSize, Ogre::Real scale, Ogre::uint16 minBatchsize, Ogre::uint16 maxBatchsize)
94 catch(Ogre::Exception &)
100 Ogre::Terrain::ImportData imp;
101 imp.inputImage = &img;
102 imp.terrainSize = img.getWidth();
103 imp.worldSize = worldSize;
104 imp.inputScale = scale;
105 imp.minBatchSize = minBatchsize;
106 imp.maxBatchSize = maxBatchsize;
111 if (!(Ogre::Bitwise::isPO2(imp.terrainSize - 1) && Ogre::Bitwise::isPO2(imp.minBatchSize - 1) && Ogre::Bitwise::isPO2(imp.maxBatchSize - 1)))
115 imp.layerList.resize(3);
116 imp.layerList[0].worldSize = 10;
117 imp.layerList[0].textureNames.push_back(
"terraindef/grass_green-01_diffusespecular.dds");
118 imp.layerList[0].textureNames.push_back(
"terraindef/grass_green-01_normalheight.dds");
119 imp.layerList[1].worldSize = 20;
120 imp.layerList[1].textureNames.push_back(
"terraindef/growth_weirdfungus-03_diffusespecular.dds");
121 imp.layerList[1].textureNames.push_back(
"terraindef/growth_weirdfungus-03_normalheight.dds");
122 imp.layerList[2].worldSize = 100;
123 imp.layerList[2].textureNames.push_back(
"terraindef/dirt_grayrocky_diffusespecular.dds");
124 imp.layerList[2].textureNames.push_back(
"terraindef/dirt_grayrocky_normalheight.dds");
131 catch(Ogre::Exception &)
137 Ogre::TerrainLayerBlendMap* blendMap0 =
mTerrain->getLayerBlendMap(1);
138 Ogre::TerrainLayerBlendMap* blendMap1 =
mTerrain->getLayerBlendMap(2);
139 Ogre::Real minHeight0 = 30;
140 Ogre::Real fadeDist0 = 20;
141 Ogre::Real minHeight1 = 25;
142 Ogre::Real fadeDist1 = 5;
143 float* pBlend0 = blendMap0->getBlendPointer();
144 float* pBlend1 = blendMap1->getBlendPointer();
145 for (Ogre::uint16 y = 0; y <
mTerrain->getLayerBlendMapSize(); ++y)
147 for (Ogre::uint16 x = 0; x <
mTerrain->getLayerBlendMapSize(); ++x)
151 blendMap0->convertImageToTerrainSpace(x, y, &tx, &ty);
152 Ogre::Real height =
mTerrain->getHeightAtTerrainPosition(tx, ty);
153 Ogre::Real val = (height - minHeight0) / fadeDist0;
154 val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);
157 val = (height - minHeight1) / fadeDist1;
158 val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);