示例#1
0
文件: GUI.cpp 项目: dbaumeister/LBM
void draw(const VectorGrid& grid) {

    glBegin(GL_LINES);
    double x, y, z = 0.;
    double velScale = 2.;
    glColor3f(0.9f, 0.f, 0.f);

    int dimX = grid.getDimX();
    int dimY = grid.getDimY();

    for(int i = 0; i < dimX - 1; ++i){
        for(int j = 0; j < dimY - 1; ++j){

            x = scaleX(i + 0.5, dimX);
            y = scaleY(j + 0.5, dimY);

            glVertex3f((float)x, (float)y, (float)z);

            double velX = grid.get(i, j).x;
            double velY = grid.get(i, j).y;
            x = scaleX(i + 0.5, dimX) +  velX * velScale * IMAGESCALE / (dimX - 1.);
            y = scaleY(j + 0.5, dimY) +  velY * velScale * IMAGESCALE / (dimY - 1.);

            glVertex3f((float)x, (float)y, (float)z);

        }
    }
    glEnd();
}
示例#2
0
void CartesianWidget::calcBounds()
{
    int w = width();
    int h = height();

    mxmin = centerX() - (double)(w/2.0) / ((double)scaleX()/zoom());
    mxmax = centerX() + (double)(w/2.0) / ((double)scaleX()/zoom());
    mymin = centerY() - (double)(h/2.0) / ((double)scaleY()/zoom());
    mymax = centerY() + (double)(h/2.0) / ((double)scaleY()/zoom());

    emit boundsChanged(mxmin, mymin, mxmax, mymax);
}
示例#3
0
void CartesianWidget::zoomIn()
{
    if (zoom() > ZOOM_MINIMUM)
    {
        setScale(scaleX() + SCALE_STP, scaleY() + SCALE_STP);
        if (scaleX() > SCALE_MAX)
        {
            setScale(SCALE_MIN, SCALE_MIN);
            setZoomLevel(zoomLevel()-1);
        }
    }
    update();
}
示例#4
0
void CartesianWidget::zoomOut()
{
    if (zoom() < ZOOM_MAXIMUM)
    {
        setScale(scaleX() - SCALE_STP, scaleY() - SCALE_STP);
        if (scaleX() < SCALE_MIN)
        {
            setScale(SCALE_MAX, SCALE_MAX);
            setZoomLevel(zoomLevel()+1);
        }
    }
    update();
}
示例#5
0
文件: Matrix.hpp 项目: Levinna/ogl
	void Decompose(Vector3<T>& vRotationAngle, Vector3<T>& vScale, Vector3<T>& vTranslate) {
		//이동
		vTranslate = Vector3<T>(w.x, w.y, w.z);
		
		//크기
		Vector3<T> scaleX(x.x, x.y, x.z);
		Vector3<T> scaleY(y.x, y.y, y.z);
		Vector3<T> scaleZ(z.x, z.y, z.z);
		vScale.x = scaleX.Length();
		vScale.y = scaleY.Length();
		vScale.z = scaleZ.Length();
		
		//회전
		float sx = z.y/vScale.z;
		float cx = sqrtf(1.0f - sx * sx);
		float xx, yy, zz;
		if (cx < 0.00001f) {
			if (sx > 0)
				xx = PI / 2;
			else
				xx = -PI / 2;

			yy = atan2f(z.x / vScale.z, x.x/vScale.x);
			zz = 0.0f;
		} else {
			xx = atan2f(sx, cx);
			yy = atan2f(-z.x / vScale.z, z.z / vScale.z);
			zz = atan2f(-x.y / vScale.x, y.y / vScale.y);
		}

		vRotationAngle = Vector3<T>(xx, yy, zz);
	}
