Archived

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

Scaling a mesh

This topic is 5337 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, I am trying to scale a mesh in my program but when I do it, it also changes the mesh''s position(scales the mesh''s translation/position?). My code is: D3DXMATRIX matWorld, matScale; D3DXMatrixScaling(&matScale, scale, scale, scale); D3DXMatrixTranslation(&matWorld,m_Position.x, m_Position.y, m_Position.z); D3DXMatrixMultiply(&matWorld, &matWorld, &matScale); g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); where scale = the amount to scale the mesh. m_Position = the position of the mesh (D3DVECTOR3) Is there a way to scale the mesh but keep the position (shrinking effect is what im after). Im sure there is but I am still getting my head around matrices and the order that I am supposed to do things. I have searched the forums but couldn''t quite find the answer i was after, although it did get me from nothing to where I am now. Thanks, h

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i know of two things that can cause this:

1) matrix concatenation is order dependent. in other words, translating then scaling is not the same as scaling then translating.

2) if the geometric center of the mesh is not at (0,0,0) then the mesh will look like it''s not rotating around its center. this can be fixed by finding the geometric center of the mesh, and then always translating to that point, rotating, then translating back.

Share this post


Link to post
Share on other sites
Thanks for the suggestions AP.
I went to bed after i posted my problem and with a clear head today, i figured it out while I was at work. The following code does what I want it to:

D3DXMATRIX matWorld, matScale;

D3DXMatrixScaling(&matScale, scale, scale, scale);
D3DXMatrixTranslation(&matWorld,m_Position.x, m_Position.y, m_Position.z);

D3DXMatrixMultiply(&matWorld, &matScale, &matWorld

g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);

All i did was switch matScale and matWorld in the D3DXMatrixMultiply() function. I guess if i knew my maths i would have known this

thanks,

h

Share this post


Link to post
Share on other sites