Texture Coords Translation

Started by
10 comments, last by Evil Steve 14 years, 1 month ago
Hi Everyone! I'm trying change the texture coords on an object and I'm having trouble doing this using D3DXMatrixTranslation() with the code below:


m_d3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

D3DXMATRIX matTrans;
D3DXMatrixIdentity(&matTrans);
D3DXMatrixTranslation(&matTrans,66.6f,66.6f,0.0f);

m_d3dDevice->SetTransform( D3DTS_TEXTURE0, &matTrans );

Test.Render();
However, the following code works fine:

m_d3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );

D3DXMATRIX matTrans;
D3DXMatrixIdentity(&matTrans);

matTrans._31 = 66.6f;
matTrans._32 = 66.6f;

m_d3dDevice->SetTransform( D3DTS_TEXTURE0, &matTrans );
Does anyone have any ideas why D3DXMatrixTranslation() is not working?? Any help would be greatly appreciated! Many Thanks David
Advertisement
I'm still having touble with this. However, it's very strange as both D3DXMatrixRotationZ() and D3DXMatrixScaling() work fine.
Any Ideas Anyone?
David
Both bits of code should produce the exact same result. Have you tried comparing the generated matrices to see what the difference is?
Thanks for the reply Evil Steve!
It's Messing up for some reason as you can see:
D3DXMatrixTranslation(&matTrans,66.6f,66.6f,0.0f);
1.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
66.6 66.6 0.0 1.0

What It Should Be:
1.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0
66.6 66.6 1.0 0.0
0.0 0.0 0.0 1.0

Any Ideas Why Anyone??
Thanks
David
Hi,

The D3DXMatrixTranslation routine is working with 4x4 matrices where the translation is stored in different elements, as you have already noticed.

The texture coordinate transform function expects you to provide a 4x4 matrix where only the 3x3 part is used.

Hope you understand.

Best regards!

For reference the d3dmatrix structure which d3dxmatrix inherits:

typedef struct _D3DMATRIX {    union {        struct {            float        _11, _12, _13, _14;            float        _21, _22, _23, _24;            float        _31, _32, _33, _34;            float        _41, _42, _43, _44;        };        float m[4][4];    };} D3DMATRIX;
any vector you want to transform with a translation matrix must be passed to transform function in [x,y,z,1.0] 4 dimensional vector thus you get

1*x + 0*y + 0*z + 1*66.6f=translatedvec.x;

0*x + 1*y + 0*z + 1*66.6f=translatedvec.y;

0*x + 0*y + 1*z + 1*66.6f=translatedvec.z;

the translation part of matrix is stored as a 4th column allways (row in dx case).
the 1-3*1-3 portion of matrix is for rotation component.

In case you transform direction vectors(normalized vectors) not position vectors,
you do not use [vector,1.0] but [vector,0.0] input vector.
You guys are going over my head here. :) What exactly do I need to do to get the matrix in a format that can be translated using the normal function?

Thanks Guys!
David

Hi,

sorry for being too hard to understand.

What I meant to say that you cannot use D3DXMatrixTranslation in this case since it will place the translation in the elements matTrans._41,matTrans._42,matTrans._43.

The texture transformation matrix must have the translation in the elements matTrans._31,matTrans._32.

I hope you understand.

Best regards!
Quote:Original post by kauna
The texture coordinate transform function expects you to provide a 4x4 matrix where only the 3x3 part is used.
Really? Where does it say that? I can only find a reference to "Direct3D devices can transform the texture coordinates for vertices by applying a 4x4 matrix."

In any case - this is another reason to use vertex shaders; you have full control over what size of matrix you pass in [wink]
Quote:Original post by Evil Steve
Really? Where does it say that? I can only find a reference to "Direct3D devices can transform the texture coordinates for vertices by applying a 4x4 matrix."


Another thread on this matter and here is an example of applying texture translation on Direct3d mobile.

I also suggest using the vertex shaders instead of fixed function pipeline.

Regards!

This topic is closed to new replies.

Advertisement