# Rotate UV

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

## Recommended Posts

Hi,

I'm currently learning d3d11 including the basics of texturing/ UV updating etc.

In the current exercise I'm trying to rotate a texture on each face of a cube (6 faces), around the center of the texture/ aka face. The UV's range nicely from 0.0 to 1.0 and I'm using 'WRAP' as address mode.

To achieve the result I'm multiply the UV's by a texture transform matrix.

Here's my attempt:

	XMMATRIX zRotMat = XMMatrixRotationZ(XMConvertToRadians(zRot));
XMMATRIX centerMat = XMMatrixTranslation(0.5f, 0.5f, 0.0f);
XMMATRIX scaleMat = XMMatrixScaling(1.0f, 1.0f, 1.0f);

//	XMStoreFloat4x4(&mTexTransform, scaleMat * zRotMat * centerMat);
XMStoreFloat4x4(&mTexTransform, centerMat * zRotMat);



So far I've found out that just doing a rotation, doesn't give the expected result, because the rotation then uses 0.0 as origin (in my case the left top corner of the cube face). So I tried to do a translation of 0.5f on both X and Y, because the cube has the dimensions of 1.0 x 1.0 x 1.0.

The result of this is also that the origin of the rotation is not the center of both the cube face and/or the texture.

I think I'm overseeing something, but can't figure it out yet.

Any input is appreciated.

Edited by cozzie

##### Share on other sites
Try this

        XMMATRIX zRotMat = XMMatrixRotationZ(XMConvertToRadians(zRot));
XMMATRIX centerMat = XMMatrixTranslation(0.5f, 0.5f, 0.0f);
XMMATRIX centerInverse = XMMatrixTranslation(-0.5f, -0.5f, 0.0f);

XMStoreFloat4x4(&mTexTransform, centerMat * zRotMat * centerInverse);

If that doesn't work, then switch the order of centerMat and centerInverse to be

	XMStoreFloat4x4(&mTexTransform, centerInverse * zRotMat * centerMat);


##### Share on other sites

Thanks, got it.

When I read your reply it 'felt', first move to the center, rotate and then move back to the initial coordinate.

Working like a charm now, with the 2nd option (inverse * zRot * center).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015434
×