示例#1
0
BOOL cTexture::Blit(long DestX, long DestY,                   \
                    long SrcX, long SrcY,                     \
                    long Width, long Height,                  \
                    float XScale, float YScale,               \
                    D3DCOLOR Color)
{
  RECT Rect;
  ID3DXSprite *pSprite;

  if(m_Texture == NULL)
    return FALSE;
  if(m_Graphics == NULL)
    return FALSE;
  if((pSprite = m_Graphics->GetSpriteCOM()) == NULL)
    return FALSE;

  if(!Width)
    Width = m_Width;
  if(!Height)
    Height = m_Height;

  Rect.left = SrcX;
  Rect.top  = SrcY;
  Rect.right = Rect.left + Width;
  Rect.bottom = Rect.top + Height;

  if(FAILED(pSprite->Draw(m_Texture,&Rect,NULL, NULL,Color)))
    return FALSE;
  return TRUE;
}
示例#2
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;
}