Search code examples
c++directxdirectx-11directxmath

Can't multiply XMVECTOR with float


I got these rows code from the DirectX Tutorial which is compiling fine in the tutorial:

DirectX::XMFLOAT4 vLightDirs[2] =
{
    DirectX::XMFLOAT4(-0.577f, 0.577f, -0.577f, 1.0f),
    DirectX::XMFLOAT4(0.0f, 0.0f, -1.0f, 1.0f),
};

for (int m = 0; m < 2; m++)
{
    DirectX::XMMATRIX mLight = DirectX::XMMatrixTranslationFromVector(5.0f * DirectX::XMLoadFloat4(&vLightDirs[m]));
    DirectX::XMMATRIX mLightScale = DirectX::XMMatrixScaling(0.2f, 0.2f, 0.2f);
    mLight = mLightScale * mLight;
}

But in my own project I get an error:

Error 4 error C2677: binary '*' : no global operator found which takes type 'DirectX::XMVECTOR' (or there is no acceptable conversion) d:\projects\3dtestproject\3dtestproject\application.cpp 76 1 3DTestProject

This is the row (if it isn't clear):

DirectX::XMMATRIX mLight = DirectX::XMMatrixTranslationFromVector(5.0f * DirectX::XMLoadFloat4(&vLightDirs[m]));

directxmath.h is included.


Solution

  • The operator overloads are also in the DirectX C++ namespace, so they won't resolve unless you have:

    using namespace DirectX;