Sign in to follow this  
cozzie

Rotate UV

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 this post


Link to post
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 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