Esempio n. 1
18
		bool KINRenderManager::DrawTexture(Texture& pTexture, const Common::KINPoint& pPoint, const Common::KINRect& pRect, float pAngle, float pScaling_Width, float pScaling_Height, float pCenter_X, float pCenter_Y, int pAlpha)
		{
			if(mpD3D == NULL || mpD3D_Device == NULL ||
			   mpD3D_Sprite == NULL || pTexture.mpTexture == NULL)
			{
				return false;
			}

			RECT rc = {pRect.mX, pRect.mY, pRect.mWidth, pRect.mHeight};

			if(pAngle != 0)
			{
				pAngle = D3DX_PI/(180/pAngle);
			}

			pCenter_X *= pScaling_Width;
			pCenter_Y *= pScaling_Height;

			D3DXMATRIX mat;
			D3DXVECTOR2 mov((-(cos(pAngle)*pCenter_X-sin(pAngle)*pCenter_Y))+pPoint.mX+pCenter_X, (-(sin(pAngle)*pCenter_X+cos(pAngle)*pCenter_Y))+pPoint.mY+pCenter_Y);
			D3DXVECTOR2 sc(pScaling_Width, pScaling_Height);

			D3DXMatrixTransformation2D(&mat, NULL, NULL, &sc, NULL, pAngle, &mov);
			mpD3D_Sprite->SetTransform(&mat);
			
			D3DXVECTOR3 Pos(0, 0, 0);
			mpD3D_Sprite->Draw(pTexture.mpTexture, &rc, NULL, &Pos, Common::DX_RGBA(255, 255, 255, pAlpha));

			return true;
		}
void CTextureDx9::RenderWithoutTransform(LPD3DXSPRITE _lpDSpriteHandle, D3DXVECTOR2 position, D3DXVECTOR2 Center, D3DXVECTOR2 scale, float angle, D3DCOLOR color, RECT *srcRect, float deep)
{
	D3DXVECTOR2 CamTransDistance;
	CamTransDistance.x = -Camera::getInstance()->GetMatrixTranslate()._41;
	CamTransDistance.y = Camera::getInstance()->GetMatrixTranslate()._42;

	position.y += Camera::getInstance()->getBound().bottom;
	Center.y += Camera::getInstance()->getBound().bottom;
	D3DXVECTOR3 currentPosition(position.x + CamTransDistance.x, position.y, deep); //toa do trong the gioi thuc

	D3DXMATRIX oldMatrix; //ma tran luu lai phep transform cua SpriteBatch

	_lpDSpriteHandle->GetTransform(&oldMatrix);
	
	D3DXVECTOR2 centerScale = D3DXVECTOR2(position.x, position.y);//lay vi tri cua vat the lam tam xoay(vi vi tri cua vat la vi tri chinh giua cua vat)

	D3DXMATRIX matrixScalingRotate; //ma tran rotate, scale

	D3DXMatrixTransformation2D(&matrixScalingRotate, &centerScale, 0.0f, &scale, &Center, D3DXToRadian(angle), 0);

	D3DXMATRIX finalMatrix = matrixScalingRotate * oldMatrix;

	_lpDSpriteHandle->SetTransform(&finalMatrix); //ma tran chuyen toa do vi tri cua vat the tu the gioi thuc sang toa do trong directX de ve

	_lpDSpriteHandle->Draw(
		this->m_lpTexture,
		srcRect,
		&D3DXVECTOR3((float)(srcRect->right - srcRect->left)/2, (float)(srcRect->bottom - srcRect->top)/2, 0),
		&currentPosition,
		color);

	_lpDSpriteHandle->SetTransform(&oldMatrix);
}
	void TwoDRenderManager::Render()
	{
		// Set matrix vectors
		Vector2 scale(_scaleX, _scaleY);
		Vector2 center((float)(_frameW * _scaleX) / 2.0f, (float)(_frameH * _scaleY) / 2.0f);
		Vector2 translation(_posVector.x, _posVector.y);

		// Create the matrix
		D3DXMATRIX transform;
		D3DXMatrixTransformation2D(&transform, NULL, 0, &scale.ToD3DXVECTOR2(),
			&center.ToD3DXVECTOR2(), _rotation, &translation.ToD3DXVECTOR2());

		// Set our transform matrix
		g_Engine->GetSpriteObj()->SetTransform(&transform);

		// Get a RECT for current frame
		RECT rect;
		rect.left = (_curFrame % _numCol) * _frameW;
		rect.right = rect.left + _frameW;
		rect.top = (_curFrame / _numCol) * _frameH;
		rect.bottom = rect.top + _frameH;

		// Draw to screen
		g_Engine->GetSpriteObj()->Draw(_texture, &rect, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255));

	}
