Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Solution to DirectX9 Rotate Sprites

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 Crowbar   Members   

109
Like
1Likes
Like

Posted 31 January 2013 - 11:28 PM

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: http://www.gamedev.net/topic/520506-sprite-rotation/ was helpful, but I still had a lot of work to do.

 

Code:

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);

 

Hope this helps,

 

Crowbar






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.