Texture Coordinate Transformations (rotate? scale?)

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

Recommended Posts

After some excessive experimenting with lightmaps and stuff, im trying to use matrices to transform the 2D texture coordinates on my vertices. RendersStates, Vertex formats and TextureStageStates are not my problem here, but I dont know how to rotate or scale my texture coordinates. Im using C#, but due to lack of Managed documentation, let me quote what the C++ docs have to say about texture coordinate transformations;
// M is a D3DMATRIX being set to translate texture
// coordinates in the U and V directions.
//      1   0  0  0
//      0   1  0  0
//      du dv  1  0 (du and dv change each frame)
//      0   0  0  1

D3DMATRIX M = D3DXMatrixIdentity(); // declared in d3dutil.h
M._31 = du;
M._32 = dv;


Appearently, there are no functions (like Matrix.Translate, Matrix.Rotate and Matrix.Scaling) to make matrices for texture coordinates. The existing functions are all for 3D transformations and these do not work for texture coordinates, even Matrix.Transformation2D doesnt work. So, how do I scale and rotate my texture coordinates?

Share on other sites
3D transformations DO work !

Matrix.Translate2d (du = x, dv = y) =//     1   0  0  0//     0   1  0  0//     du dv  1  0 (du and dv change each frame)//     0   0  0  1

FinalMatrix = Matrix.Rotate * Matrix.Scaling * Matrix.Translate2d

(note: Remember to multiply in the above order)

Share on other sites
Are you saying I should position by setting M31 and M32 manually and rotate/scale with the standard methods? Because there is no Matrix.Translate2D method, there is only Matrix.Transformation2D but it does not give the appropriate result.

Share on other sites
Yes, set M31 and M32 manually and rotate/scale with the standard methods :)

(set M31 and M32 manually = write a new function = Translate2d)

Share on other sites
Thanks Mythar, that worked! Odd how MS chose to use different matrix entries for positioning texture coordinates than for vertex coordinates... but im sure theres a reason for that.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 10
• 11
• 37
• 12
• 12
• Forum Statistics

• Total Topics
631414
• Total Posts
2999958
×