Jump to content
  • Advertisement
Sign in to follow this  
cozzie

Rotate UV

This topic is 1117 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,

 

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
Advertisement
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

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!