Sign in to follow this  

ID3DXSprite Rotation Problems - Rotates along top left corner.

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, Trying to get a small sprite engine up with the ID3XSprite Interface, but I'm having an issue with rotations. No matter where I put the sprite, it's always rotating about the top-left corner of the screen. What I mean is, that it rotates around the top left corner of the screen in a giant circle. So you only see a 'quarter' of the rotation around the top-left corner because the other 3 quarters it is off the screen. How can I make it rotate about its own origin, rather than the top-left corner's origin? Heres my relevant code:
			D3DXMATRIX matRotation;

			// Degrees x (PI / 180)
			D3DXMatrixRotationZ(&matRotation, (fDegrees * (D3DX_PI / 180)));

			D3DXVECTOR3 vCentre = D3DXVECTOR3(16.0f, 16.0f, 0.0f);
			D3DXVECTOR3 vPosition = D3DXVECTOR3(64.0f, 64.0f, 0.0f);

			pSprite->Begin(0);
				pSprite->SetTransform(&matRotation);
				pSprite->Draw(pPlayerTexture, NULL, &vCentre, &vPosition, 0xFFFFFFFF);
			pSprite->End();

fDegrees starts at 0, and continually increases. So how can I make the origin of the rotation the middle of the sprite itself? I thought thats what vCentre would do, but apparently not. If I change vPosition to something smaller or bigger, it only increases the width of the circle rotation. ie, if I make it 128 , 128 it'll rotate around the top-left corner in a bigger circle. What do I have to do to make it rotate about itself and not the top-left origin?

Share this post


Link to post
Share on other sites
Cheers mate! I used D3DXMatrixTransformation2D instead, works like a charm.

For completeness sake, heres the complete code incase anyone comes lookin:


D3DXVECTOR2 vCentre2D = D3DXVECTOR2(16.0f, 16.0f);
D3DXVECTOR2 vPosition2D = D3DXVECTOR2(64.0f, 64.0f);

D3DXMATRIX matRotation;

// Degrees x (PI / 180)
D3DXMatrixTransformation2D(&matRotation, NULL, NULL, NULL, &vCentre2D, (fDegrees * (D3DX_PI / 180)), &vPosition2D);

//D3DXMatrixRotationZ(&matRotation, (fDegrees * (D3DX_PI / 180)));

pSprite->Begin(0);
pSprite->SetTransform(&matRotation);
pSprite->Draw(pPlayerTexture, NULL, NULL, NULL, 0xFFFFFFFF);
pSprite->End();

Share this post


Link to post
Share on other sites

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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