Пример #1
0
void getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
   if(flipX)
      img.flipAroundY();
   if(flipY)
      img.flipAroundX();
}
Пример #2
0
void getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
	img.load("terrain1.bmp", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    if (flipX)
        img.flipAroundY();
    if (flipY)
        img.flipAroundX();
}
Пример #3
0
void TerrainManager::GetTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
    img.load(mHeightMapFileName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    if (flipX)
        img.flipAroundY();
    if (flipY)
        img.flipAroundX();
}
Пример #4
0
/// FIXME
void getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
  img.load("height_map.png", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
  if (flipX)
      img.flipAroundY();
  if (flipY)
      img.flipAroundX();
}
Пример #5
0
void OgreWidget::getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
    img.load("terrain.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    qDebug() << "OgreWidget::getTerrainImage(): loaded terrain heightmap, width is" << img.getWidth();
    if(flipX)
        img.flipAroundY();
    if(flipY)
        img.flipAroundX();

}
Пример #6
0
	Vector4* SnowTerrain::getTerrainNormalData()
	{
		PixelBox* terrainNormals;

		// load from normals file
		if(mSnowConfig->terrainSettings.normalsDataFile.length() > 0)
		{
			// get terrain normal data using image
			Ogre::Image img;
			img.load(mSnowConfig->terrainSettings.normalsDataFile,  "General");
			//img.flipAroundY();
			//img.flipAroundX();

			size_t size = img.getWidth();
			assert(img.getWidth() == img.getHeight());

			if (img.getWidth() != mTerrainSize || img.getHeight() != mTerrainSize)
				img.resize(mTerrainSize, mTerrainSize);

			terrainNormals = &img.getPixelBox();

			Vector4* floats = convertNormalsToFloats(terrainNormals, true);
			//OGRE_FREE(terrainNormals->data, Ogre::MEMCATEGORY_GENERAL);
			
			// need to swap z and y vector due to different vertical axis in normal map and world space!
			for(size_t i = 0;i<mTerrainSize*mTerrainSize;i++)
			{
				Vector4 v = floats[i];
				floats[i].z = v.y;
				floats[i].y = v.z;

			}
			return floats;
		}
		else
		{
			// need to wait until terrain is loaded
			while (getTerrain()->isDerivedDataUpdateInProgress())
			{
				// we need to wait for this to finish
				OGRE_THREAD_SLEEP(50);
				Root::getSingleton().getWorkQueue()->processResponses();
			}

			// Get terrain normal data using official method
			//terrainNormals = getTerrain()->calculateNormals(Ogre::Rect(0,0,mTerrainSize,mTerrainSize),Rect(0,0,mTerrainSize,mTerrainSize));
			Ogre::Image img;
			getTerrain()->getTerrainNormalMap()->convertToImage(img);
			//img.flipAroundY();
			img.flipAroundX();
			//img.save("test_normals.bmp");
			terrainNormals = &img.getPixelBox();

			Vector4* floats = convertNormalsToFloats(terrainNormals, true);
			//OGRE_FREE(terrainNormals->data, Ogre::MEMCATEGORY_GENERAL);
			return floats;
		}


		
	}
Пример #7
0
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");
}