Esempio n. 4
0
void CImage::DrawSprite(LPD3DXSPRITE SpriteInterface, LPDIRECT3DTEXTURE9 TextureInterface, int PosX, int PosY, int Rotation, int Align)
{
	if(SpriteInterface == NULL || TextureInterface == NULL)
		return;

	D3DXVECTOR3 Vec;

	Vec.x = (FLOAT)PosX;
	Vec.y = (FLOAT)PosY;
	Vec.z = (FLOAT)0.0f;

	D3DXMATRIX mat;
	D3DXVECTOR2 scaling(1.0f, 1.0f);
	D3DSURFACE_DESC desc;
	TextureInterface->GetLevelDesc(0, &desc);
	D3DXVECTOR2 spriteCentre;
	if(Align == 1)
		spriteCentre = D3DXVECTOR2((FLOAT)desc.Width / 2, (FLOAT)desc.Height / 2);
	else
		spriteCentre = D3DXVECTOR2(0, 0);
	D3DXVECTOR2 trans = D3DXVECTOR2(0, 0);
	D3DXMatrixTransformation2D(&mat, NULL, 0.0, &scaling, &spriteCentre, (FLOAT)Rotation, &trans);

	SpriteInterface->SetTransform(&mat);
	SpriteInterface->Begin(D3DXSPRITE_ALPHABLEND);
	SpriteInterface->Draw(TextureInterface, NULL, NULL, &Vec, 0xFFFFFFFF);
	SpriteInterface->End();
}
Esempio n. 5
0
BOOL dx9vid_init()
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface
	D3DCAPS9 d3dCaps;
	d3d->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps );
	d3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );

	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed               = TRUE;
	d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat       = d3ddm.Format;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
	d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;

	d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hwnd,
						D3DCREATE_SOFTWARE_VERTEXPROCESSING,
						&d3dpp, &d3ddev );

	// Create the screen texture
	D3DXCreateTexture( d3ddev, 256, 256, D3DX_FILTER_NONE, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &g_screenTex);

	// Create the screen sprite (ignores 3d perspective)
	D3DXCreateSprite( d3ddev, &g_screenSprite );

	// Scale our matrix to match the screen
	D3DXMatrixIdentity( &pTransform );
	spritePos = D3DXVECTOR2( 0.f, 0.f );
	rotCenter = D3DXVECTOR2( 0.f, 0.f);
	D3DXVECTOR2 vscale = D3DXVECTOR2( float(3.0f), float(3.0f));
	D3DXMatrixTransformation2D( &pTransform, NULL, 0.0f, &vscale, &rotCenter, 0.f, &spritePos );
	g_screenSprite->SetTransform(&pTransform);

	return TRUE;
}
Esempio n. 6
0
void CEnemy1::Render(ID3DXSprite* pSprite, CCamera* const pCamera)
{
	if (!this->IsEnable())
	{
		MATRIX matTransform;

		D3DXVECTOR2 anchorPoint = D3DXVECTOR2(this->GetWSrcRect() / 2.0f,
			this->GetHSrcRect() / 2.0f);

		D3DXVECTOR2 position_temp = pCamera->getPointTransform(
			this->position.x, this->position.y);

		D3DXMatrixTransformation2D(
			&matTransform,
			&anchorPoint, 0, &this->scale,
			&anchorPoint, 0,
			&D3DXVECTOR2(position_temp.x - anchorPoint.x,
				position_temp.y - this->GetHSrcRect()));
		pSprite->SetTransform(&matTransform);

		HR(pSprite->Draw(
			CEnemy1::texture, &this->sourceRect,
			0, 0, D3DCOLOR_XRGB(255, 255, 255)));
	}
}
Esempio n. 7
0
void Renderer::DrawComplex(Drawable *complex_obj, UINT &index, bool parent_visible) {
  if (!parent_visible) {
    index++;
  } else {
    // World transformation
    D3DXVECTOR2 pivot = {complex_obj->size().width / 2, 0};
    D3DXVECTOR2 scaling = {complex_obj->scale().width, complex_obj->scale().height};
    D3DXVECTOR2 moving = {complex_obj->position().x - Game::instance()->instance()->width() / 2,
                          complex_obj->position().y - Game::instance()->instance()->height() / 2};
    D3DXMATRIX matFinal;
    D3DXMatrixTransformation2D(&matFinal, &pivot, 1.0f, &scaling, &pivot, complex_obj->rotation(),
                               &moving);

    device_->SetTransform(D3DTS_WORLD, &matFinal);

    // Draw
    complex_obj->Draw(this, &index);

    // Reset world transformation
    D3DXMatrixIdentity(&matFinal);
    device_->SetTransform(D3DTS_WORLD, &matFinal);
  }
  for (const auto &drawable_obj : complex_obj->complex_list_) {
    DrawComplex(drawable_obj.get(), index, (complex_obj->visible() && parent_visible));
  }
}
Esempio n. 8
0
/** This function should mostly only be called by Draw() in the Tile class.  It renders any subset of the texture
	\param DestX The x-coordinate to render the texture.  This coordinate represents the top-left corner.
	\param DestY The y-coordinate to render the texture.  This coordinate represents the top-left corner.
	\param SrcX The x-coordinate of the subset of the texture to render.
	\param SrcY the y-coordinate of the subset of the texture to render.
	\param Width the width of the subset to render.
	\param Height the height of the subset to render.
	\param XScale the scale with which to render the texture.
	\param YScale the scale with which to render the texture.
	\param Color the color to consider transparent in the texture.
	\return TRUE if the texture is drawn successfully.
*/
bool Texture::draw(float destx, float desty, 
				  long srcx, long srcy, 
				  long width, long height, 
				  float scalex, float scaley,
				  Color color, const Vector2 * pcenter,
				  float angle) const
{
  if(!pTexture) 
	return false;

  if(width == 0) { width = nWidth; }
  if(height == 0) { height = nHeight; }

  // Set the source rectangle.
  RECT Rect;
  Rect.left = srcx;
  Rect.top  = srcy;
  Rect.right = Rect.left + width;
  Rect.bottom = Rect.top + height;
  
  D3DXMATRIX transform;
  D3DXMatrixTransformation2D(&transform, &D3DXVECTOR2(0, 0), NULL,
	  &D3DXVECTOR2(scalex, scaley), pcenter ? &D3DXVECTOR2(pcenter->x, pcenter->y) : NULL, 
	  angle, &D3DXVECTOR2(destx, desty));
  
  gGraphics.getSpriteRenderer()->SetTransform(&transform); 
  if(FAILED(gGraphics.getSpriteRenderer()->Draw(pTexture, &Rect, NULL, NULL, color)))
			return false;

  return true;
}
Esempio n. 9
0
	void Button::drawtexture(D3DCOLOR color)
	{
		D3DXMATRIX mat;
		D3DXVECTOR2 trans((float)getX(),(float)getY());
		D3DXVECTOR2 scale((float)getScaleX(),(float)getScaleY());
		D3DXMatrixTransformation2D(&mat,NULL,0,&scale,NULL,0,&trans);
		g_engine->getSpriteHandler()->SetTransform(&mat);

		//calculate frame position and size
		int fx = (this->getFrameCurrent() % this->getFrameColumns()) * this->getImage()->tile_width;
		int fy = (this->getFrameCurrent() / this->getFrameColumns()) * this->getImage()->tile_height;
		fx += (this->getFrameCurrent() % this->getFrameColumns()) * this->getImage()->tile_offset_x;
		fy += (this->getFrameCurrent() / this->getFrameColumns()) * this->getImage()->tile_offset_y;

		RECT srcRect;
		srcRect.left = fx;
		srcRect.top = fy;
		
		if(this->getScaleX()==1)
			srcRect.right = fx + this->getWidth();
		else
			srcRect.right = fx + this->getImage()->getWidth();
		
		if(this->getScaleY()==1)
			srcRect.bottom = fy + this->getHeight();			
		else
			srcRect.bottom = fy + this->getImage()->getHeight();			
		
		g_engine->getSpriteHandler()->Draw(this->getImage()->GetTexture(),&srcRect,NULL,NULL,color);

	}
