• Advertisement
Sign in to follow this  

Texture Coordinate Transformations (rotate? scale?)

This topic is 4508 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

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


Link to post
Share on other sites
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)

Share this post


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


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


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

Share this post


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

  • Advertisement