Ejemplo n.º 1
0
void klsMiniMap::update(GLPoint2f origin, GLPoint2f endpoint) {
	//wxClientDC dc(this);
	//dc.FloodFill(0, 0, *wxWHITE);
	this->origin = origin;
	this->endpoint = endpoint;
	
	generateImage();
	
	//*****************************
	//Edit by Joshua Lansford 4/9/07
	//In search of determineing the
	//cause of the miniMap spazz bug
	//I refactored update and
	//OnPaint.
	//Instead of update doing both
	//jobs, I now have OnPaint
	//handling the painting
	//and update handling the update-
	//ing.  It didn't seem right
	//for the update to be grabbing
	//the hardware and rendering
	//to it when we were not servicing
	//a onPaint request.
	//***************************
	
	
	//wxBitmap mapBitmap(mapImage);
	//dc.DrawBitmap(mapBitmap, 0, 0, true);
	Refresh( false );
	//Update makes it so that we don't lag
	//when the user is moveing the cavase around
	wxWindow::Update();
}
Ejemplo n.º 2
0
Archivo: main.cpp Proyecto: t3kt/bkb
static void generateImages(const ofxOBJGroup& group, int& i) {
  ofLogVerbose() << "writing group images: " << group.name;
  for (const auto& face : group.faces) {
    generateImage(face, i);
    i++;
  }
}
Ejemplo n.º 3
0
/**
 * @class cs::Background
 */
