Hello guys, this is my first post in this forum. So, I am maintaining an old game, written in C++ and using DirectX9b. In order to use shader model 3 I decided to update the source code to Directx9c. The issue I am trying to fix right now is exactly what the title suggests.
To make a long story short, here is the function I am currently using to replace the old functionality:
HRESULT SpriteDrawFix(
LPD3DXSPRITE pSprite, // The sprite
LPDIRECT3DTEXTURE9 pSrcTexture, // The texture to draw.
CONST RECT* pSrcRect, // The src rect
CONST D3DXVECTOR2* pScaling, // Scaling
CONST D3DXVECTOR2* pRotationCenter, // The rotation center if rotation is used.
FLOAT Rotation, // Rotation in radians.
CONST D3DXVECTOR2* pTranslation, // Translation, i.e. moving the object to this place.
D3DCOLOR Color) // Color to module the image pixels.
{
D3DXVECTOR3 vScale = pScaling != nullptr ? D3DXVECTOR3{ pScaling->x, pScaling->y, 1 } : D3DXVECTOR3{ 1, 1, 1 };
D3DXVECTOR3 vCenter = pRotationCenter != nullptr ? D3DXVECTOR3{ pRotationCenter->x, pRotationCenter->y, 0 } : D3DXVECTOR3{ 0, 0, 0 };
D3DXVECTOR3 vTrans = pTranslation != nullptr ? D3DXVECTOR3{ pTranslation->x, pTranslation->y, 0 } : D3DXVECTOR3{ 0, 0, 0 };
D3DXMATRIXA16 s, r, t, total;
D3DXMatrixScaling(&s, vScale.x, vScale.y, 1);
D3DXMatrixRotationZ(&r, Rotation);
D3DXMatrixTranslation(&t, vTrans.x + vCenter.x * vScale.x, vTrans.y + vCenter.y * vScale.y, 0);
total = s * r * t;
pSprite->SetTransform(&total);
pSprite->Begin(D3DXSPRITE_ALPHABLEND);
HRESULT hr = pSprite->Draw(pSrcTexture, pSrcRect, &vCenter, nullptr, Color);
pSprite->End();
return hr;
}
It works for most cases, however, there seems to be a problem with rotation. This screenshot speaks for itself:
With Directx9b and using the old method, this renders as expected. I would appreciate it if someone knows what causes this bug or how the original method was implemented. Thanks in advance.
PS: I just noticed IDirectXSprite never existed, well, you got the picture anyway.