| Platform SDK: DirectX |
This section details how to draw a transformed sprite by using the Direct3DX utility library.
The following code example builds and draw a sprite that had been transformed using scaling:
D3DXMATRIX matScale;
D3DXMatrixScaling(&matScale, m_fScaleCurrent, m_fScaleCurrent, 1);
D3DXMATRIX matTransform;
D3DXBuildSpriteTransform(&matTransform, &rectViewport, m_fRotationCurrent);
D3DXMATRIX mat;
mat = matScale * matTransform;
hr = ::D3DXDrawSpriteTransform(
m_ptex, // texture
m_pd3dDevice, // 3-D device
&mat, // matrix
(BYTE)m_dwAlpha,// alpha
&srcRect // source sub-rect
);
The following code example builds and draws a sprite that has been transformed using rotation, translation, and scaling:
D3DXMATRIX matScaleToSize;
D3DXMatrixScaling(&matScaleToSize, 64, 48, 1);
D3DXMATRIX matRotate;
D3DXMatrixRotationZ(&matRotate, m_fRotationCurrent);
D3DXMATRIX matTranslate;
D3DXMatrixTranslation(&matTranslate, (float)pointDest.x, (float)pointDest.y, 0);
D3DXMATRIX matScale;
D3DXMatrixScaling(&matScale, m_fScaleCurrent, m_fScaleCurrent, 1);
D3DXMATRIX mat;
mat = matScaleToSize * matRotate * matScale * matTranslate;
hr = ::D3DXDrawSpriteTransform(
m_ptex, // texture
m_pd3dDevice, // 3-D device
&mat, // matrix
(BYTE)m_dwAlpha,// alpha
&srcRect // source sub-rect
);