Esempio n. 10
0
//
// --------------------------------------------------------
//  Renders the edit box and the internal text.
// --------------------------------------------------------
void DirectX::GUI::EditBox::render( LPD3DXSPRITE d3dsprite, const POINT* pos )
{
	// Compute absolute offset 
	int xpos = m_posX + pos->x; 
	int ypos = m_posY + pos->y;

	// Render edit box background sprite
	Matrix fieldTransform;
	float fieldScaleX = (float)m_sizeX / (float)(m_style->selectionBox.right - m_style->selectionBox.left);
	float fieldScaleY = (float)m_sizeY / (float)(m_style->selectionBox.bottom - m_style->selectionBox.top);
	D3DXMatrixTransformation2D( &fieldTransform, NULL, 0.0, &Vector2( fieldScaleX, fieldScaleY ), NULL, 
		NULL, &Vector2( (float)xpos, (float)ypos ) );

	// Render the properly positioned sprite
	d3dsprite->SetTransform( &fieldTransform );
	d3dsprite->Draw( m_style->spriteSheet.getImage( ), 
		&m_style->selectionBox, NULL, NULL, 0xFFFFFFFF );

	// Draw button text
	if( m_state&FOCUSED ) m_cursorPosition = m_text.insert( m_cursorPosition, '|' );
	Matrix iden; RECT textRect = { xpos, ypos, xpos+m_sizeX, ypos+m_sizeY };
	D3DXMatrixIdentity( &iden ); d3dsprite->SetTransform( &iden );
	m_style->font.getFont( )->DrawTextW( d3dsprite, m_text.c_str( ), -1, 
		&textRect, m_alignment, m_style->color );
	if( m_state&FOCUSED ) { std::wstring::iterator next = m_cursorPosition; next++; 
		m_cursorPosition = m_text.erase( m_cursorPosition, next ); }
}
Esempio n. 11
0
int OpticSprite::draw(LPD3DXSPRITE sprite, double time, D3DXCOLOR colour, double offsetX, double offsetY) {
	if(!this->animate) {
		sprite->Draw(texture, NULL, NULL, NULL, colour);
		return 1;
	}

	if(animation.lifetime() > time) {
		animation.updateState(aniState, time);
		colour = D3DXCOLOR(aniState.red, aniState.green, aniState.blue, colour.a < aniState.alpha? colour.a : aniState.alpha);
		float rotation = 6.28318531f * aniState.rotation;
		D3DXMATRIX mat, current;
		D3DXVECTOR2 scaling(aniState.scale_x, aniState.scale_y);
		D3DXVECTOR2 position(floor(((pResolution->width * aniState.position_x) - translateCentre.x) + offsetX),
							 floor(((pResolution->height * aniState.position_y) - translateCentre.y) + offsetY));
		D3DXMatrixTransformation2D(&mat, &transformCentre, 0.0f, &scaling, &transformCentre, rotation, &position);
		sprite->GetTransform(&current);
		mat *= current;
		sprite->SetTransform(&mat);
		
		HRESULT res;

		//Spritesheet rect calculations are slightly iffy thanks to the texture scaling (rounding errors)
		if(this->spritesheet) {
			int x = (width * currFrame) % surfaceDesc.Width;
			
			//Hacky workaround
			int diff = x - surfaceDesc.Width;

			if(abs(diff) <= 10) {
				x = 0;
			}
			//End of hacky workaround

			int y = height * currRow;
			RECT source;
			source.top = y;
			source.left = x;
			source.right = x + width;
			source.bottom = y + height;
			res = sprite->Draw(texture, &source, NULL, NULL, colour);
			sprite->SetTransform(&current);

			if(!advanceFrame(time, x, y)) {
				return 0;
			}
		} else {
			res = sprite->Draw(texture, NULL, NULL, NULL, colour);
			sprite->SetTransform(&current);
		}

		if(res != S_OK) {
			throw OpticSpriteException("Rendering sprite failed!");
		}

		return 1;
	}

	return 0;
}
Esempio n. 12
0
void CGameObject::Draw(LPD3DXSPRITE _spriteHandler,CCamera* _camera){
	D3DXMATRIX Scale;
	D3DXMatrixIdentity(&Scale);
	D3DXMatrixTransformation2D(&Scale, &D3DXVECTOR2(m_pos.x, m_pos.y), 0.0f, &D3DXVECTOR2(1.f, -1.f),NULL, 0.f, NULL);
	D3DXMatrixMultiply(&Scale,&Scale, &_camera->Get_ViewPort());
	_spriteHandler->SetTransform(&Scale);
	m_sprite->DrawSprite(_spriteHandler,D3DXVECTOR2(m_pos.x,m_pos.y));
}
Esempio n. 13
0
void CGame::RenderUIElements()
{
	if(!CGameFunction::IsRadarVisible() && m_bRadarVisibility) {
		// Clear the device
		m_bRadarVisibility = false;
		g_pCore->GetGraphics()->GetDevice()->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0),1.0f,0);
	}
	else {
		if(!CGameFunction::IsRadarVisible())
			return;

		m_bRadarVisibility = true;

		// Render Images
		float fX, fY, sX, sY;
		CIVScript_NativeInvoke::Invoke<unsigned int>(CIVScript::NATIVE_GET_VIEWPORT_POS_AND_SIZE, 3, &fX, &fY, &sX, &sY);

		D3DVIEWPORT9 viewport;
		g_pCore->GetGraphics()->GetDevice()->GetViewport(&viewport);
		g_pCore->GetGraphics()->GetSprite()->Begin(0);
		D3DXVECTOR2 spriteCentre = D3DXVECTOR2(0, 0);
		D3DXVECTOR2 trans= D3DXVECTOR2(viewport.Width * fX - 6.5, viewport.Height * fY - 6.5);

		D3DXMATRIX mat;
		D3DXVECTOR2 scaling2((viewport.Width * sX) / 990, (viewport.Height*sY) / 460);
		float rotation=0.0f;
		D3DXMatrixTransformation2D(&mat,NULL,0.0,&scaling2,&spriteCentre,rotation,&trans);

		g_pCore->GetGraphics()->GetSprite()->SetTransform(&mat);
		g_pCore->GetGraphics()->GetSprite()->Draw(g_pCore->GetGraphics()->m_pRadarOverlayTexture,NULL, NULL,&D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DCOLOR_ARGB(255,255,255,255));

		// Draw health bar
		float fxPos = viewport.Width * fX - 6.5;
		float fyPos = viewport.Height * fY - 6.5;
		;//g_pCore->GetGraphics()->

		float fWidth = viewport.Width/12.4;
		float fHeight = viewport.Height/50;

		D3DXVECTOR2 scaling3((viewport.Width * sX) / 1000, (viewport.Height*sY) / 460);
		CVector3 vecScreen = CVector3(trans.x, (trans.y+scaling3.y), 0.0f);
		vecScreen.fY += (viewport.Height/10)*2;
		
		if(m_pLocalPlayer && m_pLocalPlayer->IsSpawned()) {
			//g_pCore->GetGraphics()->DrawBox((vecScreen.fX + 4), (vecScreen.fY + 16), fWidth, fHeight, D3DCOLOR_ARGB(160, 0, 0, 0) );
			g_pCore->GetGraphics()->DrawBox(((vecScreen.fX + 6)), (vecScreen.fY + 18), (fWidth - 4), (fHeight - 4), D3DCOLOR_ARGB(120, 125, 157, 120) );
			g_pCore->GetGraphics()->DrawBox(((vecScreen.fX + 6)), (vecScreen.fY + 18), (((Math::Clamp( 0.0f, m_pLocalPlayer->GetHealth(), 720.0f ) * 100.0f) / 720.0f) / 100 * (fWidth - 4)), (fHeight - 4), D3DCOLOR_ARGB(255, 125, 157, 120) );
	
			vecScreen.fX += fWidth;
			//g_pCore->GetGraphics()->DrawBox((vecScreen.fX + 4), (vecScreen.fY + 16), fWidth, fHeight, D3DCOLOR_ARGB(160, 0, 0, 0) );
			g_pCore->GetGraphics()->DrawBox(((vecScreen.fX + 6)), (vecScreen.fY + 18), (fWidth - 4), (fHeight - 4), D3DCOLOR_ARGB(210, 0, 79, 96) );
			g_pCore->GetGraphics()->DrawBox(((vecScreen.fX + 6)), (vecScreen.fY + 18), (((Math::Clamp( 0.0f, m_pLocalPlayer->GetHealth(), 720.0f ) * 100.0f) / 720.0f) / 100 * (fWidth - 4)), (fHeight - 4), D3DCOLOR_ARGB(255, 0, 79, 96) );
		}

		g_pCore->GetGraphics()->GetSprite()->Flush();
		g_pCore->GetGraphics()->GetSprite()->End();
	}
}
//RenderImage(TetrisGame* game, int x, int y, D3DXCOLOR color,Texture* image) - used by many other functions
//to render the supplied image at the x and y position
void RenderImage(TetrisGame* game, int x, int y, D3DXCOLOR color,Texture* image)
{
	D3DXMATRIX mat;
	D3DXVECTOR2 trans(x,y);
	D3DXMatrixTransformation2D(&mat,NULL,0,NULL,NULL,NULL,&trans);
	g_engine->GetSpriteHandler()->SetTransform(&mat);

	g_engine->GetSpriteHandler()->Draw(image->GetTexture(),NULL,NULL,NULL,color);
}
	void Sprite::transform()
	{
		D3DXMATRIX mat;
		D3DXVECTOR2 scale((float)scaling,(float)scaling);
		D3DXVECTOR2 center((float)(width*scaling)/2, (float)(height*scaling)/2);
		D3DXVECTOR2 trans((float)getX(), (float)getY());
		D3DXMatrixTransformation2D(&mat,NULL,0,&scale,&center,(float)rotation,&trans);
		g_engine->getSpriteHandler()->SetTransform(&mat);
	}