Background::Background(const cs::Settings &s, const glm::ivec2 &window_size)
		: mSettings(s)
		, mWorkerWindowSize(window_size)
		, mWorkerColor(s.mBackgroundColor) {
	// Setup
	mHasWorkerSurface = false;

	// Create the mesh
	const glm::vec2			tc_ul(0.0f, 0.0f),
							tc_ur(1.0f, 0.0f),
							tc_lr(1.0f, 1.0f),
							tc_ll(0.0f, 1.0f);
	const float				fw = static_cast<float>(window_size.x),
							fh = static_cast<float>(window_size.y);
	ci::gl::VboMeshRef		mesh = ci::gl::VboMesh::create(ci::geom::Rect(ci::Rectf(0, 0, fw, fh)).texCoords(tc_ul, tc_ur, tc_lr, tc_ll));
	if (!mesh) throw std::runtime_error("Background vbo can't create vbo mesh");

	// Create shader
	auto					shader = ci::gl::getStockShader(ci::gl::ShaderDef().texture());
	if (!shader) throw std::runtime_error("Background vbo can't create shader");
	
	// Create batch
	mBatch = ci::gl::Batch::create(mesh, shader);
	if (!mBatch) throw std::runtime_error("Background vbo can't create batch");

	// Generate background
	mThread = std::thread([this](){generateImage();});
}
Ejemplo n.º 4
0
void MainWindow::on_actionGenerate_triggered()
{
    QSettings settings;
    auto path = QFileDialog::getSaveFileName(this, tr("Generate disk image"), settings.value(cSettingsGenerateFileDirectory).toString(), tr("Disk Image (*.img)"));
    if (!path.isEmpty()) {
        generateImage(path);
    }
}
Ejemplo n.º 5
0
void GameWidget::loadGraphism(QString repertoire)
{
	int size;

	if (repertoire == tr("Classique")) // Si graphisme par défaut
		repertoire = ":/ressources/widget/";
	else
		repertoire = QString("graphismes")+QString(QDir::separator())+repertoire+QString(QDir::separator());

	if (!avalanche.load(repertoire+"avalanche.png"))
		std::cout << "Error chargement de avalanche" << std::endl;
	if (!neige.load(repertoire+"neige.png"))
		std::cout << "Error chargement de neige" << std::endl;
	if (!tuxfisher_vivant.load(repertoire+"tuxfisher_vivant.png"))
		std::cout << "Error chargement de TuxFisher :P" << std::endl;
	if (!tuxfisher_gagne.load(repertoire+"tuxfisher_gagne.png"))
		std::cout << "Error chargement de TuxFisher :P" << std::endl;
	if (!tuxfisher_mort.load(repertoire+"tuxfisher_mort.png"))
		std::cout << "Error chargement de TuxFisher :P" << std::endl;
	if (!fish.load(repertoire+"fish.png"))
		std::cout << "Error chargement de fish" << std::endl;
	if (!montagne.load(repertoire+"montagne.png"))
		std::cout << "Error chargement de montagne" << std::endl;
	if (!vide.load(repertoire+"vide.png"))
		std::cout << "Error chargement de vide" << std::endl;

	// Redimensionne correctement les cases (pour les différentes résolutions d'écrans)
	if (QApplication::desktop()->width()>1024 && QApplication::desktop()->height()>768) // ]1024*768;infini[
		size=32;
	else if (QApplication::desktop()->width()>800 && QApplication::desktop()->height()>600) // ]800*600;1024*768]
		size=30;
	else if (QApplication::desktop()->width()>600 && QApplication::desktop()->height()>480) // ]600*480;800*600]
		size=22;
	else
		size=16;
	
	avalanche=avalanche.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	neige=neige.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	tuxfisher_vivant=tuxfisher_vivant.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	tuxfisher_gagne=tuxfisher_gagne.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	tuxfisher_mort=tuxfisher_mort.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	fish=fish.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	montagne=montagne.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	vide=vide.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);


	if (moteur->gameOver())
		tuxfisher = tuxfisher_mort;
	else
		tuxfisher = tuxfisher_vivant;

	case_width=avalanche.width();
	case_height=avalanche.height();
	// La size des cases peut avoir set
	if (!afficher_accueil)
		bufferimage = QImage(QSize(nbcase_width*case_width,nbcase_height*case_height),QImage::Format_ARGB32); // Nouvelle size du buffer
	generateImage(true);
}
Ejemplo n.º 6
0
void ModuleView::updateWidget(QWidget& widget)
{
  {
    SYNC_WITH(console);
    if(lastModulInfoTimeStamp == console.moduleInfo.timeStamp)
      return;
  }
  generateImage();
  ((ModuleWidget*)(&widget))->image = image;
  widget.update();
}
Ejemplo n.º 7
0
QMimeData* PictureBase::dragObject(QWidget * dragSource, const char * name)
{
    Q_UNUSED(dragSource);
    QImage image(generateImage(getOriginalSize()));
    if (image.isNull())
        return 0;
    else {
        QMimeData* mimeData = new QMimeData();
        mimeData->setImageData(image);
        mimeData->setObjectName(name);
        return mimeData; // XXX: Qt3 use dragsource here?
    }
}
Ejemplo n.º 8
0
void Plot2D::exportImageToFile(int w, int h)
{
  QString filename = QFileDialog::getSaveFileName(this,
    tr("Export Image"), // caption
    ".",        // folder
    tr(  "JPEG (*.jpeg)\n" // filters
    "PNG (*.png)\n"
    "Bitmap (*.bmp)\n"));
  if (!filename.isEmpty())
  {
    generateImage(toPath(filename), w, h);
  }
}
Ejemplo n.º 9
0
bool GameWidget::loadMap(int x, int y, QByteArray datasmap)
{
	tuxfisher = tuxfisher_vivant;
	if (datasmap.size()!=x*y)
		return false;
	
	afficher_accueil=false;
	nbcase_width=x;
	nbcase_height=y;
	bufferimage = QImage(QSize(nbcase_width*case_width,nbcase_height*case_height),QImage::Format_ARGB32);
	moteur->loadMap(nbcase_width, nbcase_height, datasmap.data());
	generateImage(true);
	return true;
}
Ejemplo n.º 10
0
video::IImage* TextureSource::generateImageFromScratch(std::string name)
{
	/*infostream<<"generateImageFromScratch(): "
			"\""<<name<<"\""<<std::endl;*/

	video::IVideoDriver *driver = m_device->getVideoDriver();
	assert(driver);

	/*
		Get the base image
	*/

	video::IImage *baseimg = NULL;

	char separator = '^';

	// Find last meta separator in name
	s32 last_separator_position = name.find_last_of(separator);

	/*
		If separator was found, construct the base name and make the
		base image using a recursive call
	*/
	std::string base_image_name;
	if(last_separator_position != -1)
	{
		// Construct base name
		base_image_name = name.substr(0, last_separator_position);
		baseimg = generateImageFromScratch(base_image_name);
	}

	/*
		Parse out the last part of the name of the image and act
		according to it
	*/

	std::string last_part_of_name = name.substr(last_separator_position+1);

	// Generate image according to part of name
	if(!generateImage(last_part_of_name, baseimg))
	{
		errorstream<<"generateImageFromScratch(): "
				"failed to generate \""<<last_part_of_name<<"\""
				<<std::endl;
		return NULL;
	}

	return baseimg;
}
Ejemplo n.º 11
0
GameWidget::GameWidget(QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent) // QWidget(parent) //
{
	moteur = new GameEngine();
	audio = SoundManager::getInstance();
	son_montagne = son_avalanche = son_mort = son_fish = son_victoire = 0;
	setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
	animation_en_cours=false;
	avalancheTombant=false;
	afficher_accueil=true;
	timer_animation = new QTimer(this);
	connect(timer_animation, SIGNAL(timeout()), this, SLOT(animation()));
	generateImage();
	setFocus();
}
Ejemplo n.º 12
0
void GameWidget::animation()
{
	bool tuxfisher_deja_mort=moteur->gameOver();

	animation_en_cours=true;

	if(avalancheTombant)
	{
		if(moteur->dropAvalanche())
			generateImage();
		else
		{
			if (moteur->gameOver()  && !tuxfisher_deja_mort)
			{
				tuxfisher = tuxfisher_mort;
				audio->playSound(son_mort, false);
				generateImage(true);
			}
			avalancheTombant=false;
			audio->playSound(son_avalanche, true);
		}
		return;
	}

	if(moteur->fallingAvalanche())
		avalancheTombant=true;
	else
	{
		// Animation terminée
		avalancheTombant=false;
		animation_en_cours=false;
		timer_animation->stop();
		if (moteur->gameOver()) // On signale le gameover si tuxfisher est mort et que l'animation est terminée
			emit gameOver();
	}
}
Ejemplo n.º 13
0
void PdfImageGenerator::startGeneration(void) {
    int page;
    QRectF highlight;
    QImage img;
    QPair<int,QRectF> demand;

    while (!this->requestedPages.isEmpty()) {
        demand    = requestedPages.takeLast();
        page      = demand.first;
        highlight = demand.second;
        img       = generateImage(page);

        if (!img.isNull()) {
            /* image size estimation */
            if (this->passes < this->minpasses) {
                ++passes;
                avgw += img.width();
                avgh += img.height();
            }

            /* search result highlight
             * cuts out the highlighted word and darkens the rest of the page */
            if (highlight.isValid()) {
                QRect highlightRect = scaleHighlightRect(highlight);
                highlightRect.adjust(-2, -2, 2, 2);
                QImage hImage = img.copy(highlightRect);
                QPainter painter;

                painter.begin(&img);
                painter.fillRect(img.rect(), QColor(0, 0, 0, 32));
                painter.drawImage(highlightRect, hImage);
                painter.end();
            }

            emit imageFinished(img, page);
        }
    }

    if (this->passes == minpasses) {
        pageSize.setWidth((int)(avgw/passes));
        pageSize.setHeight((int)(avgh/passes));
        ++passes;
        emit newPageSize(pageSize);
    }

    emit generationFinished();
}
Ejemplo n.º 14
0
void PowerDevilRunner::addMatch(PowerDevilRunner::PowerDevilAction action, Sprinter::MatchData &matchData)
{
    Sprinter::QueryMatch match;

    switch (action) {
    case DimTotalAction:
        match.setText(i18n("Dim screen completely"));
        break;

    case DimHalfAction:
        match.setText(i18n("Dim screen halfway"));
        break;

    case DimNotAction:
        match.setText(i18n("Make screen bright"));
        break;

    case SuspendAction:
        match.setText(i18n("Suspend to RAM"));
        break;

    case HibernateAction:
        match.setText(i18n("Suspend to Disk"));
        break;

    case ChangeBrightnessAction:
        Q_ASSERT_X(false, "PowerDevilRunner::addMatch", "Please use PowerDevilRunner::addBrightnessMatch");
        return;

    default:
        Q_ASSERT_X(false, "PowerDevilRunner::addMatch", "PowerDevilAction type does not exist");
        return;
    }

    match.setType(Sprinter::QuerySession::HardwareType);
    match.setSource(Sprinter::QuerySession::FromLocalService);
    match.setPrecision(Sprinter::QuerySession::ExactMatch);
    match.setImage(generateImage(m_actionIcons.value(action), matchData.queryContext()));

    QStringList data;
    data.append(QLatin1String("PowerDevilAction"));
    data.append(QString::number((int)action));
    match.setData(data.join(ParameterSeperator));

    matchData << match;
}
Ejemplo n.º 15
0
void PowerDevilRunner::addBrightnessMatch(int brightness, Sprinter::MatchData &matchData)
{
    brightness = qBound(0, brightness, 100);

    Sprinter::QueryMatch match;
    match.setType(Sprinter::QuerySession::HardwareType);
    match.setSource(Sprinter::QuerySession::FromLocalService);
    match.setImage(generateImage(m_actionIcons.value(ChangeBrightnessAction), matchData.queryContext()));
    match.setText(i18n("Set Brightness to %1", brightness));
    match.setPrecision(Sprinter::QuerySession::ExactMatch);

    QStringList data;
    data.append(QLatin1String("PowerDevilAction"));
    data.append(QString::number((int)ChangeBrightnessAction));
    data.append(QLatin1String("Brightness"));
    data.append(QString::number(brightness));
    match.setData(data.join(ParameterSeperator));

    matchData << match;
}
Ejemplo n.º 16
0
ccRasterizeTool::ccRasterizeTool(ccGenericPointCloud* cloud, QWidget* parent/*=0*/)
	: QDialog(parent, Qt::WindowMaximizeButtonHint)
	, cc2Point5DimEditor()
	, Ui::RasterizeToolDialog()
	, m_cloud(cloud)
{
	setupUi(this);

#ifndef CC_GDAL_SUPPORT
	generateRasterPushButton->setDisabled(true);
	generateRasterPushButton->setChecked(false);
#endif

	connect(buttonBox,					SIGNAL(accepted()),					this,	SLOT(testAndAccept()));
	connect(buttonBox,					SIGNAL(rejected()),					this,	SLOT(testAndReject()));
	connect(gridStepDoubleSpinBox,		SIGNAL(valueChanged(double)),		this,	SLOT(updateGridInfo()));
	connect(gridStepDoubleSpinBox,		SIGNAL(valueChanged(double)),		this,	SLOT(gridOptionChanged()));
	connect(emptyValueDoubleSpinBox,	SIGNAL(valueChanged(double)),		this,	SLOT(gridOptionChanged()));
	connect(resampleCloudCheckBox,		SIGNAL(toggled(bool)),				this,	SLOT(gridOptionChanged()));
	connect(dimensionComboBox,			SIGNAL(currentIndexChanged(int)),	this,	SLOT(projectionDirChanged(int)));
	connect(heightProjectionComboBox,	SIGNAL(currentIndexChanged(int)),	this,	SLOT(projectionTypeChanged(int)));
	connect(scalarFieldProjection,		SIGNAL(currentIndexChanged(int)),	this,	SLOT(sfProjectionTypeChanged(int)));
	connect(fillEmptyCellsComboBox,		SIGNAL(currentIndexChanged(int)),	this,	SLOT(fillEmptyCellStrategyChanged(int)));
	connect(updateGridPushButton,		SIGNAL(clicked()),					this,	SLOT(updateGridAndDisplay()));
	connect(generateCloudPushButton,	SIGNAL(clicked()),					this,	SLOT(generateCloud()));
	connect(generateImagePushButton,	SIGNAL(clicked()),					this,	SLOT(generateImage()));
	connect(generateRasterPushButton,	SIGNAL(clicked()),					this,	SLOT(generateRaster()));
	connect(generateASCIIPushButton,	SIGNAL(clicked()),					this,	SLOT(generateASCIIMatrix()));
	connect(generateMeshPushButton,		SIGNAL(clicked()),					this,	SLOT(generateMesh()));
	connect(generateContoursPushButton,	SIGNAL(clicked()),					this,	SLOT(generateContours()));
	connect(exportContoursPushButton,	SIGNAL(clicked()),					this,	SLOT(exportContourLines()));
	connect(clearContoursPushButton,	SIGNAL(clicked()),					this,	SLOT(removeContourLines()));
	connect(activeLayerComboBox,		SIGNAL(currentIndexChanged(int)),	this,	SLOT(activeLayerChanged(int)));

	//custom bbox editor
	ccBBox gridBBox = m_cloud ? m_cloud->getOwnBB() : ccBBox(); 
	if (gridBBox.isValid())
	{
		createBoundingBoxEditor(gridBBox, this);
		connect(editGridToolButton, SIGNAL(clicked()), this, SLOT(showGridBoxEditor()));
	}
	else
	{
		editGridToolButton->setEnabled(false);
	}

	if (m_cloud)
	{
		cloudNameLabel->setText(m_cloud->getName());
		pointCountLabel->setText(QString::number(m_cloud->size()));
		interpolateSFFrame->setEnabled(cloud->hasScalarFields());

		//populate layer box
		activeLayerComboBox->addItem(GetDefaultFieldName(PER_CELL_HEIGHT));
		if (cloud->isA(CC_TYPES::POINT_CLOUD) && cloud->hasScalarFields())
		{
			ccPointCloud* pc = static_cast<ccPointCloud*>(cloud);
			for (unsigned i=0; i<pc->getNumberOfScalarFields(); ++i)
				activeLayerComboBox->addItem(pc->getScalarField(i)->getName());
		}
		else
		{
			activeLayerComboBox->setEnabled(false);
		}

		//add window
		create2DView(mapFrame);
	}

	loadSettings();

	updateGridInfo();

	gridIsUpToDate(false);
}
Ejemplo n.º 17
0
void SkScalerContext::getImage(const SkGlyph& origGlyph) {
    const SkGlyph*  glyph = &origGlyph;
    SkGlyph         tmpGlyph;

    // in case we need to call generateImage on a mask-format that is different
    // (i.e. larger) than what our caller allocated by looking at origGlyph.
    SkAutoMalloc tmpGlyphImageStorage;

    // If we are going to draw-from-path, then we cannot generate color, since
    // the path only makes a mask. This case should have been caught up in
    // generateMetrics().
    SkASSERT(!fGenerateImageFromPath ||
             SkMask::kARGB32_Format != origGlyph.fMaskFormat);

    if (fMaskFilter) {   // restore the prefilter bounds
        tmpGlyph.initGlyphIdFrom(origGlyph);

        // need the original bounds, sans our maskfilter
        SkMaskFilter* mf = fMaskFilter;
        fMaskFilter = nullptr;             // temp disable
        this->getMetrics(&tmpGlyph);
        fMaskFilter = mf;               // restore

        // we need the prefilter bounds to be <= filter bounds
        SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth);
        SkASSERT(tmpGlyph.fHeight <= origGlyph.fHeight);

        if (tmpGlyph.fMaskFormat == origGlyph.fMaskFormat) {
            tmpGlyph.fImage = origGlyph.fImage;
        } else {
            tmpGlyphImageStorage.reset(tmpGlyph.computeImageSize());
            tmpGlyph.fImage = tmpGlyphImageStorage.get();
        }
        glyph = &tmpGlyph;
    }

    if (fGenerateImageFromPath) {
        SkPath      devPath, fillPath;
        SkMatrix    fillToDevMatrix;
        SkMask      mask;

        this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix);
        glyph->toMask(&mask);

        if (fRasterizer) {
            mask.fFormat = SkMask::kA8_Format;
            sk_bzero(glyph->fImage, mask.computeImageSize());

            if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr,
                                        fMaskFilter, &mask,
                                        SkMask::kJustRenderImage_CreateMode)) {
                return;
            }
            if (fPreBlend.isApplicable()) {
                applyLUTToA8Mask(mask, fPreBlend.fG);
            }
        } else {
            SkASSERT(SkMask::kARGB32_Format != mask.fFormat);
            generateMask(mask, devPath, fPreBlend);
        }
    } else {
        generateImage(*glyph);
    }

    if (fMaskFilter) {
        SkMask      srcM, dstM;
        SkMatrix    matrix;

        // the src glyph image shouldn't be 3D
        SkASSERT(SkMask::k3D_Format != glyph->fMaskFormat);

        SkAutoSMalloc<32*32> a8storage;
        glyph->toMask(&srcM);
        if (SkMask::kARGB32_Format == srcM.fFormat) {
            // now we need to extract the alpha-channel from the glyph's image
            // and copy it into a temp buffer, and then point srcM at that temp.
            srcM.fFormat = SkMask::kA8_Format;
            srcM.fRowBytes = SkAlign4(srcM.fBounds.width());
            size_t size = srcM.computeImageSize();
            a8storage.reset(size);
            srcM.fImage = (uint8_t*)a8storage.get();
            extract_alpha(srcM,
                          (const SkPMColor*)glyph->fImage, glyph->rowBytes());
        }

        fRec.getMatrixFrom2x2(&matrix);

        if (fMaskFilter->filterMask(&dstM, srcM, matrix, nullptr)) {
            int width = SkFastMin32(origGlyph.fWidth, dstM.fBounds.width());
            int height = SkFastMin32(origGlyph.fHeight, dstM.fBounds.height());
            int dstRB = origGlyph.rowBytes();
            int srcRB = dstM.fRowBytes;

            const uint8_t* src = (const uint8_t*)dstM.fImage;
            uint8_t* dst = (uint8_t*)origGlyph.fImage;

            if (SkMask::k3D_Format == dstM.fFormat) {
                // we have to copy 3 times as much
                height *= 3;
            }

            // clean out our glyph, since it may be larger than dstM
            //sk_bzero(dst, height * dstRB);

            while (--height >= 0) {
                memcpy(dst, src, width);
                src += srcRB;
                dst += dstRB;
            }
            SkMask::FreeImage(dstM.fImage);

            if (fPreBlendForFilter.isApplicable()) {
                applyLUTToA8Mask(srcM, fPreBlendForFilter.fG);
            }
        }
    }
}
Ejemplo n.º 18
0
void gateImage::update() {
	setViewport();
	generateImage();
}
Ejemplo n.º 19
0
/*
	This method generates all the textures
*/
u32 TextureSource::getTextureIdDirect(const std::string &name)
{
	//infostream<<"getTextureIdDirect(): name=\""<<name<<"\""<<std::endl;

	// Empty name means texture 0
	if(name == "")
	{
		infostream<<"getTextureIdDirect(): name is empty"<<std::endl;
		return 0;
	}

	/*
		Calling only allowed from main thread
	*/
	if(get_current_thread_id() != m_main_thread)
	{
		errorstream<<"TextureSource::getTextureIdDirect() "
				"called not from main thread"<<std::endl;
		return 0;
	}

	/*
		See if texture already exists
	*/
	{
		JMutexAutoLock lock(m_textureinfo_cache_mutex);

		std::map<std::string, u32>::iterator n;
		n = m_name_to_id.find(name);
		if(n != m_name_to_id.end())
		{
			/*infostream<<"getTextureIdDirect(): \""<<name
					<<"\" found in cache"<<std::endl;*/
			return n->second;
		}
	}

	/*infostream<<"getTextureIdDirect(): \""<<name
			<<"\" NOT found in cache. Creating it."<<std::endl;*/

	/*
		Get the base image
	*/

	char separator = '^';

	/*
		This is set to the id of the base image.
		If left 0, there is no base image and a completely new image
		is made.
	*/
	u32 base_image_id = 0;

	// Find last meta separator in name
	s32 last_separator_position = -1;
	for(s32 i=name.size()-1; i>=0; i--)
	{
		if(name[i] == separator)
		{
			last_separator_position = i;
			break;
		}
	}
	/*
		If separator was found, construct the base name and make the
		base image using a recursive call
	*/
	std::string base_image_name;
	if(last_separator_position != -1)
	{
		// Construct base name
		base_image_name = name.substr(0, last_separator_position);
		/*infostream<<"getTextureIdDirect(): Calling itself recursively"
				" to get base image of \""<<name<<"\" = \""
                <<base_image_name<<"\""<<std::endl;*/
		base_image_id = getTextureIdDirect(base_image_name);
	}

	//infostream<<"base_image_id="<<base_image_id<<std::endl;

	video::IVideoDriver* driver = m_device->getVideoDriver();
	assert(driver);

	video::ITexture *t = NULL;

	/*
		An image will be built from files and then converted into a texture.
	*/
	video::IImage *baseimg = NULL;

	// If a base image was found, copy it to baseimg
	if(base_image_id != 0)
	{
		JMutexAutoLock lock(m_textureinfo_cache_mutex);

		TextureInfo *ti = &m_textureinfo_cache[base_image_id];

		if(ti->img == NULL)
		{
			infostream<<"getTextureIdDirect(): WARNING: NULL image in "
					<<"cache: \""<<base_image_name<<"\""
					<<std::endl;
		}
		else
		{
			core::dimension2d<u32> dim = ti->img->getDimension();

			baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);

			ti->img->copyTo(
					baseimg, // target
					v2s32(0,0), // position in target
					core::rect<s32>(v2s32(0,0), dim) // from
			);

			/*infostream<<"getTextureIdDirect(): Loaded \""
					<<base_image_name<<"\" from image cache"
					<<std::endl;*/
		}
	}

	/*
		Parse out the last part of the name of the image and act
		according to it
	*/

	std::string last_part_of_name = name.substr(last_separator_position+1);
	//infostream<<"last_part_of_name=\""<<last_part_of_name<<"\""<<std::endl;

	// Generate image according to part of name
	if(!generateImage(last_part_of_name, baseimg))
	{
		errorstream<<"getTextureIdDirect(): "
				"failed to generate \""<<last_part_of_name<<"\""
				<<std::endl;
	}

	// If no resulting image, print a warning
	if(baseimg == NULL)
	{
		errorstream<<"getTextureIdDirect(): baseimg is NULL (attempted to"
				" create texture \""<<name<<"\""<<std::endl;
	}

	if(baseimg != NULL)
	{
		// Create texture from resulting image
		t = driver->addTexture(name.c_str(), baseimg);
	}

	/*
		Add texture to caches (add NULL textures too)
	*/

	JMutexAutoLock lock(m_textureinfo_cache_mutex);

	u32 id = m_textureinfo_cache.size();
	TextureInfo ti(name, t, baseimg);
	m_textureinfo_cache.push_back(ti);
	m_name_to_id[name] = id;

	/*infostream<<"getTextureIdDirect(): "
			<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/

	return id;
}
Ejemplo n.º 20
0
int main(int argc, char** argv)
{
  // parse command
  unsigned int pos = 1;
  unsigned int mask = (argc >= 2) ? 0 : 0xFFFF;
  while(pos < argc)
  {
    unsigned int sceneNumber = atoi(argv[pos++]);
    mask |= 1 << sceneNumber;
  }


  // Initialize
  phong p32(32.0f);
  phong p64(64.0f);
  phong p16(16.0f);
  diffuse d;
  constantAlbedo red(color(1.0f, 0.0f, 0.0f));
  constantAlbedo green(color(0.0f, 1.0f, 0.0f));
  constantAlbedo blue(color(0.0f, 0.0f, 1.0f));
  constantAlbedo white(color(1.0f, 1.0f, 1.0f));

  std::vector<triangle> sphere = createSphere( vec3d(0.0f, 0.0f, 0.0f), 1.0f, 16, 16 );
  std::vector<triangle> plane = createPlane( vec3d(-1.0f, -1.0f, 0.0f), vec3d(0.0f, 2.0f, 0.0f), vec3d(2.0f, 0.0f, 0.0f) );

  material redMaterial;
  redMaterial.addComponent( reflectanceComponent(&red, &d) );
  redMaterial.addComponent( reflectanceComponent(&white, &p32) );

  material greenMaterial;
  greenMaterial.addComponent( reflectanceComponent(&green, &d) );
  greenMaterial.addComponent( reflectanceComponent(&white, &p64) );

  material blueMaterial;
  blueMaterial.addComponent( reflectanceComponent(&blue, &d) );
  blueMaterial.addComponent( reflectanceComponent(&white, &p16) );

  material whiteMaterial;
  whiteMaterial.addComponent( reflectanceComponent(&white, &d) );

  triangleMesh redSphere(sphere, redMaterial);
  triangleMesh greenSphere(sphere, greenMaterial);
  triangleMesh blueSphere(sphere, blueMaterial);
  triangleMesh whitePlane(plane, whiteMaterial);

  sceneGraphObject redSphereObject(redSphere);
  sceneGraphObject greenSphereObject(greenSphere);
  sceneGraphObject blueSphereObject(blueSphere);
  sceneGraphObject whitePlaneObject(whitePlane);

  camera cam( vec3d(0.0f, 0.0f, 5.0f),
	      vec3d(0.0f, 0.0f, -1.0f),
	      vec3d(0.0f, 1.0f, 0.0f),
	      35.0f * M_PI / 180.0f,
	      512, 512 );

  directionalLightsource ls( color(1.0f, 1.0f, 1.0f), vec3d(0.0f, -1.0f, -1.0f) );
  directionalLightsource frontal( color(1.0f, 1.0f, 1.0f), vec3d(0.0f, 0.0f, -1.0f) );


  /////////////////////////////////////////////////////

  if((mask & 2) != 0)
  {
    sceneGraphNode sg1;
    sg1.addChildNode(redSphereObject);
  
    std::cout << "Generating Image 1." << std::endl;
    image result1 = generateImage(cam, sg1, ls);
    result1.save("hw4-result1.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 4) != 0)
  {
    sceneGraphNode sg2node1(translation3d(vec3d(+1.0f, 0.0f, 0.0f)));
    sg2node1.addChildNode(redSphereObject);

    sceneGraphNode sg2node2(translation3d(vec3d(-1.0f, 0.0f, 0.0f)));
    sg2node2.addChildNode(blueSphereObject);

    sceneGraphNode sg2;
    sg2.addChildNode(sg2node1);
    sg2.addChildNode(sg2node2);

    std::cout << "Generating Image 2." << std::endl;
    image result2 = generateImage(cam, sg2, ls);
    result2.save("hw4-result2.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 8) != 0)
  {
    sceneGraphNode sg3node1(scale3d(2.0f, 0.5f, 0.5f));
    sg3node1.addChildNode(greenSphereObject);

    sceneGraphNode sg3;
    sg3.addChildNode(sg3node1);
  
    std::cout << "Generating Image 3." << std::endl;
    image result3 = generateImage(cam, sg3, ls);
    result3.save("hw4-result3.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 16) != 0)
  {
    sceneGraphNode sg2node1(translation3d(vec3d(+1.0f, 0.0f, 0.0f)));
    sg2node1.addChildNode(redSphereObject);

    sceneGraphNode sg2node2(translation3d(vec3d(-1.0f, 0.0f, 0.0f)));
    sg2node2.addChildNode(blueSphereObject);

    sceneGraphNode sg2;
    sg2.addChildNode(sg2node1);
    sg2.addChildNode(sg2node2);

    sceneGraphNode sg4node1(rotationY3d(M_PI));
    sg4node1.addChildNode(sg2);

    sceneGraphNode sg4;
    sg4.addChildNode(sg4node1);
  
    std::cout << "Generating Image 4." << std::endl;
    image result4 = generateImage(cam, sg4, ls);
    result4.save("hw4-result4.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 32) != 0)
  {
    sceneGraphNode sg5node0(scale3d(0.5f, 0.5f, 0.5f));
    sceneGraphNode sg5node1(rotationY3d(0.5 * M_PI));
    sceneGraphNode sg5node2(rotationX3d(0.5 * M_PI));
    sceneGraphNode sg5node3(translation3d(vec3d(0.0f, 2.0f, 0.0f)));
    sceneGraphNode sg5node4(rotationX3d(0.5 * M_PI));
    sceneGraphNode sg5node5(translation3d(vec3d(0.0f, 2.0f, 0.0f)));
    sceneGraphNode sg5node6(rotationX3d(0.5 * M_PI));
    sceneGraphNode sg5node7(translation3d(vec3d(0.0f, 2.0f, 0.0f)));
    sceneGraphNode sg5node8(rotationX3d(0.5 * M_PI));
    sceneGraphNode sg5node9(translation3d(vec3d(0.0f, 2.0f, 0.0f)));

    sceneGraphNode sg5;
    sg5.addChildNode(sg5node0);
    sg5node0.addChildNode(sg5node1);
    sg5node1.addChildNode(sg5node2);
    sg5node2.addChildNode(sg5node3);
    sg5node3.addChildNode(redSphereObject);
    sg5node3.addChildNode(sg5node4);
    sg5node4.addChildNode(sg5node5);
    sg5node5.addChildNode(greenSphereObject);
    sg5node5.addChildNode(sg5node6);
    sg5node6.addChildNode(sg5node7);
    sg5node7.addChildNode(blueSphereObject);
    sg5node7.addChildNode(sg5node8);
    sg5node8.addChildNode(sg5node9);
    sg5node9.addChildNode(blueSphereObject);
    
    std::cout << "Generating Image 5." << std::endl;
    image result5 = generateImage(cam, sg5, ls);
    result5.save("hw4-result5.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 64) != 0)
  {
    sceneGraphNode cubeside( translation3d(vec3d(0.0f, 0.0f, 1.0f)) );
    cubeside.addChildNode(whitePlaneObject);

    sceneGraphNode cubeNode1( rotationY3d(0.0f / 2.0f * M_PI) );
    cubeNode1.addChildNode(cubeside);
    sceneGraphNode cubeNode2( rotationY3d(1.0f / 2.0f * M_PI) );
    cubeNode2.addChildNode(cubeside);
    sceneGraphNode cubeNode3( rotationY3d(2.0f / 2.0f * M_PI) );
    cubeNode3.addChildNode(cubeside);
    sceneGraphNode cubeNode4( rotationY3d(3.0f / 2.0f * M_PI) );
    cubeNode4.addChildNode(cubeside);
    sceneGraphNode cubeNode5( rotationX3d(0.5f * M_PI) );
    cubeNode5.addChildNode(cubeside);
    sceneGraphNode cubeNode6( rotationX3d(-0.5f * M_PI) );
    cubeNode6.addChildNode(cubeside);
    
    sceneGraphNode cube;
    cube.addChildNode(cubeNode1);
    cube.addChildNode(cubeNode2);
    cube.addChildNode(cubeNode3);
    cube.addChildNode(cubeNode4);
    cube.addChildNode(cubeNode5);
    cube.addChildNode(cubeNode6);
    
    sceneGraphNode sg6( rotation3d(0.25*M_PI, vec3d(1.0f, 0.75f, 0.5f)) );
    sg6.addChildNode(cube);
  
    std::cout << "Generating Image 6." << std::endl;
    image result6 = generateImage(cam, sg6, frontal);
    result6.save("hw4-result6.ppm");
  }

  // Done.
  return 0;
}
Ejemplo n.º 21
0
void GameWidget::keyPressEvent(QKeyEvent *event)
{
	if (animation_en_cours || moteur->gameOver() || moteur->levelCompleted())
	{
		//event->ignore();
		QWidget::keyPressEvent(event);
		return;
	}
	RETOURMVT retourmvt=RET_MONTAGNE;
	switch (event->key())
	{
		case Qt::Key_Left:
			retourmvt=moteur->moveTuxFisher(MVT_GAUCHE);
			break;
		case Qt::Key_Right:
			retourmvt=moteur->moveTuxFisher(MVT_DROITE);
			break;
		case Qt::Key_Down:
			retourmvt=moteur->moveTuxFisher(MVT_BAS);
			break;
		case Qt::Key_Up:
			retourmvt=moteur->moveTuxFisher(MVT_HAUT);
			break;
		case Qt::Key_Backspace:
			retourmvt = moteur->getBackToPrevMap();
			break;
		default:
			QWidget::keyPressEvent(event);
			//event->ignore();
			return;
	}
	
	switch (retourmvt)
	{
		case RET_POISSON:
			timer_animation->start(0);
			emit addMove(true);
			audio->playSound(son_fish, false);
			break;
		case RET_MONTAGNE:
		case RET_AVALANCHE:
		case RET_RIEN:
			audio->playSound(son_montagne, false);
			break;
		case RET_RETOUR:
			emit addMove(false);
			break;
		case RET_NEIGE:
		case RET_VIDE:
			timer_animation->start(0);
			emit addMove(true);
			break;
		default:
			break;
	}
	if (moteur->levelCompleted())
	{
		tuxfisher = tuxfisher_gagne;
		audio->playSound(son_victoire);
		emit levelCompleted();
	}

	generateImage();
}