Sign in to follow this  
CodeImp

Texture Coordinate Transformations (rotate? scale?)

Recommended Posts

CodeImp    565
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
Mythar    138
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
CodeImp    565
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
Mythar    138
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
CodeImp    565
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this