示例#6
0
void Mouse::setY(int y)
{
    _y = y;
    auto renderer = Game::getInstance()->renderer();
    float scaleX = renderer->scaleX();
    float scaleY = renderer->scaleY();
    SDL_WarpMouseInWindow(renderer->sdlWindow(), _x*scaleX, _y*scaleY);
}
示例#7
0
 void Mouse::setPosition(const Point& pos)
 {
     _position = pos;
     auto renderer = Game::getInstance()->renderer();
     float scaleX = renderer->scaleX();
     float scaleY = renderer->scaleY();
     SDL_WarpMouseInWindow(renderer->sdlWindow(), (int)(pos.x() * scaleX), (int)(pos.y() * scaleY));
 }
示例#8
0
static void scaleX (I, double xminfrom, double xmaxfrom, double xminto, double xmaxto) {
	iam (RealTier);
	inherited (RealTier) scaleX (me, xminfrom, xmaxfrom, xminto, xmaxto);
	for (long i = 1; i <= my points -> size; i ++) {
		RealPoint point = (structRealPoint *)my points -> item [i];
		NUMscale (& point -> time, xminfrom, xmaxfrom, xminto, xmaxto);
	}
}
示例#9
0
reg_t GfxText32::createFontBitmap(int16 width, int16 height, const Common::Rect &rect, const Common::String &text, const uint8 foreColor, const uint8 backColor, const uint8 skipColor, const GuiResourceId fontId, const TextAlign alignment, const int16 borderColor, const bool dimmed, const bool doScaling, reg_t *outBitmapObject) {

	_field_22 = 0;
	_borderColor = borderColor;
	_text = text;
	_textRect = rect;
	_width = width;
	_height = height;
	_foreColor = foreColor;
	_backColor = backColor;
	_skipColor = skipColor;
	_alignment = alignment;
	_dimmed = dimmed;

	setFont(fontId);

	if (doScaling) {
		int16 scriptWidth = g_sci->_gfxFrameout->getCurrentBuffer().scriptWidth;
		int16 scriptHeight = g_sci->_gfxFrameout->getCurrentBuffer().scriptHeight;

		Ratio scaleX(_scaledWidth, scriptWidth);
		Ratio scaleY(_scaledHeight, scriptHeight);

		_width = (_width * scaleX).toInt();
		_height = (_height * scaleY).toInt();
		mulinc(_textRect, scaleX, scaleY);
	}

	// _textRect represents where text is drawn inside the
	// bitmap; clipRect is the entire bitmap
	Common::Rect bitmapRect(_width, _height);

	if (_textRect.intersects(bitmapRect)) {
		_textRect.clip(bitmapRect);
	} else {
		_textRect = Common::Rect();
	}

	_bitmap = _segMan->allocateHunkEntry("FontBitmap()", _width * _height + BITMAP_HEADER_SIZE);

	byte *bitmap = _segMan->getHunkPointer(_bitmap);
	buildBitmapHeader(bitmap, _width, _height, _skipColor, 0, 0, _scaledWidth, _scaledHeight, 0, false);

	erase(bitmapRect, false);

	if (_borderColor > -1) {
		drawFrame(bitmapRect, 1, _borderColor, false);
	}

	drawTextBox();

	*outBitmapObject = _bitmap;
	return _bitmap;
}
示例#10
0
static void scaleX (I, double xminfrom, double xmaxfrom, double xminto, double xmaxto) {
	iam (FormantGrid);
	inherited (FormantGrid) scaleX (me, xminfrom, xmaxfrom, xminto, xmaxto);
	for (long i = 1; i <= my formants -> size; i ++) {
		RealTier tier = (structRealTier *)my formants -> item [i];
		tier -> methods -> scaleX (tier, xminfrom, xmaxfrom, xminto, xmaxto);
	}
	for (long i = 1; i <= my bandwidths -> size; i ++) {
		RealTier tier = (structRealTier *)my bandwidths -> item [i];
		tier -> methods -> scaleX (tier, xminfrom, xmaxfrom, xminto, xmaxto);
	}
}
示例#11
0
文件: text32.cpp 项目: 86400/scummvm
reg_t GfxText32::createFontBitmap(int16 width, int16 height, const Common::Rect &rect, const Common::String &text, const uint8 foreColor, const uint8 backColor, const uint8 skipColor, const GuiResourceId fontId, const TextAlign alignment, const int16 borderColor, const bool dimmed, const bool doScaling, const bool gc) {

	_borderColor = borderColor;
	_text = text;
	_textRect = rect;
	_width = width;
	_height = height;
	_foreColor = foreColor;
	_backColor = backColor;
	_skipColor = skipColor;
	_alignment = alignment;
	_dimmed = dimmed;

	setFont(fontId);

	if (doScaling) {
		int16 scriptWidth = g_sci->_gfxFrameout->getCurrentBuffer().scriptWidth;
		int16 scriptHeight = g_sci->_gfxFrameout->getCurrentBuffer().scriptHeight;

		Ratio scaleX(_xResolution, scriptWidth);
		Ratio scaleY(_yResolution, scriptHeight);

		_width = (_width * scaleX).toInt();
		_height = (_height * scaleY).toInt();
		mulinc(_textRect, scaleX, scaleY);
	}

	// _textRect represents where text is drawn inside the
	// bitmap; clipRect is the entire bitmap
	Common::Rect bitmapRect(_width, _height);

	if (_textRect.intersects(bitmapRect)) {
		_textRect.clip(bitmapRect);
	} else {
		_textRect = Common::Rect();
	}

	_segMan->allocateBitmap(&_bitmap, _width, _height, _skipColor, 0, 0, _xResolution, _yResolution, 0, false, gc);

	erase(bitmapRect, false);

	if (_borderColor > -1) {
		drawFrame(bitmapRect, 1, _borderColor, false);
	}

	drawTextBox();
	return _bitmap;
}
示例#12
0
void 
reshape(int w, int h)
{
	
	W = w;
    H = h;
	GLfloat scaleX(1), scaleY(1);
	if ( W * worldY > H * worldX )  // the window is too wide
		scaleX = (W * worldY)/(H * worldX );
	else
		scaleY = (H * worldX )/(W * worldY);

    glViewport(0, 0, w/scaleX, h/scaleY);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
	//       left,right, bottom, top
    glOrtho(0.0f, worldX, 0.0f, worldY, -5.0f, 5.0f);
    glMatrixMode(GL_MODELVIEW);
    W = w;
    H = h;	
}
示例#13
0
// -----------------------------------------------------------------------------
// Writes the texture list in TEXTUREX format to [texturex], using [patch_table]
// for patch information.
// Returns true on success, false otherwise
// -----------------------------------------------------------------------------
bool TextureXList::writeTEXTUREXData(ArchiveEntry* texturex, const PatchTable& patch_table)
{
	// Check entry was given
	if (!texturex)
		return false;

	if (texturex->isLocked())
		return false;

	Log::info("Writing " + textureXFormatString() + " format TEXTUREx entry");

	/* Total size of a TEXTUREx lump, in bytes:
		Header: 4 + (4 * numtextures)
		Textures:
			22 * numtextures (normal format)
			14 * numtextures (nameless format)
			18 * numtextures (Strife 1.1 format)
		Patches:
			10 * sum of patchcounts (normal and nameless formats)
			 6 * sum of patchcounts (Strife 1.1 format)
	*/
	size_t numpatchrefs = 0;
	size_t numtextures  = textures_.size();
	for (size_t i = 0; i < numtextures; ++i)
	{
		numpatchrefs += textures_[i]->nPatches();
	}
	Log::info("{} patch references in {} textures", numpatchrefs, numtextures);

	size_t datasize   = 0;
	size_t headersize = 4 + (4 * numtextures);
	switch (txformat_)
	{
	case Format::Normal: datasize = 4 + (26 * numtextures) + (10 * numpatchrefs); break;
	case Format::Nameless: datasize = 4 + (18 * numtextures) + (10 * numpatchrefs); break;
	case Format::Strife11:
		datasize = 4 + (22 * numtextures) + (6 * numpatchrefs);
		break;
		// Some compilers insist on having default cases.
	default: return false;
	}

	MemChunk        txdata(datasize);
	vector<int32_t> offsets(numtextures);
	int32_t         foo = wxINT32_SWAP_ON_BE((signed)numtextures);

	// Write header
	txdata.seek(0, SEEK_SET);
	SAFEFUNC(txdata.write(&foo, 4));

	// Go to beginning of texture definitions
	SAFEFUNC(txdata.seek(4 + (numtextures * 4), SEEK_SET));

	// Write texture entries
	for (size_t i = 0; i < numtextures; ++i)
	{
		// Get texture to write
		auto tex = textures_[i].get();

		// Set offset
		offsets[i] = (signed)txdata.currentPos();

		// Write texture entry
		switch (txformat_)
		{
		case Format::Normal:
		{
			// Create 'normal' doom format texture definition
			FullTexDef txdef;
			memset(txdef.name, 0, 8); // Set texture name to all 0's (to ensure compatibility with XWE)
			strncpy(txdef.name, tex->name().data(), tex->name().size());
			for (auto& c : txdef.name)
				c = toupper(c);
			txdef.flags        = 0;
			txdef.scale[0]     = (tex->scaleX() * 8);
			txdef.scale[1]     = (tex->scaleY() * 8);
			txdef.width        = tex->width();
			txdef.height       = tex->height();
			txdef.columndir[0] = 0;
			txdef.columndir[1] = 0;
			txdef.patchcount   = tex->nPatches();

			// Check for WorldPanning flag
			if (tex->world_panning_)
				txdef.flags |= Flags::WorldPanning;

			// Write texture definition
			SAFEFUNC(txdata.write(&txdef, 22));

			break;
		}
		case Format::Nameless:
		{
			// Create nameless texture definition
			NamelessTexDef txdef;
			txdef.flags        = 0;
			txdef.scale[0]     = (tex->scaleX() * 8);
			txdef.scale[1]     = (tex->scaleY() * 8);
			txdef.width        = tex->width();
			txdef.height       = tex->height();
			txdef.columndir[0] = 0;
			txdef.columndir[1] = 0;
			txdef.patchcount   = tex->nPatches();

			// Write texture definition
			SAFEFUNC(txdata.write(&txdef, 8));

			break;
		}
		case Format::Strife11:
		{
			// Create strife format texture definition
			StrifeTexDef txdef;
			memset(txdef.name, 0, 8); // Set texture name to all 0's (to ensure compatibility with XWE)
			strncpy(txdef.name, tex->name().data(), tex->name().size());
			for (auto& c : txdef.name)
				c = toupper(c);
			txdef.flags      = 0;
			txdef.scale[0]   = (tex->scaleX() * 8);
			txdef.scale[1]   = (tex->scaleY() * 8);
			txdef.width      = tex->width();
			txdef.height     = tex->height();
			txdef.patchcount = tex->nPatches();

			// Check for WorldPanning flag
			if (tex->world_panning_)
				txdef.flags |= Flags::WorldPanning;

			// Write texture definition
			SAFEFUNC(txdata.write(&txdef, 18));

			break;
		}
		default: return false;
		}

		// Write patch references
		for (size_t k = 0; k < tex->nPatches(); ++k)
		{
			// Get patch to write
			auto patch = tex->patch(k);

			// Create patch definition
			Patch pdef;
			pdef.left = patch->xOffset();
			pdef.top  = patch->yOffset();

			// Check for 'invalid' patch
			if (StrUtil::startsWith(patch->name(), "INVPATCH"))
			{
				// Get raw patch index from name
				std::string_view number = patch->name();
				number.remove_prefix(8);
				pdef.patch = StrUtil::asInt(number);
			}
			else
				pdef.patch = patch_table.patchIndex(
					patch->name()); // Note this will be -1 if the patch doesn't exist in the patch table. This
									// should never happen with the texture editor, though.

			// Write common data
			SAFEFUNC(txdata.write(&pdef, 6));

			// In non-Strife formats, there's some added rubbish
			if (txformat_ != Format::Strife11)
			{
				foo = 0;
				SAFEFUNC(txdata.write(&foo, 4));
			}
		}
	}

	// Write offsets
	SAFEFUNC(txdata.seek(4, SEEK_SET));
	SAFEFUNC(txdata.write(offsets.data(), 4 * numtextures));

	// Write data to the TEXTUREx entry
	texturex->importMemChunk(txdata);

	// Update entry type
	EntryType::detectEntryType(texturex);

	return true;
}
示例#14
0
文件: square.cpp 项目: gdari/cg
void Square::setDefault(){
    rotate(0);
    scaleX(Triangle::DEFAULT_SCALE_X);
    scaleY(Triangle::DEFAULT_SCALE_Y);
}
示例#15
0
文件: mgmat.cpp 项目: Vito2015/vgcore
float Matrix2d::scale() const
{
    float sx = scaleX();
    float sy = scaleY();
    return fabsf(sx - sy) < _MGZERO ? sx : mgHypot(sx, sy);
}
示例#16
0
	void Point2f::scale(float xs, float ys)
	{
		scaleX(xs);
		scaleY(ys);
	}
