无运算符 = 匹配操作数 - DX11

No Operator = Matches Operands - DX11

我正在尝试在 DX11 中将两组值相乘。

void Update()
{
    rot += 0.0005f;
    if (rot > 6.26f)
        rot = 0.0f;

    cube1 = XMMatrixIdentity();

    XMVECTOR rotaxis = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
    Rotation = (rotaxis, rot);
    Translation = XMMatrixTranslation(0.0f, 0.0f, 4.0f);

    cube1 = Translation * Rotation;
    cube2 = XMMatrixIdentity();

    Rotation = XMMatrixRotationAxis(rotaxis, -rot);
    Scale = XMMatrixScaling(1.3f, 1.3f, 1.3f);

    cube2 = Rotation * Scale;

但我一直收到错误;

[code]No operator "=" matches these operands
operand types are: DirectX::XMVECTOR = DirectX::XMMATRIX[/code]

根据我的阅读,它们不能相乘,但我似乎找不到解决方法。

代码片段。

转发声明

const int Width = 300;
const int Height = 300;

XMMATRIX WVP;
XMMATRIX cube1;
XMMATRIX cube2;
XMMATRIX camView;
XMMATRIX camProjection;

XMVECTOR camPosition;
XMVECTOR camTarget;
XMVECTOR camUp;

XMVECTOR Rotation;
XMVECTOR Scale;
XMVECTOR Translation;
float rot = 0.1f;

在 InitDevice() 函数的末尾设置 camera/projection。

camPosition = XMVectorSet(0.0f, 3.0f, -8.0f, 0.0f);
camTarget = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
camUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
camView = XMMatrixLookAtLH(camPosition, camTarget, camUp);
camProjection = XMMatrixPerspectiveFovLH(0.4f*3.14f, Width / Height, 1.0f, 1000.0f);

我看到的第一个问题是:

XMVECTOR rotaxis = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
Rotation = (rotaxis, rot); <<--- You are missing the name of a function here!
Translation = XMMatrixTranslation(0.0f, 0.0f, 4.0f);

因为那里没有函数名称,所以您实际上使用的是 comma operator。基本相同:

Rotation = rotaxis = rot;

我不确定你想在这里做什么,但可能不是那样。

第二个问题是:

Rotation = XMMatrixRotationAxis(rotaxis, -rot);

XMMatrixRotationAxis returns 您试图分配给 XMVECTORXMMATRIX 无效。

您需要检查您的使用情况。如果 Rotation 应该是一个四元数(适合 XMVECTOR)那么你需要使用 XMQuaternion* 函数而不是 XMMatrix*.

我建议使用 C++ 风格的类型声明,而不是将它们全部放在顶部。阅读和遵循类型要容易得多。

Note if you are new to DirectXMath, you should take a look at the SimpleMath wrapper in the DirectX Tool Kit for DX11 / DX12.