Texture Coordinate Transformations (rotate? scale?)

Started by
3 comments, last by CodeImp 18 years, 5 months ago
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?
Kind regards,
Pascal van der Heiden

CodeImp - My trademark and website
Advertisement
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)
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.
Kind regards,
Pascal van der Heiden

CodeImp - My trademark and website
Yes, set M31 and M32 manually and rotate/scale with the standard methods :)

(set M31 and M32 manually = write a new function = Translate2d)
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.
Kind regards,
Pascal van der Heiden

CodeImp - My trademark and website

This topic is closed to new replies.

Advertisement