glm::vec2 CoordinateTransform::scale( glm::vec2 vec, CoordinateSystem to )
{
    return glm::vec2( scaleX( vec.x, to ), scaleY( vec.y, to ) );
}
示例#18
0
bool COscScaler::eventFilter( QObject * obj, QEvent * e )
{
    QMouseEvent  * me;
    QKeyEvent    * ke;
    //QResizeEvent * re;
    if ( obj == m_pd->xBottom )
    {
        switch ( e->type() )
        {
        case QEvent::MouseMove:
            me = reinterpret_cast< QMouseEvent * >( e );
            // Подсвечивать или нет.
            m_pd->m_paintX = true;
            // Если включена прокрутка, вызываем прокрутку.
            if ( m_pd->m_dragX ) 
            {
                // А если включено масштабирование, вызываем масштабирование.
                if ( m_pd->m_scale )
                    scaleX( me->pos() );
                else
                    dragXY( me->pos() );
            }
            break;

        case QEvent::MouseButtonPress:
            m_pd->m_dragX = true;
            me = reinterpret_cast< QMouseEvent * >( e );
            m_pd->m_at = me->pos();
            m_pd->xMinBase = m_pd->m_plot->axisScaleDiv( QwtPlot::xBottom )->lowerBound();
            m_pd->xMaxBase = m_pd->m_plot->axisScaleDiv( QwtPlot::xBottom )->upperBound();
            m_pd->yMinBase = m_pd->m_plot->axisScaleDiv( QwtPlot::yLeft )->lowerBound();
            m_pd->yMaxBase = m_pd->m_plot->axisScaleDiv( QwtPlot::yLeft )->upperBound();
            break;

        case QEvent::MouseButtonRelease:
            m_pd->m_dragX = false;
            break;

        case QEvent::MouseButtonDblClick:
            m_pd->m_plot->setAxisAutoScale( QwtPlot::xBottom );
            m_pd->m_plot->replot();
            break;

        case QEvent::Leave:
            m_pd->m_paintX = false;
            m_pd->xBottom->releaseKeyboard();
            m_pd->xBottom->update();
            m_pd->m_scale = false;
            m_keyEqualScales = false;
            break;

        case QEvent::Enter:
            m_pd->m_paintX = true;
            m_pd->xBottom->grabKeyboard();
            m_pd->xBottom->update();
            break;

        case QEvent::Paint:
            // Рисуем то, что нужно было,
            obj->event( e );
            // А потом своё.
            if ( m_pd->m_paintX )
                paintX();
            return true;
        break;
        }
    }
    else if ( obj == m_pd->yLeft )
    {
        switch ( e->type() )
        {
        case QEvent::MouseMove:
            me = reinterpret_cast< QMouseEvent * >( e );
            // Подсвечивать или нет.
            m_pd->m_paintY = true;
            // Если включена прокрутка, вызываем прокрутку.
            if ( m_pd->m_dragY )
            {
                // А если включено масштабирование, вызываем масштабирование.
                if ( m_pd->m_scale )
                    scaleY( me->pos() );
                else
                    dragXY( me->pos() );
            }                
            break;

        case QEvent::MouseButtonPress:
            m_pd->m_dragY = true;
            me = reinterpret_cast< QMouseEvent * >( e );
            m_pd->m_at = me->pos();
            m_pd->xMinBase = m_pd->m_plot->axisScaleDiv( QwtPlot::xBottom )->lowerBound();
            m_pd->xMaxBase = m_pd->m_plot->axisScaleDiv( QwtPlot::xBottom )->upperBound();
            m_pd->yMinBase = m_pd->m_plot->axisScaleDiv( QwtPlot::yLeft )->lowerBound();
            m_pd->yMaxBase = m_pd->m_plot->axisScaleDiv( QwtPlot::yLeft )->upperBound();
            break;

        case QEvent::MouseButtonRelease:
            m_pd->m_dragY = false;
            break;

        case QEvent::MouseButtonDblClick:
            m_pd->m_plot->setAxisAutoScale( QwtPlot::yLeft );
            m_pd->m_plot->replot();
            break;

        case QEvent::Leave:
            m_pd->m_paintY = false;
            m_pd->yLeft->releaseKeyboard();
            m_pd->yLeft->update();
            m_pd->m_scale = false;
            m_keyEqualScales = false;
            break;

        case QEvent::Enter:
            m_pd->m_paintY = true;
            m_pd->yLeft->grabKeyboard();
            m_pd->yLeft->update();
            break;

        case QEvent::Paint:
            // Рисуем то, что нужно было,
            obj->event( e );
            // А потом своё.
            if ( m_pd->m_paintY )
                paintY();
            return true;
        }
    }
    else if ( obj == m_pd->canvas )
    {
        switch ( e->type() )
        {
        case QEvent::Wheel:
            mouseWheel( e );
            return false;
        }
    }
    
    if ( e->type() == QEvent::KeyPress )
    {
        ke = reinterpret_cast< QKeyEvent * >( e );
        switch( ke->key() )
        {
        case Qt::Key_Shift:
            m_pd->m_scale = true;
            break;
        case Qt::Key_Alt:
            m_pd->m_scale = true;
            m_keyEqualScales = true;
            break;
        }
    }
    else if ( e->type() == QEvent::KeyRelease )
    {
        ke = reinterpret_cast< QKeyEvent * >( e );
        switch( ke->key() )
        {
        case Qt::Key_Shift:
            m_pd->m_scale = false;
            break;
        case Qt::Key_Alt:
            m_pd->m_scale = false;
            m_keyEqualScales = false;
            break;
        }
    }    
    return false;
}
void Shape::scale_change(GLfloat x) {
	scaleX(x);
	scaleY(x);
	scaleZ(x);
	MC.normalize();
}
示例#20
0
// -----------------------------------------------------------------------------
// Returns the flat matching [name], loading it from resources if necessary.
// If [mixed] is true, textures are also searched if no matching flat is found
// -----------------------------------------------------------------------------
const MapTextureManager::Texture& MapTextureManager::flat(std::string_view name, bool mixed)
{
	// Get flat matching name
	auto& mtex = flats_[StrUtil::upper(name)];

	// Get desired filter type
	auto filter = OpenGL::TexFilter::Linear;
	if (map_tex_filter == 0)
		filter = OpenGL::TexFilter::NearestLinearMin;
	else if (map_tex_filter == 1)
		filter = OpenGL::TexFilter::Linear;
	else if (map_tex_filter == 2)
		filter = OpenGL::TexFilter::LinearMipmap;
	else if (map_tex_filter == 3)
		filter = OpenGL::TexFilter::NearestMipmap;

	// If the texture is loaded
	if (mtex.gl_id)
	{
		// If the texture filter matches the desired one, return it
		auto& tex_info = OpenGL::Texture::info(mtex.gl_id);
		if (tex_info.filter == filter)
			return mtex;
		else
		{
			// Otherwise, reload the texture
			OpenGL::Texture::clear(mtex.gl_id);
			mtex.gl_id = 0;
		}
	}

	if (mixed)
	{
		auto ctex = App::resources().getTexture(name, archive_);
		if (ctex && ctex->isExtended() && ctex->type() != "WallTexture")
		{
			SImage image;
			if (ctex->toImage(image, archive_, palette_.get(), true))
			{
				mtex.gl_id = OpenGL::Texture::createFromImage(image, palette_.get(), filter);

				double sx = ctex->scaleX();
				if (sx == 0)
					sx = 1.0;
				double sy = ctex->scaleY();
				if (sy == 0)
					sy = 1.0;

				mtex.scale         = { 1.0 / sx, 1.0 / sy };
				mtex.world_panning = ctex->worldPanning();

				return mtex;
			}
		}
	}

	// Flat not found, look for it
	// Palette8bit* pal = getResourcePalette();
	if (!mtex.gl_id)
	{
		auto entry = App::resources().getTextureEntry(name, "hires", archive_);
		if (entry == nullptr)
			entry = App::resources().getTextureEntry(name, "flats", archive_);
		if (entry == nullptr)
			entry = App::resources().getFlatEntry(name, archive_);
		if (entry)
		{
			SImage image;
			if (Misc::loadImageFromEntry(&image, entry))
				mtex.gl_id = OpenGL::Texture::createFromImage(image, palette_.get(), filter);
		}
	}

	// Not found
	if (!mtex.gl_id)
	{
		// Try textures if mixed
		if (mixed)
			return texture(name, false);

		// Otherwise use missing texture
		else
			mtex.gl_id = OpenGL::Texture::missingTexture();
	}

	return mtex;
}
示例#21
0
// -----------------------------------------------------------------------------
// Returns the texture matching [name], loading it from resources if necessary.
// If [mixed] is true, flats are also searched if no matching texture is found
// -----------------------------------------------------------------------------
const MapTextureManager::Texture& MapTextureManager::texture(std::string_view name, bool mixed)
{
	// Get texture matching name
	auto& mtex = textures_[StrUtil::upper(name)];

	// Get desired filter type
	auto filter = OpenGL::TexFilter::Linear;
	if (map_tex_filter == 0)
		filter = OpenGL::TexFilter::NearestLinearMin;
	else if (map_tex_filter == 1)
		filter = OpenGL::TexFilter::Linear;
	else if (map_tex_filter == 2)
		filter = OpenGL::TexFilter::LinearMipmap;
	else if (map_tex_filter == 3)
		filter = OpenGL::TexFilter::NearestMipmap;

	// If the texture is loaded
	if (mtex.gl_id)
	{
		// If the texture filter matches the desired one, return it
		auto& tex_info = OpenGL::Texture::info(mtex.gl_id);
		if (tex_info.filter == filter)
			return mtex;
		else
		{
			// Otherwise, reload the texture
			OpenGL::Texture::clear(mtex.gl_id);
			mtex.gl_id = 0;
		}
	}

	// Texture not found or unloaded, look for it

	// Look for stand-alone textures first
	auto etex         = App::resources().getTextureEntry(name, "hires", archive_);
	auto textypefound = CTexture::Type::HiRes;
	if (etex == nullptr)
	{
		etex         = App::resources().getTextureEntry(name, "textures", archive_);
		textypefound = CTexture::Type::Texture;
	}
	if (etex)
	{
		SImage image;
		// Get image format hint from type, if any
		if (Misc::loadImageFromEntry(&image, etex))
		{
			mtex.gl_id = OpenGL::Texture::createFromImage(image, palette_.get(), filter);

			// Handle hires texture scale
			if (textypefound == CTexture::Type::HiRes)
			{
				auto ref = App::resources().getTextureEntry(name, "textures", archive_);
				if (ref)
				{
					SImage imgref;
					if (Misc::loadImageFromEntry(&imgref, ref))
					{
						int w, h, sw, sh;
						w                  = image.width();
						h                  = image.height();
						sw                 = imgref.width();
						sh                 = imgref.height();
						mtex.world_panning = true;
						mtex.scale         = { (double)sw / (double)w, (double)sh / (double)h };
					}
				}
			}
		}
	}

	// Try composite textures then
	auto ctex = App::resources().getTexture(name, archive_);
	if (ctex) // Composite textures take precedence over the textures directory
	{
		textypefound = CTexture::Type::WallTexture;
		SImage image;
		if (ctex->toImage(image, archive_, palette_.get(), true))
		{
			mtex.gl_id = OpenGL::Texture::createFromImage(image, palette_.get(), filter);

			double sx = ctex->scaleX();
			if (sx == 0)
				sx = 1.0;
			double sy = ctex->scaleY();
			if (sy == 0)
				sy = 1.0;

			mtex.world_panning = ctex->worldPanning();
			mtex.scale         = { 1.0 / sx, 1.0 / sy };
		}
	}

	// Not found
	if (!mtex.gl_id)
	{
		// Try flats if mixed
		if (mixed)
			return flat(name, false);

		// Otherwise use missing texture
		mtex.gl_id = OpenGL::Texture::missingTexture();
	}

	return mtex;
}
// Serving HTML/Content function
static void serveHTML (int socket) {
   
   // Initalizing message string.
   char *message;
   
   // first send the http response header
   // (if you write stings one after another like this on separate
   // lines the c compiler kindly joins them togther for you into
   // one long string)
   message = "HTTP/1.0 200 OK\r\n"
                "Content-Type: image/bmp\r\n"
                "\r\n";
   printf ("about to send=> %s\n", message);
   write (socket, message, strlen (message));
   
   

   // Initalizing variables.
   double i,j,x,y,x0,y0,xTemp;
   int iteration;
   
   // Creating loader pixel struct to serve pixel colors to BMP array
   pixel loaderPixel;
   
   // Creating and filling out array of BMP data. 
   unsigned char bmp[BMP_ARRAY_SIZE] = {
   0x42,0x4D,0x36,0x00,0x0C,0x00,0x00,0x00,
   0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
   0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,
   0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00};
   
   // After the header (54th byte) we include the pixel data.
   int start = BMP_Header_BYTE;
   
   // Row Loop.
   for(i=0.0;i<ROWS;i++){
      
      // Column Loop.
      for(j=0.0;j<COLUMNS;j++){
      
         // Reseting x,y to zero.
         y = 0;
         x = 0;
      
         // Scale X,Y points to within the Mandelbrot Set. 
         x0 = scaleX(j);
         y0 = scaleY(i);
      
         // Reset iteration counter.
         iteration = 0;
         
         // Calculation code paraphrased from Mandelbrot Wikipedia website.
         while ((x*x + y*y) < 4.0 && iteration<MAX_ITERATION)
         {
            xTemp = x*x - y*y + x0;
            y = 2.0*x*y + y0;

            x = xTemp;

            iteration++;
         }
         
         // Printing out color pixels corresponding to pixel color functions.
         loaderPixel.red = stepsToRed(iteration);
         loaderPixel.green = stepsToGreen(iteration); 
         loaderPixel.blue = stepsToBlue(iteration);
            
         // Increment through Bytes & include numbers for all BGR. 
         start++;
         bmp[start] = loaderPixel.blue;
         start++;
         bmp[start] = loaderPixel.green;
         start++;
         bmp[start] = loaderPixel.red;
 
      }
        
   } 
 
   // Now send the contents of the web page to be displayed  
   printf ("about to send=> %s\n", message);         
   write (socket, bmp, sizeof(bmp));
   
}
示例#23
0
static void scaleX (I, double xminfrom, double xmaxfrom, double xminto, double xmaxto) {
	iam (Sampled);
	inherited (Sampled) scaleX (me, xminfrom, xmaxfrom, xminto, xmaxto);
	NUMscale (& my x1, xminfrom, xmaxfrom, xminto, xmaxto);
	my dx *= (xmaxto - xminto) / (xmaxfrom - xminfrom);
}