1
\$\begingroup\$

To draw a simple model using the DirectXTk, I'm doing the following. It all works perfectly, draws correct, and so on. Except changing the scaling factor makes NO difference, and I can't figure out why.

_MissileScale = 5.0f;
XMMATRIX GetWorldMatrix()
{
    XMMATRIX translation = XMMatrixTranslationFromVector(XMLoadFloat4(&_Position));
    XMMATRIX rotation    = XMMatrixRotationRollPitchYaw(_RotationX, _RotationY, _RotationZ);
    XMMATRIX scaling     = XMMatrixScaling(_MissileScale, _MissileScale, _MissileScale);

    return scaling * rotation * translation;
}

Then when I draw it, I ask for that matrix. The rotation and translation work, but not the scaling.

        XMMATRIX mView = pCamera->GetViewMatrix();
        XMMATRIX mProj = pCamera->GetProjMatrix();
        XMMATRIX mWorld = pMissile->GetWorldMatrix();

        _ptrMissileModel->UpdateEffects([pCamera](IEffect* effect)
        {
            XMFLOAT3 ambientLightColor(0.5f, 0.5f, 0.5f);
            auto lights = dynamic_cast<IEffectLights*>(effect);
            if (lights)
            {
                lights->SetLightingEnabled(true);
                lights->SetPerPixelLighting(true);
                lights->SetLightEnabled(0, true);
                lights->SetAmbientLightColor(XMLoadFloat3(&ambientLightColor));
                lights->SetLightDiffuseColor(0, Colors::White);
                lights->SetLightDirection(0, pCamera->GetWorldAhead());
                lights->SetLightEnabled(1, true);
                lights->SetLightEnabled(2, true);
            }
        });

Any thoughts? Of all the linear transformations you'd think scaling would be the hardest to get wrong! I've tried the two "flailing" attempts of reversing my order of multiplication and of transposing the matrix before handing it off to the shader, neither helped (both broke the rendering as you'd expect).

\$\endgroup\$
2
  • 1
    \$\begingroup\$ It doesn't really seem possible to tell with just the code you've posted. Have you tried non-uniform scales too? \$\endgroup\$
    – Ryan
    Aug 26, 2015 at 18:48
  • \$\begingroup\$ What happens to the matrix when you set the translation and rotation to 0 and only vary the scale? If you stop on setting the scale in the debugger, is it getting set to what you expect? Does the mWorld matrix end up looking the same in the function that calls GetWorldMatrix() as it does in GetWorldMatrix()? \$\endgroup\$ Aug 27, 2015 at 3:30

1 Answer 1

1
\$\begingroup\$

It turns out that the scaling was being corrupted/altered elsewhere, so it was unrelated to the problem I believed it to be. The code above is, for all intents and purposes, correct.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .