Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

OregonGhost

Texture Coordinate Transformations

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

For a sprite engine, I decided to use texture coordinate transforms to select the correct rectangle from the source texture. First I create a scaling matrix with D3DXMatrixScaling to get the correct width and height. This works pretty well. Then I wanted to create a translation matrix with D3DXMatrixTranslation and this doesn''t work. However, I''ve found a piece of code like the following (M is an identity matrix): M._31 = du; M._32 = dv; where du and dv are the left and top positions in texture coordinates. Hey, and it works. So now my question is: Why can I use D3DX for scaling but not for translation (nor rotation), and how should I know this (where to look at in the SDK, maybe someone knows a general article about texture transformations)? Oregon Ghost

Share this post


Link to post
Share on other sites
Advertisement
i, at least, need a little more code to see what is happening. there is quite a few things you could be doing wrong. many people have gotten this to work, so it is not impossible. also, many people have this problem when dealing with D3DXMatrixWhatever functions:

D3DXMatrixWhatever(&matrix, doSomething, doSomethingElse);
device->setTransform(...);

D3DXMatrixWhatever(&anotherMatrix, doSomeMore);
device->setTransform(...);

and then it doesnt work...

what you need to do is:

D3DXMatrixWhatever(&matrix, doSomething, doSomethingElse);
device->setTransform(...);

D3DXMatrixWhatever(&anotherMatrix, doSomeMore);
device->multiplyTransform(...);

that multiplyTransform is a pretty common mistake and a very powerful tool.

hope it helped



Brett Lynnes
cheez_keeper@hotmail.com

Share this post


Link to post
Share on other sites
This post held me, its from an AP:

The transform can operate on normal UVs too, not just generated ones.

If Ratterbox is just looking to pick a different sprite for his 2D game, you guys are all going WAY overboard here.

Set your vertex quad UVs to (0,0) (0,1) (1,0) (1,1).
Create a transform to select a part of the image
Program the transform into DX

Creating the transform:
D3DXMatrixIdentity(mat);
mat->_11 = spritewidth/texturewidth
mat->_22 = spriteheight/textureheight
mat->_31 = spritexoffset/texturewidth
mat->_32 = spriteyoffset/textureheight

Note that with 2 coordinates (UV rather than XYZ) the translation part of the matrix is row 3, not row 4. Because of this you can''t use all of the D3DX macros to create texture transforms.


// Enable transformpDevice->SetTextureStageState(nStage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );pDevice->SetTransform( (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+nStage), &matrix);// Any draw calls here will have a transform applied// Disable transformpDevice->SetTextureStageState(nCounter, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );

Share this post


Link to post
Share on other sites
Yeah, that was an earlier post of mine (I''m anonymous when I post from work because I have no idea what my password is).

Doing a rotation around Z (roll) should work with the D3DX functions as it modifies X and Y, aka. U and V for texture coordinates.

Also the row 3 vs. row 4 rule only applies when your transform flags are set to COUNT2. When it''s COUNT3 the full 4x4 matrix works, but that''s generally only when you have texture coordinates generated for you (cameraspacenormal, cameraspaceposition, cameraspacereflectionvector).

Share this post


Link to post
Share on other sites
The thing with MultiplyTransform didn''t change anything. D3DXScaling and D3DXRotationZ work pretty well, and for translation, I change row 3.
Thanks to you all, but does anyone know a good article or so about transformation matrices in general?

Share this post


Link to post
Share on other sites
You could check the sdk. Just ignore all the math and look at the structure of the translation matrix. Not hard to understand it once u know what to plug in and where to put it

Share this post


Link to post
Share on other sites
Hmmm... Never thought of just looking into the Transforms->Matrices section in the SDK...

However, there isn''t anything about 2D-Translations... But I think, I now understand more - thanks ;c)

Share this post


Link to post
Share on other sites
quote:
Original post by OregonGhost
However, there isn''t anything about 2D-Translations... But I think, I now understand more - thanks ;c)


DirectX Graphics ->
Programming Guide ->
Fixed Function Pipeline ->
Textures ->
Texture Coordinates ->
Texture Coordinate Processing ->
Special Effects ->
"Animating textures (by translation or rotation) on a model"

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!