transformations.

Started by
1 comment, last by Ksingh30 18 years, 11 months ago
ok how do you translate and scale a 3d object. This is what Im doing D3DXMATRIX tra; D3DXMATRIX scale; D3DXMatrixTransalation(&tra, 1.0f,1.0f,1.0f); D3DXMatrixScaling(&scale, 1.0f,2.0f,1.0f); Device->SetTransform(D3DTS_WORLD, &tra); Device->SetTransform(D3DTS_WORLD, &scale); ///Drawinf the object here but the thing is the object only gets scaled. and if I move the Device->SetTransform(D3DTS_WORLD, &tra); down, then it only gets translated. so whats wrong?
Advertisement

SetTransform() is like SetRenderState() in so much as only the most recent value for a state will be used for drawing.

So if you have:
SetTransform(D3DTS_WORLD, &A);
SetTransform(D3DTS_WORLD, &B);
SetTransform(D3DTS_WORLD, &C);
DrawPrimitive( blah );

The value of D3DTS_WORLD that gets used is C, and *only* C.

D3D doesn't concatenate your matrices for you, it just accepts a single matrix for the world matrix and uses that to draw with.


D3DXMatrixTransalation() and D3DXMatrixScaling() build entirely independent matrices that only serve one purpose (i.e. translate, or scale).

If you want the matrix to serve multiple purposes, you should multiply (concatenate) the matrices together, e.g.:

D3DXMATRIX tra;D3DXMATRIX scale;D3DXMatrixTransalation(&tra, 1.0f,1.0f,1.0f);D3DXMatrixScaling(&scale, 1.0f,2.0f,1.0f);...D3DXMATRIX scale_and_translate;D3DXMatrixMultiply( &scale_and_translate, &translate, &scale );...Device->SetTransform(D3DTS_WORLD, &scale_and_translate);


The following tutorial may be of use to you:
http://www.andypike.com/tutorials/directx8/005.asp

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

great, Ill remember that, Thank You, you are now my hero. but as far as matricies are concerned I do understand them fairly well, I just didnt know you had to concatnate them.

This topic is closed to new replies.

Advertisement