Esempio n. 16
0
void CSprite::UpdateMatrix()
{
	D3DXVECTOR2 Pt;
	Pt.x = _pos.x - (_texture->getImgInfo().Width * _acp.x);
	Pt.y = _pos.y - (_texture->getImgInfo().Height * _acp.y);

	float radian = _degree * 3.141592f / 180.0f;

	D3DXMatrixTransformation2D(&_mat, &_acp, NULL, &_scale, &_acp, radian, &Pt);
}
//*****************************************************************************
// Renders a sprite based upon graphic image sprite data
//*****************************************************************************
void CGraphics::RenderGraphicModulate(GRAPHIC_IMAGE gi, int positionX, int positionY, int red, int green, int blue){
  CLog *pLog = CLog::Instance();
  if(gi.bValid == false)
    return;
  
  RECT rect;
  if(gi.frameMax > 1){//animated frames
    rect.left = gi.sourceX + (gi.frameCount * gi.width);
    rect.top = gi.sourceY;
    rect.right = rect.left + gi.width;//gi.sourceX + gi.width;// * 2;
    rect.bottom = gi.sourceY + gi.height;// * 2;
  }
  else{ //static frame
    rect.left = gi.sourceX;
    rect.top = gi.sourceY;
    rect.right = rect.left + gi.width;//gi.sourceX + gi.width;// * 2;
    rect.bottom = gi.sourceY + gi.height;// * 2;
  }
  if(NULL == m_pSprite)
    return;
  
  m_pSprite->Begin(D3DXSPRITE_ALPHABLEND);
  m_d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);


  //************************* EXPERIMENTATION *********************
  //sets the screen color
  
  m_d3ddev->SetRenderState(D3DRS_TEXTUREFACTOR, D3DCOLOR_XRGB(m_textureRed, m_textureGreen, m_textureBlue)); 
	m_d3ddev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); 
	m_d3ddev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
  //***************************************************************

  D3DXVECTOR2 pos;
  pos.x = static_cast<float>(positionX);
  pos.y = static_cast<float>(positionY);
  D3DXVECTOR2 scaling;
  scaling.x = gi.scale * gi.screenScale;
  scaling.y = gi.scale * gi.screenScale;
  D3DXVECTOR2 rotcenter;
  rotcenter.x = (rect.right - rect.left)/2 * gi.screenScale;
  rotcenter.y = (rect.bottom - rect.top)/2 * gi.screenScale;
  D3DXMATRIX mat;

  D3DXMatrixTransformation2D(&mat, NULL, 0.0, &scaling, &rotcenter, gi.angle, &pos);
  m_pSprite->SetTransform(&mat);  
  if(NULL != GetTexture(gi.fileID)){
    if(FAILED(m_pSprite->Draw(GetTexture(gi.fileID), &rect, NULL, NULL, D3DCOLOR_ARGB(gi.alpha , red, green, blue)) )){
    }
  }
  D3DXMatrixIdentity(&mat);
  m_pSprite->SetTransform(&mat);
  //m_pSprite->End();
}
Esempio n. 18
0
//=============================================================================
// Print text inside RECT using DirectX text format
// Return 0 on fail, height of text on success
// pre: spriteBegin()
// post: spriteEnd()
//=============================================================================
int TextDX::print(const std::string &str, RECT &rect, UINT format)
{
    if(dxFont == NULL)
        return 0;

    // Setup matrix to not rotate text
    D3DXMatrixTransformation2D(&matrix, NULL, 0.0f, NULL, NULL, NULL, NULL);
    // Tell the sprite about the matrix "Hello Neo"
    graphics->getSprite()->SetTransform(&matrix);
    return dxFont->DrawTextA(graphics->getSprite(), str.c_str(), -1, &rect, format, color);
}
Esempio n. 19
0
//-----------------------------------------------------------------------------
// Purpose: Init the Engine by setting the input module, graphics module,
//			the delta time (used to set the speed of the game) and the scale
//			matrix to put the game at the right size
//-----------------------------------------------------------------------------
void Engine::InitEngine(string name, int width, int height)
{
	m_InputModule = new InputModule(name, width, height);
	m_GraphicsModule = new GraphicsModule(m_InputModule);
	m_FramerateManager = new FramerateManager(100);


	// factor 1.4 of scale
	D3DXVECTOR2 scale(1.4f,1.4f);
	D3DXMatrixTransformation2D(&m_ScaleMatrix, NULL,0.0f,&scale, NULL, 0.0f, NULL);
}
Esempio n. 20
0
	//================================================================================
	//!	メソッド名	CTEXTURE_BASE::drawTexture
	//
	//	機能		描画(2D用)
	//	引数		inSprite	スプライトデバイス
	//				rcFrom		描画元矩形
	//				rcTo		描画先矩形
	//				fPosZ		Zバッファ
	//				*rot		回転位置オフセット
	//				angle		回転角度
	//				color		ディフューズ
	//	更新		2008/05/03	<新規>
	//================================================================================
	BOOL
	CTEXTURE_BASE::drawTexture(	CONST SPRITE	inSprite,
								RECT			rcFrom,
								RECT			rcTo,
								float			fPosZ,
								VEC2*			rot,
								float			angle,
								D3DCOLOR		color)
	{
	//-------------------------------------------------
	//	値の設定
	//-------------------------------------------------
		float	fSrcX	= float(rcFrom.right	- rcFrom.left);
		float	fSrcY	= float(rcFrom.bottom	- rcFrom.top);
		float	fDrawX	= float(rcTo.right		- rcTo.left);
		float	fDrawY	= float(rcTo.bottom		- rcTo.top);
		D3DXMATRIX		matDraw;										//!< 座標変換マトリックスの格納先
		D3DXVECTOR3		center(0.0f, 0.0f, 0.0f);						//!< 描画の基準値の設定
		D3DXVECTOR3		position(0.0f, 0.0f, fPosZ);					//!< 表示する位置を指定
		D3DXVECTOR2		draw(float(rcTo.left), float(rcTo.top));		//!< 描画先座標(演算前)
		D3DXVECTOR2		scale(fDrawX/fSrcX, fDrawY/fSrcY);				//!< スケーリング係数(倍率を指定)
		bool			bAlloc = false;
	//	回転値の確認
		if(	!rot)
		{
			rot		= new D3DXVECTOR2(fDrawX/2.0f, fDrawY/2.0f);
			bAlloc	= true;
		}

	//-------------------------------------------------
	//	スプライトの設定
	//-------------------------------------------------
		D3DXMatrixTransformation2D(&matDraw, NULL, 0.0f, &scale, rot, angle, &draw);
		if(	bAlloc)
		{
			SAFE_DELETE(rot);
		}
		inSprite->SetTransform(&matDraw);

	//-------------------------------------------------
	//	描画
	//-------------------------------------------------
		if(	FAILED(inSprite->Draw(texd_ptr->texture, &rcFrom, &center, &position, color)))
		{
			return	FALSE;
		}
		else
		{
			return	TRUE;
		}
	}
