void TileDownloader::downloadPicture(unsigned int index)
{
	const PictureInfo& info = mPictures[index];
	
	//Downloading all tiles in parallel
	{
		boost::threadpool::pool tp(info.tiles.size());
		for (unsigned int i=0; i<info.tiles.size(); ++i)
			tp.schedule(boost::bind(&TileDownloader::downloadPictureTile, this, index, i));
	}
	//compose all tiles on the canvas
	unsigned int width  = info.width;
	unsigned int height = info.height;
	Ogre::Canvas::Context* ctx = new Ogre::Canvas::Context(width, height, false);
	for (unsigned int i=0; i<info.tiles.size(); ++i)
	{
		const TileInfo& tileInfo = info.tiles[i];
		Ogre::Image img;
		std::stringstream filename;
		filename << tileInfo.j << "_" << tileInfo.i << ".jpg";
		img.load(filename.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);		
		float x = (tileInfo.i == 0) ? 0 : 509.0f + (tileInfo.i-1)*510.0f;
		float y = (tileInfo.j == 0) ? 0 : 509.0f + (tileInfo.j-1)*510.0f;
		ctx->drawImage(img, x, y);
	}
	
	//save canvas to jpeg
	ctx->saveToFile(info.filePath);

	delete ctx;
}
Ejemplo n.º 2
0
void OgreAppLogic::updateSunCanvas()
{
	Ogre::Canvas::Context* ctx = mCanvasTextureSun->getContext();

	//ctx->globalCompositeOperation(Ogre::Canvas::DrawingOperator_DestOver);
	ctx->clearRect(0, 0, 300, 300); // clear canvas  
	ctx->fillStyle(Ogre::ColourValue::Black);
	ctx->fillRect(0, 0, 300, 300);
	ctx->fillStyle(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 0.4f));
	ctx->strokeStyle(Ogre::Canvas::ColourConverter::fromRGBA(0, 153, 255, 102));
	ctx->save();  
	ctx->translate(150, 150);  

	// Earth  
	time_t now = time(NULL);
	struct tm * timeinfo;
	timeinfo = localtime(&now);
	int sec = timeinfo->tm_sec;
	int min = timeinfo->tm_min;
	int hr = timeinfo->tm_hour;

	ctx->rotate( ((2*Ogre::Math::PI)/60)*sec);// + ((2*Math.PI)/60000)*time.getMilliseconds() );  
	ctx->translate(105,0);  
	ctx->fillRect(0,-12,50,24); // Shadow  
	ctx->drawImage(mEarth, -12.0f, -12.0f);  

	// Moon  
	ctx->save();  
	ctx->rotate( ((2*Ogre::Math::PI)/6)*sec);// + ((2*Math.PI)/6000)*time.getMilliseconds() );  
	ctx->translate(0.0f, 28.5f);  
	ctx->drawImage(mMoon, -3.5f, -3.5f);  
	ctx->restore();  

	ctx->restore();  

	ctx->beginPath();  
	ctx->arc(150, 150, 105, 0, Ogre::Math::PI*2, false); // Earth orbit  
	ctx->stroke();  

	ctx->drawImage(mSun, 0.0f, 0.0f, 300.0f, 300.0f); 

	mCanvasTextureSun->uploadTexture();
}