Sign in to follow this  

I need help (with Scaling)...

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

Its kinda odd. Let me just post the code: D3DXMATRIX matTrans; D3DXMATRIX matRotate; D3DXMATRIX matScale; D3DXMatrixIdentity(&matScale); D3DXMatrixTranslation(&matTrans, pos.x, pos.y, pos.z); D3DXMatrixRotationY(&matRotate, D3DXToRadian(1.0f)); D3DXMatrixMultiply(&matTrans, &matRotate, &matTrans); D3DXMatrixScaling(&matScale, 0.5f, 0.5f, 0.5f); D3DXMatrixMultiply(&matTrans, &matScale, &matTrans); When I create the object with this code, it doesn't even show up. If I remove the two last lines, the object shows up, but is absolutely huge (even though the 3D model is tiny). Any ideas why my scaling isnt working? Any help you guys can offer would be awesome. Thanks in advance.

Share this post


Link to post
Share on other sites
Im sorry, I posted the code the DOESNT show anything. This is the code that renders the object, but HUGELY (and as if Im not using the scale factor at all...ie. if I take out the first two lines, the result is exactly the same).

D3DXMatrixScaling(&matScale, 0.5f, 0.5f, 0.5f);
D3DXMatrixMultiply(&matTrans, &matScale, &matTrans);
D3DXMatrixTranslation(&matTrans, pos.x, pos.y, pos.z);
D3DXMatrixRotationY(&matRotate, D3DXToRadian(1.0f));
D3DXMatrixMultiply(&matTrans, &matRotate, &matTrans);

So, if I use this:

D3DXMatrixTranslation(&matTrans, pos.x, pos.y, pos.z);
D3DXMatrixRotationY(&matRotate, D3DXToRadian(1.0f));
D3DXMatrixMultiply(&matTrans, &matRotate, &matTrans);
D3DXMatrixScaling(&matScale, 0.5f, 0.5f, 0.5f);
D3DXMatrixMultiply(&matTrans, &matScale, &matTrans);

I get nothing on the screen. All the variables seem placed correctly, Im just not sure what Im doing wrong here.

Share this post


Link to post
Share on other sites
This is what I wanted you to try...

D3DXMatrixTranslation(&matTrans, pos.x, pos.y, pos.z);
D3DXMatrixRotationY(&matRotate, D3DXToRadian(1.0f));
D3DXMatrixMultiply(&matTrans, &matRotate, &matTrans);
D3DXMatrixScaling(&matScale, 0.5f, 0.5f, 0.5f);
D3DXMatrixMultiply(&matTrans, &matTrans, &matScale);

The order matrices are multiplied is important.

Swapping the arguments of the last matrix multiply. In your first code snippet on your latest post you scale a translation matrix that hasn't been set up yet, then you overwrite it with a plain translation matrix... so yeah, the scale has no effect. It's as if you did this.

float s,t,r;

s = scale;
t *= s;
t = pos;
r = rot;
t *= r;

Notice how you're multiplying t before assigning a value, then overwriting the result completely anyway.

Share this post


Link to post
Share on other sites
The problem with your first code I think lies here
|
| D3DXMatrixScaling(&matScale, 0.5f, 0.5f, 0.5f);
| D3DXMatrixMultiply(&matTrans, &matScale, &matTrans);
+> D3DXMatrixTranslation(&matTrans, pos.x, pos.y, pos.z);
D3DXMatrixRotationY(&matRotate, D3DXToRadian(1.0f));
D3DXMatrixMultiply(&matTrans, &matRotate, &matTrans);

This will overwrite what was in matTrans (ie your scale) with just your Translation variables. Instead, try something like :

D3DXMatrixIdentity(&matWorld);
D3DXMatrixScaling(&matScale, 0.5f, 0.5f, 0.5f);
D3DXMatrixTranslation(&matTrans, pos.x, pos.y, pos.z);
D3DXMatrixRotationY(&matRotate, D3DXToRadian(1.0f));
D3DXMatrixMultiply(&matWorld, &matRotate, &matScale);
D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans);

Hope this helps,
Steele.

Share this post


Link to post
Share on other sites
To illustrate the point about the order of operations, I'll clarify it a bit here why it matters.

Imagine you have a vertex at 2,3,4. Lets just worry about x for now. We translate by 40, and scale by 0.5.

2, translate by 40 = 42, scale by 0.5 = 21
vs
2, scale by 0.5 = 1, translate by 40 = 41.

Vastly different answers based on the order of operations. The order you multiply matrices determines the order of operations.

Share this post


Link to post
Share on other sites
The order of multiplication with matrices is imperative. You must multiply scale with rotation first. You then take the result of that and multiply with the translation matrix. Do it out of order and your result will be incorrect.

Share this post


Link to post
Share on other sites
Ok, I feel a little dumb with regards to the ordering, I know that it matters, and yet I still screwed it up! Anyhow, thanks guys for the help, it seems I was just being an idiot! Thanks again.

Share this post


Link to post
Share on other sites

This topic is 4745 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this