Esempio n. 21
0
void Sprite::Draw(LPD3DXSPRITE _Handler,D3DMATRIX _mtWorld, float _X,float _Y, int _Index,float _Depth,D3DXCOLOR _color)
{
	D3DXMATRIX MaTrix,mtFinal; //
	
	D3DXMatrixIdentity(&mtFinal);
	D3DXVECTOR2 MTTran (_X,_Y); 

	D3DXMatrixTransformation2D(&MaTrix,NULL,0,NULL,NULL,NULL,&MTTran);
	mtFinal = MaTrix*_mtWorld;
	_Handler->SetTransform(&mtFinal);

	_Handler->Draw(m_Image,&this->getRect(_Index),NULL,
		&D3DXVECTOR3(0,0,_Depth),_color);
}
Esempio n. 22
0
void CTDrawImpl::DrawFit( int iX, int iY, int iModuleID, int iGraphicID, int iWidth, int iHeight, D3DCOLOR color )
{
	CImageRes* pImageRes = (CImageResManager::GetSingleton()).GetImageRes( iModuleID );
	if( pImageRes == NULL )
	{
		assert( pImageRes && "Get ImageRes failed" );
		return;
	}

	stTexture* pTextureInfo = pImageRes->GetTexture( iGraphicID );
	stSprite* pSpriteInfo = pImageRes->GetSprite( iGraphicID );

	if( pTextureInfo == NULL )
	{
		assert( pTextureInfo && "Get TextureInfo failed" );
		return;
	}

	if( pSpriteInfo == NULL )
	{
		assert( pSpriteInfo  && "Get SpriteInfo failed");
		return;
	}

	HNODE hTexture = pTextureInfo->m_Texture;

	if( hTexture == NULL )
	{
		assert( hTexture && "Get Texture failed");
		return;
	}

	// Transform	
	D3DXMATRIX mat;	
	float fScaleWidth = (float)iWidth / (pSpriteInfo->m_Rect.right - pSpriteInfo->m_Rect.left);
	float fScaleHeight = (float)iHeight / (pSpriteInfo->m_Rect.bottom - pSpriteInfo->m_Rect.top);
	

	D3DXVECTOR2 scale(fScaleWidth, fScaleHeight );
	D3DXVECTOR2 pos( (float)iX,(float)iY );
	D3DXMatrixTransformation2D(&mat, NULL, NULL, &scale, NULL, NULL, &pos);

	::setTransformSprite( mat );

	::drawSprite( hTexture, 
		&( pSpriteInfo->m_Rect ),
		NULL,
		&D3DXVECTOR3( 0, 0 , 0 ),								
		color );
}
Esempio n. 23
0
D3DXMATRIX SUIPictureBox::TransformMatrixImage()
{
	D3DXMATRIX transformMatrix;

	if(picture->GetTarget())
	{
		D3DXMatrixTransformation2D(
		&transformMatrix, 
		&D3DXVECTOR2(PositionImage().x, PositionImage().y),
		0, 
		&D3DXVECTOR2((float)GetTexRect().Width / picture->GetTarget()->GetWidth(), 
			(float)GetTexRect().Height / picture->GetTarget()->GetHeight()),
		&D3DXVECTOR2(0, 0),
		0, 
		&D3DXVECTOR2(0, 0));
	}
	else
	{
		D3DXMatrixTransformation2D(
		&transformMatrix, 
		&D3DXVECTOR2(PositionImage().x, PositionImage().y),
		0, 
		&D3DXVECTOR2(1, 1),
		&D3DXVECTOR2(0, 0),
		0, 
		&D3DXVECTOR2(0, 0));
	}	

	if (isAbsoluteRender && father)
	{
		D3DXMATRIX fMatrix = TransformMatrix();
		D3DXMATRIX result = transformMatrix * fMatrix;
		return result;
	}

	return transformMatrix;
}
/** Use a given font object to draw text at location (x,y) in a certain color */
void DirectXStuff::fontPrint(LPD3DXFONT font, int x, int y, string text, D3DCOLOR color)
{
	//Figure out the text boundary first
	RECT Rect = {x, y, 0, 0};

	/** 
	int DrawText( LPD3DXSPRITE pSprite, LPCTSTR pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color );

	pSprite - the first parameter allows a sprite interface to be passed in. Setting this to NULL means Direct3D 
		will use its own internal sprite object to render the text. If you are doing lots of DrawText calls passing 
		your own sprite object can SPEED UP RENDERING SIGNIFICANTLY (Up to 4x - see font drawing optimisations).
	pString - this is the string to render. The type of string depends on your projects character set.
	Count -  the number of characters in the string. You can set this to the magic number -1 in order to specify that 
		Direct3D should count the characters itself. Note that this only works with null terminated strings.
	pRect - the rectangular area in which the text will be displayed. How the text is justified within this rectangle 
		depends on the next parameter:
	Format - allows you to specify some flags. This allows you to specify the justification of the text within the 
		rectangle plus some other options (see advanced).
	Color - the final parameter is the colour you want to render the text.
	As always you must release the D3DX interface before your program exits or on a device reset:

	*/
	//This call fills in values for rect (alternatively you could just fill in rect yourself)
	font->DrawText(this->spriteObj, text.c_str(), text.length(), &Rect, DT_CALCRECT, color);

	//Now print the text actually
	//Create vectors for matrix transformation (annoying)
	D3DXVECTOR2 scale(1, 1);
	D3DXVECTOR2 translate(x, y);
	D3DXVECTOR2 center((float)(Rect.right)/2, (float)(Rect.bottom));

	//The 2D transformation matrix and the function that actually sets the matrix values
	D3DXMATRIX mat;

	D3DXMatrixTransformation2D(
		&mat, //The matrix; note pass by reference 
		NULL, //scaling center point (not used)
		0, //scaling rotation value (not used)
		&scale, //scaling vector
		&center, //rotation / pivot center
		0, //rotation angle
		&translate //translation vector
	); 

	//Tell sprite object to use the matrix
	this->spriteObj->SetTransform(&mat);
	font->DrawText(this->spriteObj, text.c_str(), text.length(), &Rect, DT_LEFT, color);
}
Esempio n. 25
0
void Origin::RenderOneFrame()
{
	//
	pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
	pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
	pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

	//
	pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
	pD3DDevice->BeginScene();
	pSprite->Begin(D3DXSPRITE_DONOTSAVESTATE);

	//PBIGSCENENODE pOrigineSceneNodeP = pBigScene->GetOriginSceneNodeP();
	//helpRenderOneFrame(pOrigineSceneNodeP);
	
	D3DXMATRIX tramatrix;
	PDIRECT3DTEXTURE9 pTexture = NULL;
	for(RenderCursor cursor = pBigScene->GetStartRenderEntity();
		cursor != pBigScene->GetEndRenderEntity(); cursor++)
	{
		D3DXMatrixTransformation2D(&tramatrix, NULL, NULL, NULL, NULL, (*cursor)->GetAngle(), &((*cursor)->GetPosition()));
		pSprite->SetTransform(&tramatrix);
		pTexture = (*cursor)->GetTexture();
		if(pTexture != NULL)
		{
			pSprite->Draw(pTexture, NULL, NULL,
			&D3DXVECTOR3(-float((*cursor)->GetTextureWidth()) / 2, -float((*cursor)->GetTextureHeight()) / 2, 0.0),
			D3DCOLOR_RGBA(255, 255, 255, 255));
		}
		else
		{
			MessageBox(0, "RenderOneFrame() - NULL Texture", 0, 0);
		}
	}

	for(ParticalCursor cursor = pBigScene->GetStartParticalCursor();
		cursor != pBigScene->GetEndParticalCursor(); cursor++)
	{
		if( !(*cursor)->isDead())
			(*cursor)->render();
	}

	pSprite->End();
	pD3DDevice->EndScene();
	pD3DDevice->Present(0, 0, 0, 0);
}
Esempio n. 26
0
//=============================================================================
// Print text at x,y
// Return 0 on fail, height of text on success
// pre: spriteBegin()
// post: spriteEnd()
//=============================================================================
int TextDX::print(const std::string &str, int x, int y)
{
    if(dxFont == NULL)
        return 0;
    // set font position
    fontRect.top = y;
    fontRect.left = x;

    // Rotation center
    D3DXVECTOR2 rCenter=D3DXVECTOR2((float)x,(float)y);
    // Setup matrix to rotate text by angle
    D3DXMatrixTransformation2D(&matrix, NULL, 0.0f, NULL, &rCenter, angle, NULL);
    // Tell the sprite about the matrix "Hello Neo"
    graphics->getSprite()->SetTransform(&matrix);
    return dxFont->DrawTextA(graphics->getSprite(), str.c_str(), -1, &fontRect, DT_LEFT, color);
}
Esempio n. 27
0
bool cTexture::draw
( 
	long p_destX, long p_destY, 
	long p_srcX /*= 0*/, long p_srcY /*= 0*/, 
	long p_width /*= 0*/, long p_height /*= 0*/, 
	D3DCOLOR p_color /*= 0xffffffff*/,
	D3DXVECTOR2 *p_pRotationCenter /*= NULL*/,
	float p_angle /*= 0.0f*/, 
	float p_XScale /*= 1.0f*/, float p_YScale /*= 1.0f*/
)
{
	RECT rect;
	ID3DXSprite *pSprite;
	
	if(m_pTexture == NULL)
		return FALSE;
	if(m_pGraphics == NULL)
		return FALSE;
	if((pSprite = m_pGraphics->getSprite()) == NULL)
		return FALSE;
	
	if(!p_width)
		p_width = m_width;
	if(!p_height)
		p_height = m_height;
	
	rect.left = p_srcX;
	rect.top  = p_srcY;
	rect.right = rect.left + p_width;
	rect.bottom = rect.top + p_height;
	
	//D3DXVECTOR3 Center = D3DXVECTOR3(10, 10, 1);          // 材质的矩形区域的中心点
	D3DXVECTOR3 Position = D3DXVECTOR3((float)p_destX, (float)p_destY, 0);   // 画的位置
	
	pSprite->Begin(D3DXSPRITE_ALPHABLEND);
	D3DXVECTOR2 Scaling(p_XScale, p_YScale);                         // 縮放比例
	/*D3DXVECTOR2 RotationCenter( p_destX + p_width / 2,
								p_destY + p_height / 2 );*/
	D3DXMATRIX  Matrix;  // 坐标转换矩阵 
	D3DXVECTOR2 d3dx_vector2((float)p_destX, (float)p_destY);
	D3DXMatrixTransformation2D(&Matrix, &d3dx_vector2, 
		0.0, &Scaling, p_pRotationCenter, p_angle, 0 );
	pSprite->SetTransform(&Matrix);
	pSprite->Draw( m_pTexture, &rect, NULL, &Position, p_color);
	pSprite->End();
	return true;
}
/** Draw a transformed sprite; does all the matrix shit for you */
void DirectXStuff::spriteTransformDraw(LPDIRECT3DTEXTURE9 texture, int x, int y, int frameWidth, int frameHeight, D3DCOLOR color, int currentFrame, int columns, float rotation, float scaling)
{
	//Create 2D vectors for scale and translate values (indicate scale x-wise and y-wise)
	D3DXVECTOR2 scale(scaling, scaling);
	D3DXVECTOR2 translate(x, y);

	//Set center by dividing width and height by 2, take scaling into account
	D3DXVECTOR2 center((float)(frameWidth * scaling)/2, (float)(frameHeight * scaling)/2);

	//The 2D transformation matrix and the function that actually sets the matrix values
	D3DXMATRIX mat;

	D3DXMatrixTransformation2D(
		&mat, //The matrix; note pass by reference 
		NULL, //scaling center point (not used)
		0, //scaling rotation value (not used)
		&scale, //scaling vector
		&center, //rotation / pivot center
		rotation, //rotation angle
		&translate //translation vector
	); 

	//Tell sprite object to use the matrix
	spriteObj->SetTransform(&mat);

	//calculate frame location in source image (only useful if it's a spritesheet)
	int fx = (currentFrame % columns) * frameWidth;
	int fy = (currentFrame / columns) * frameHeight;
	RECT sourceRect = {fx, fy, fx + frameWidth, fy + frameHeight};

	//Draw the sprite frame; note we are not filling in pivot center or position because those are already set 
	//by the matrix
	spriteObj->Draw(texture, &sourceRect, NULL, NULL, color);

	/** More on spriteObj->Draw
	pSrcTexture - a pointer to the texture to be used, see textures
	pSrcRect - pointer to a rectangle defining the area of the texture to use or NULL for the whole texture
	pCenter- pointer to a 3D vector specifying the position in the sprite around which it can be rotated or 
		NULL for top left
	pTranslation - pointer to a 3D vector defining the screen position of the sprite. Note: in Direct3D 0,0 
		is the top left of the screen.
	Color - colour value that can be used to modulate the texture colours. A value of 0xFFFFFFFF maintains 
		the colour from the texture. Note: you can use the D3DCOLOR_COLORVALUE macro to create a D3DCOLOR 
		from RGB values.
	*/

}//end spriteTransformDraw
Esempio n. 29
0
//=============================================================================
// Draw the sprite described in SpriteData structure
// Color is optional, it is applied like a filter, WHITE is default (no change)
// Pre : sprite->Begin() is called
// Post: sprite->End() is called
// spriteData.rect defines the portion of spriteData.texture to draw
//   spriteData.rect.right must be right edge + 1
//   spriteData.rect.bottom must be bottom edge + 1
//=============================================================================
void Graphics::drawSprite(const SpriteData &spriteData, COLOR_ARGB color)
{
    if(spriteData.texture == NULL)      // if no texture
        return;

    // Find center of sprite
    D3DXVECTOR2 spriteCenter=D3DXVECTOR2((float)(spriteData.width/2*spriteData.scaleX),
                                        (float)(spriteData.height/2*spriteData.scaleY));
    // Screen position of the sprite
    D3DXVECTOR2 translate=D3DXVECTOR2((float)spriteData.x,(float)spriteData.y);
    // Scaling X,Y
    D3DXVECTOR2 scaling(spriteData.scaleX,spriteData.scaleY);
    if (spriteData.flipHorizontal)  // if flip horizontal
    {
        scaling.x *= -1;            // negative X scale to flip
        // Get center of flipped image.
        spriteCenter.x -= (float)(spriteData.width*spriteData.scaleX);
        // Flip occurs around left edge, translate right to put
        // Flipped image in same location as original.
        translate.x += (float)(spriteData.width*spriteData.scaleX);
    }
    if (spriteData.flipVertical)    // if flip vertical
    {
        scaling.y *= -1;            // negative Y scale to flip
        // Get center of flipped image
        spriteCenter.y -= (float)(spriteData.height*spriteData.scaleY);
        // Flip occurs around top edge, translate down to put
        // Flipped image in same location as original.
        translate.y += (float)(spriteData.height*spriteData.scaleY);
    }
    // Create a matrix to rotate, scale and position our sprite
    D3DXMATRIX matrix;
    D3DXMatrixTransformation2D(
        &matrix,                // the matrix
        NULL,                   // keep origin at top left when scaling
        0.0f,                   // no scaling rotation
        &scaling,               // scale amount
        &spriteCenter,          // rotation center
        (float)(spriteData.angle),  // rotation angle
        &translate);            // X,Y location

    // Tell the sprite about the matrix "Hello Neo"
    sprite->SetTransform(&matrix);

    // Draw the sprite
    sprite->Draw(spriteData.texture,&spriteData.rect,NULL,NULL,color);
}
Esempio n. 30
0
void CSprite::DrawFlipY(float x, float y)
{
	D3DXMATRIX old_matrix;
	kSpriteHandler->GetTransform(&old_matrix);

	D3DXMATRIX new_natrix;
	D3DXVECTOR2 center = D3DXVECTOR2(x, y);
	D3DXVECTOR2 rotate = D3DXVECTOR2(1, -1);

	D3DXMatrixTransformation2D(&new_natrix, &center, 0.0f, &rotate, NULL, 0.0f, NULL);
	D3DXMATRIX finalMatrix = new_natrix * old_matrix;
	kSpriteHandler->SetTransform(&finalMatrix);

	Draw(x, y);

	kSpriteHandler->SetTransform(&old_matrix);
}