Skip to main content
gamedev.net
🔒 Locked

Texture Rotation

Started by pawel_p 1 reply 500+ views
Original Post
pawel_p
pawel_p
Hi, how can I rotate a texture around 0,5/0,5 (the Center) ? I have a Quad(4Vertices) and a Texture on it, now I want the texture to rotate. i havethe folowing func {Delphi, DirectX9} Procedure TTextureList.SetTextureMatrix(XFactor : double = 1; YFactor : double = 1; XPos : double = 0; YPos : double = 0; Angle : double = 0); var mat, matOut,mat1 : TD3DMatrix; Begin mat := D3DX9.D3DXMatrixIdentity; mat._00 := XFactor; mat._01 := 0.00; mat._02 := 0.00; mat._03 := 0.00; mat._10 := 0.00; mat._11 := -YFactor; mat._12 := 0.00; mat._13 := 0.00; mat._20 := XPos; mat._21 := YPos; mat._22 := 0.00; mat._23 := 0.00; mat._30 := 0.00; mat._31 := 0.00; mat._32 := 1.40; mat._33 := 0.00; D3DXMatrixRotationZ( mat1, Angle); D3DXMatrixMultiply(matOut, mat, mat1); WITH Engine.Scene.D3DDev9 DO Begin SetTransform( D3DTS_TEXTURE0, matOut ); SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU ); end; end; How have I to modify it to specify also a RotationCenter?
S1CA
S1CA
For your texture transform do the following:

TRANS = T1 * R * T2

Where:

R is your rotation matrix,

T1 is a translation matrix which translates U and V by -0.5

T2 is a translation matrix which translates U and V by +0.5

i.e. you translate the centre of rotation (origin), rotate, and translate back. The reason is that your rotation is around the 0,0 point which is the top left of the texture. Translating the origin before you rotate and translating it back afterwards is the solution.


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
pawel_p
pawel_p
I Try

D3DXMatrixRotationZ( matRot, Angle);
D3DX9.D3DXMatrixTranslation(matPos,-0.5,-0.5,0);
D3DXMatrixMultiply(matOut, matPos, matRot);

D3DX9.D3DXMatrixTranslation(matPos,0.5,0.5,0);
D3DXMatrixMultiply(matOut,matOut, matPos);

but it seems not to work... and I have no Idea why...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.