Archived

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

Scale matrix

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

Hi, in all tutorials that I could find, the object''s world matrix is always the product of the translate and rotate matrix. But how do I insert a scale operation? Thanks, Alex

Share this post


Link to post
Share on other sites
You use a D3DXMATRIX returned by the D3DXMatrixScaling function. Look up the function in the DX SDK, you just give a scaling factor for the three axis and a pointer to a D3DXMATRIX structure you want to use.

Then, you use this matrix, just as you would use a rotation or translation matrix.

Share this post


Link to post
Share on other sites
I''ve already found the functions etc, but I don''t know how to use it with the other both matrices.
This is the code:


  
D3DXMatrixMultiply(&matWorld,&rotate_matrix,&translate_matrix);
g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );


Then would this be correct or is the scale matrix multiplied in another way?


  
D3DXMatrixMultiply(&matWorldTemp,&rotate_matrix,&translate_matrix);
D3DXMatrixMultiply(&matWorld,&matWorld,&scale_matrix);
g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );

Share this post


Link to post
Share on other sites
Nope, the code should read

D3DXMatrixMultiply(&matWorldTemp,&scale_matrix,&rotate_matrix);
D3DXMatrixMultiply(&matWorld,&matWorld,&translate_matrix);
g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );

otherwise your just scaling the translated position of the object.

Share this post


Link to post
Share on other sites
To clarify that: The order in which you multiply two matrices matters. So A*B gives a different result than B*A.

You have to think about what you need to do first: First you want to scale the object to size, then you want to rotate it, and then you want to place it in the right position.

So you first multiply scale by rotate, and then multiply the result by translate.

You don''t need to use a temporary world matrix variable, by the way. As far as I know, this works fine:


  
D3DXMATRIX matWorld;
D3DXMATRIX matScale;
D3DXMATRIX matRotate;
D3DXMATRIX matTranslate;

D3DXMatrixMultiply(&matWorld,&matScale,&matRotate);
D3DXMatrixMultiply(&matWorld,&matWorld,&matTranslate);
g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );


In other words, it''s not necessary to store the results of the first multiply operation in different (temporary) variable than the final world variable.

Share this post


Link to post
Share on other sites