• Content count

  • Joined

  • Last visited

Community Reputation

109 Neutral

About Crowbar

  • Rank
  1. Hello,   After a very difficult time trying to deal with the whole "scaling rotating and translating a sprite around its center (the translation part being the difficult part) I thought I'd post my solution to the benefit of anyone who needs to do the same.   This old post: was helpful, but I still had a lot of work to do.   Code: [source]D3DXMATRIX mat, matCenter, matRot, matScale, matTrans; //center: D3DXMatrixIdentity(&matCenter); matCenter(3, 0) = -64;//x trans matCenter(3, 1) = -64;//y trans matCenter(3, 2) = 0;//z trans //init D3DXMatrixIdentity(&matScale); matScale._11 = 1; matScale._22 = 1; //init D3DXMatrixIdentity(&matRot); D3DXMatrixRotationZ(&matRot, D3DXToRadian(180.0f)); D3DXMatrixIdentity(&matTrans); matTrans(3, 0) = 400;//x trans matTrans(3, 1) = 400;//y trans matTrans(3, 2) = 0;//z trans //init final matrix D3DXMatrixIdentity(&mat); //Multiply them together: D3DXMatrixMultiply(&mat,&mat,&matCenter);//This line is the key, translating the image -half of its width and height makes all the other operations happen around it's center. D3DXMatrixMultiply(&mat,&mat,&matRot); D3DXMatrixMultiply(&mat,&mat,&matScale); D3DXMatrixMultiply(&mat,&mat,&matTrans); d3dspt->SetTransform(&mat); d3dspt->Draw(texture, NULL, NULL, NULL, D3DCOLOR_ARGB(255,50, 255, 255)); //reset matrix so it doesn't modify other sprites: D3DXMatrixIdentity(&mat); //reset matrix so it doesn't modify other sprites: d3dspt->SetTransform(&mat);[/source]   Hope this helps,   Crowbar