Sign in to follow this  
Aikavanak

Rotating a D3DXSprite before Scaling?

Recommended Posts

Hello everyone, I'm using the updated D3DXSprite and D3DXMatrixTransform2D to draw the tiles of a 2D isometric map. I'd like these tiles to be in a 2:1 ratio (more specifically, 64x32 pixels), and I'm mapping square textures to to sprite. But, when I set up my matrix to rotate the tile by 45 degrees and scale the x axis by 2, I end up with a rotated rectange, as opposed to a stretched diamond, if you can visualize that. It's as if D3D is scaling the sprite before it's rotating it, and I want to rotate it before its scaled. Is it possible to do this with D3DXMatrixTransform2D, or do I have to set up my own matrices? Here's the code to draw a single tile: bool DrawTiles() { D3DXVECTOR2 vCenter((float)(TileWidth/2),(float)(TileHeight/2)); D3DXVECTOR2 vScale(2.0f,1.0f); float fRot=D3DXToRadian(45.0f); D3DXVECTOR2 vTrans(0.0f,0.0f); D3DXMATRIX matTransform; D3DXMatrixTransformation2D(&matTransform,&vCenter,NULL,&vScale,&vCenter, fRot,&vTrans); if(FAILED(m_pD3DXS->SetTransform(&matTransform))) return false; if(FAILED(m_pD3DXS->Begin(NULL))) return false; if(FAILED(m_pD3DXS->Draw(Texture.GetTexture(),NULL, NULL,NULL, D3DCOLOR_RGBA(255,255,255,255)))) return false; if(FAILED(m_pD3DXS->End())) return false; Thanks!

Share this post


Link to post
Share on other sites
I believe you are looking for the ScalingRotation factor which you have set to NULL.

otherwise you can build your own matrix set (if you want more control):

MWorld = MRot * MScale * M(other transforms)

Also if that bugs you consider using a matrix-stack. ID3DXMatrixStack interface.

Share this post


Link to post
Share on other sites
dhanji,

You were right, after playing with the ScalingRotaion value a little (the documentation didn't help at all), I found that setting it to D3DXToRadian(-45.0f) gave the isometric shape I was looking for.

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this