Archived

This topic is now archived and is closed to further replies.

Rasm

ID3DXSprite::Draw changed?

Recommended Posts

Rasm    283
Okay, I wrote a 2d engine a while back on directx 8 and had everything I wanted in it. I loved all the new functionality that direct3d provided for sprites. Anyway, I put the engine away for awhile and just recently I got the urge to do something with it again. I downloaded the directx 9 sdk summer updated version and installed it. I got out my engine and compiled. Much to my surprise, 4 errors. One error for each version of my sprite draw function. I checked the sdk documents under "converting to directx 9" and found no mention about a change to the ID3DXSprite::Draw() function. I did a search for it and found out they did change it. It is now...
HRESULT Draw(LPDIRECT3DTEXTURE9 pTexture,
CONST RECT *pSrcRect,
CONST D3DXVECTOR3 *pCenter,
CONST D3DXVECTOR3 *pPosition,
D3DCOLOR Color);
 
Instead of..
ID3DXSprite::DrawHRESULT Draw(  LPDIRECT3DTEXTURE8 pSrcTexture,
CONST RECT* pSrcRect,
CONST D3DXVECTOR2* pScaling,
CONST D3DXVECTOR2* pRotationCenter,
FLOAT Rotation,
CONST D3DVECTOR2* pTranslation,
D3DCOLOR Color);
 
Now, I had no problem changing the number of parameters and converting to D3DXVECTOR3 but what I want to know is where the heck did the rotation parameter go? How am I supposed to rotate my sprites? I checked the ID3DXSprite interface and saw nothing. Am I not seeing something? I''m confused and would be glad to get this cleared up. Thanks.

Share this post


Link to post
Share on other sites
foofightr    130
Look up ID3DXSprite::SetTransform . You have to call it before every sprite you render. Compose a matrix with translation, scaling and rotation (around Z axis).

I noticed that the "center" parameter doesn''t do anything. That is to say I passed in bogus values like -42464,767765 and it would not affect rendering. The "position" is actually the anchor you want to rotate the sprite around. It''s in negative numbers though, for example for a 64x64 sprite you would pass in (-32,-32) to rotate it around its center.

Share this post


Link to post
Share on other sites
Rasm    283
Thank you very much foofightr.
You definately set me in the right direction. I browsed a bit more through the documentation and found a handy dandy function that pretty much does everything the old Draw function did.

D3DXMatrixTransformation2D()

I basically created two D3DXMATRIX instances, one for the current transformation state and one for the new transformation.
I called ID3DXSprite::GetTransform() and passed it the matrix instance for the current transform. Then I called D3DXMatrixTransformation2D() and passed it the new matrix transform. I simply filled it out with all the data i needed using traditional 2d vectors. Then after calling draw, I just SetTransform() the old one back allowing me to call Draw() using my other drawbitmap functions without messing with rotation. Also, I can do scaling with the same function like the old DirectX8 sprite draw() as a bonus. I believe microsoft should have really mentioned this in the changes and give a brief explanation of how to get the same functionality (ie Create matrix, then SetTransform()). Oh well, I hope this helps someone else who had the same problem.

Oh yeah, a code visual...

D3DXMATRIX rotmatrix, oldmatrix;
sprite->GetTransform(&oldmatrix);

D3DXMatrixTransformation2D(&rotmatrix,...);
sprite->SetTransform(&rotmatrix);

sprite->Draw(src,NULL,NULL,NULL,D3DCOLOR_ARGB(255,255,255,255));
sprite->SetTransform(&oldmatrix);

Share this post


Link to post
Share on other sites