WeekUp
WeekUp

Reputation: 3

Scale an object using DX

I try to scale matrix using this code:

        D3DXMATRIX & rMatrix = m_Matrices[i];
        D3DXMatrixScaling(&rMatrix, 2.0f, 2.0f, 2.0f);

i -> defined in a loop

They doesn't scale the object. It's strange cause if I use same code in an place who update mesh matrices world they work but isn't what I need cause in this place is scaling all the object so I need to use here for can define the scaling just for an certain object.

I appreciate your help!

Upvotes: 0

Views: 906

Answers (2)

Chuck Walbourn
Chuck Walbourn

Reputation: 41097

You are not scaling your array of matrices. You are overwriting them with the same matrix [2 0 0 0 | 0 2 0 0 | 0 0 2 0 | 0 0 0 1]. You need to multiply the original matrix with the scaling matrix returned by D3DXMatrixScaling to concatenate them. Something like:

D3DXMATRIX scaleMatrix;
D3DXMatrixScaling(&scaleMatrix, 2.0f, 2.0f, 2.0f);
for( i = 0; i < /*...*/ )
    D3DXMatrixMultiply(&m_Matrices[i], &m_Matrices[i], scaleMatrix);

BTW, D3DXMath is ancient as is the rest of D3DX9/D3DX10 which is deprecated per MSDN.

Take a look at DirectXMath and the SimpleMath wrapper for DirectXMath.

Upvotes: 1

NMD
NMD

Reputation: 93

I have a hard time understanding your problem. Correct me please if I didn't answer your question!

So you have to separate your render function. You have to calculate your world matrix twice. One for object what need that scaling, after calculate the world matrix without the scaling.

The world matrix contain the information for the position of your vertecies, you have to change the world matrix each object that you wanna translate, rotate, re-size. Normaly every mesh is around the origo and the world matrix moving/rotate/scale them to the position where you wanna see that mesh :)

Upvotes: 0

Related Questions