bool keyPressed( const OIS::KeyEvent &e )
  {
#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS
    switch( e.key )
    {
      case OIS::KC_S:
        // CTRL-S to save
        if( mInputContext.isKeyDown( OIS::KC_LCONTROL ) || mInputContext.isKeyDown( OIS::KC_RCONTROL ) )
        {
          saveTerrains( true );
        }
        else
          return SdkSample::keyPressed( e );
        break;
      case OIS::KC_F10:
        // dump
      {
        TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
        while( ti.hasMoreElements() )
        {
          Ogre::uint32 tkey = ti.peekNextKey();
          TerrainGroup::TerrainSlot* ts = ti.getNext();
          if( ts->instance && ts->instance->isLoaded() )
          {
            ts->instance->_dumpTextures( "terrain_" + StringConverter::toString( tkey ), ".png" );
          }
        }
      }
      break;
      /*
    case OIS::KC_F7:
      // change terrain size
      if (mTerrainGroup->getTerrainSize() == 513)
        mTerrainGroup->setTerrainSize(1025);
      else
        mTerrainGroup->setTerrainSize(513);
      break;
    case OIS::KC_F8:
      // change terrain world size
      if (mTerrainGroup->getTerrainWorldSize() == TERRAIN_WORLD_SIZE)
        mTerrainGroup->setTerrainWorldSize(TERRAIN_WORLD_SIZE * 2);
      else
        mTerrainGroup->setTerrainWorldSize(TERRAIN_WORLD_SIZE);
      break;
      */
      default:
        return SdkSample::keyPressed( e );
    }
#endif
    return true;
  }
	void SnowTerrain::dumpTextures()
	{
		if(!mTerrainGroup) return;

		TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
		while (ti.hasMoreElements())
		{
			Ogre::uint32 tkey = ti.peekNextKey();
			TerrainGroup::TerrainSlot* ts = ti.getNext();
			if (ts->instance && ts->instance->isLoaded())
			{
				ts->instance->_dumpTextures("terrain_" + StringConverter::toString(tkey), ".png");
			}
		}
	}
	Terrain* SnowTerrain::getTerrain()
	{
		if(!mTerrainGroup) return NULL;

		Terrain *t =  mTerrainGroup->getTerrain(0,0);
		return t;

		TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
		while (ti.hasMoreElements())
		{
			Ogre::uint32 tkey = ti.peekNextKey();
			TerrainGroup::TerrainSlot* ts = ti.getNext();
			if (ts->instance && ts->instance->isLoaded())
			{

				float* heights = ts->instance->getHeightData();

				//PixelBox* pBox = ts->instance->calculateNormals());
				TexturePtr texturePtr = ts->instance->getTerrainNormalMap();
				HardwarePixelBufferSharedPtr buf = texturePtr->getBuffer();

				size_t bytes = buf->getSizeInBytes();
				size_t h = buf->getHeight();
				size_t w = buf->getWidth();
				size_t d = buf->getDepth();
				PixelFormat f = PF_BYTE_RGB;//buf->getFormat();


				uint8* tmpData = (uint8*)OGRE_MALLOC(w * h * 3, MEMCATEGORY_GENERAL);
				memset(tmpData,0,w*h*3);
				PixelBox pBox(w, h, d, f, tmpData);
				buf->blitToMemory(pBox);
				OGRE_FREE(tmpData, MEMCATEGORY_GENERAL);
				
			}
		}
		return NULL;
	}