Skip to main content
gamedev.net
🔒 Locked

Problem with SetTranform

Started by valla2 Feb 14, 2007 at 4:27 AM 2 replies 1.2k views
Original Post
valla2
valla2
Hello. I have a question regarding the SetTranfrom method in the IDirect3DDevice9 class. What we have here is the texture of the background that gets rendered 2 times larger and tiled 10 times in both directions. The code for that is basically this:

 D3DXMATRIX texScaling; 
 D3DXMatrixScaling(&texScaling, 10.0f, 10.0f, 0.0f);   //this line says that the background will be tiled 10 times
 gd3dDevice->SetTransform(D3DTS_TEXTURE0, &texScaling); 
.. 
 D3DXMATRIX  S; 
 D3DXMatrixScaling(&S, 20.0f, 20.0f, 0.0f);  // this says that the background will be displaid 20 times larger
 mSprite->SetTransform(&S); 
 mSprite->Daw(....);
And here's the problem. gd3dDevice->SetTransform doesn't just tile the texture 10 times. If that's just what it does, then the texture should be diplayed 20 times larger, as the code for tranfrorming it uses the scaling matrix "D3DXMatrixScaling(&S, 20.0f, 20.0f, 0.0f);". What i want to say is that for the effect we want to achieve, shouldn't we rewrite that line like this

D3DXMatrixScaling(&S, 2.0f, 2.0f, 0.0f); 
? But If we make it like this then what we get is the texture much smaller and tiled together ( 10 times? you can't really tell ) and with a general size only 2 times bigger that the size of the original texture. The documentation for gd3dDevice->SetTransform doesn't explain it at all ( it says that it just "Sets a single device transformation-related state" ) -- I also have another question.Since we shouldn't use DirectInput8, what should we use? It was really good because we didn't have to place our code for the input in the main window procedure. Right?
valla2
valla2
Not a single reply? :.(
Cigguh
Cigguh
I used to have the same problems before.
Here's info i took from http://tomsdxfaq.blogspot.com/
It's a long faq so here's the cut:



================================================================================

Thursday, May 30, 2002
How do Texture Transform matrices work?

The answer is - slightly oddly. If you are familiar with the OpenGL ones, forget them. These are subtly and confusingly different. So best just to forget them and start again. I am using the DirectX8 terminology here, but it translates fairly easily to DX7 or DX9.

The basic operation is in four steps:

(1) Coordinates (1-4 components) are fed into the texture transformation unit.
(2) They are transformed by the matrix (i.e. a matrix multiply operation).
(3) The components of the result may be divided by one of the components (used for projective texturing), and that component is discarded.
(4) The results are fed to the texture units as texture coordinates.

Step (1) is controlled by SetTextureStageState ( n, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_xxx ), where xxx is either:
- PASSTHRU - you supply 1 to 4 values in the vertex itself. The number of components is determined by the FVF of the vertex, and the coordinate set is determined by the number order with D3DTSS_TCI_PASSTHRU. So passing in D3DTSS_TCI_PASSTHRU | 2 means that the coordinates should be taken from the third set (they are numbered from 0) of coordinates specified in the vertex/FVF.
- One of the CAMERASPACEyyy enumerations - 3 values are always used, and they are the result of calculations using other components of the vertex such as position or normal.

However they are generated, these values are padded to a 4-component vector in the following ways:
-1 component (x) -> (x,1,0,0)
-2 components (x,y) -> (x,y,1,0)
-3 components (x,y,z) -> (x,y,z,1)
-4 components (x,y,z,w) -> (x,y,z,w)

Also note that TEXCOORDINDEX requires an FVF input field, even when not using D3DTSS_TCI_PASSTHRU. This is because the behaviour of the D3DRS_WRAPzzz renderstates operates on vertex inputs, _not_ texture coordinates. So the value of zzz corresponds to the number ORed with CAMERASPACEyyy. This behaviour is slightly more rational under DX9 fortunately.

Step (2) is controlled by the texture transform matrix set using SetTransform ( D3DTS_TEXTUREn, &matrix ), where n is the appropriate Texture Stage State stage. The 4-component input defined by step (1) is transformed by the 4x4 matrix to produce a 4-component output vector.

Step (3) is controlled by SetTextureStateStage ( n, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNTxxx ). The value of xxx determines how many components are required by the rasteriser. Also, the argument may be ORed with D3DTTFF_PROJECTED. This causes the result of step (2) to have three its components divided by the other one. Which component is the divisor is determined by the value of D3DTTFF_COUNTxxx:
-D3DTTFF_COUNT1 | D3DTTFF_PROJECTED: invalid combination
-D3DTTFF_COUNT2 | D3DTTFF_PROJECTED: (x,y,z,w) -> (x/y,*,*,*)
-D3DTTFF_COUNT3 | D3DTTFF_PROJECTED: (x,y,z,w) -> (x/z,y/z,*,*)
-D3DTTFF_COUNT4 | D3DTTFF_PROJECTED: (x,y,z,w) -> (x/w,y/w,z/w,*)

An asterisk(*) means that this value is not well-defined by the docs, and trying to actually use the value generated here is unwise, as it may vary between different bits of hardware. For example, do not use D3DTTFF_COUNT2 | D3DTTFF_PROJECTED when the texture used is a 2D one.

For more details, look at the DX8.1 docs section entitled "Texture Coordinate Processing", and all its sub-sections. Especially note the one called "Special Effects", as it shows the correct matrix for scrolling a 2D texture around.

================================================================================


Hope it helps.
Good luck.
i make the game so i be ballin
valla2
valla2
It's over my head right now :(

Perhaps i should forget it and come back later. Thanks for your help though. Much appreciated.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.