Sign in to follow this  
Followers 0
MatthewDiaz

Rotating a Sprite Around Its Center Directx11

2 posts in this topic

Here is my current WorldMatrix function

[CODE]
XMMATRIX GameSprite::GetWorldMatrix( )
{
//position is the pixel position of the sprite on screen
XMMATRIX translation = XMMatrixTranslation( position_.x, position_.y, 0.0f );
XMMATRIX rotationZ = XMMatrixRotationZ(rotation_ );
XMMATRIX scale = XMMatrixScaling( scale_.x, scale_.y, 1.0f );
return translation * rotationZ * scale;
}
[/CODE]

When changing the radians for the rotation_ my sprite does rotate but around the bottom left of the screen.

I was guessing that I would need to use XMMatrixRotationNormal() to get the results I want but through experimentation I still come up with the same results.

For example I tried

[CODE]
XMMATRIX rotationZ = XMMatrixRotationNormal(tempvector, rotation_ );
//with defiintions like these
XMVECTOR tempvector = {0.0f, 0.0f, 1.0f};//Same as RotationZ()
XMVECTOR tempvector = {position_.y, position_.x, 1.0f};//Wierd results
[/CODE]


Could anyone tell me how to move the origin for the z-axis to the center of my sprite?
0

Share this post


Link to post
Share on other sites
It's been a while since I've done work with matrices but...

Try changing:
[CODE]
return translation * rotationZ * scale;
[/CODE]

To:
[CODE]
return rotationZ * translation * scale;
[/CODE]


It seems like you're rotating then translating in the direction of the rotation.
You want to translate it to its intended position first, then rotate it to the desired orientation.

Could be wrong, but it's pretty quick to test... I'm also not sure about the ordering on the scalar matrix. It might be fine where it is, I'd have to dig up some old code to verify. Edited by SeiryuEnder
1

Share this post


Link to post
Share on other sites
[quote name='SeiryuEnder' timestamp='1336008047' post='4936927']
It's been a while since I've done work with matrices but...

Try changing:
[CODE]
return translation * rotationZ * scale;
[/CODE]

To:
[CODE]
return rotationZ * translation * scale;
[/CODE]


It seems like you're rotating then translating in the direction of the rotation.
You want to translate it to its intended position first, then rotate it to the desired orientation.

Could be wrong, but it's pretty quick to test... I'm also not sure about the ordering on the scalar matrix. It might be fine where it is, I'd have to dig up some old code to verify.
[/quote]


Problem solved, thank you. That worked.
0

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  
Followers 0