I'm trying to multiply two sets of values together in 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;
But I keep getting the error;
[code]No operator "=" matches these operands
operand types are: DirectX::XMVECTOR = DirectX::XMMATRIX[/code]
From what I have read, they can't be multiplied together, but I cannot seem to find a workaround.
Code Snippets.
Forward Declarations
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;
Setting camera/projection at the end of the InitDevice() Function.
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);
The first problem I see is:
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);
Since there's no function name there so you are actually using the comma operator. It's basically the same as:
Rotation = rotaxis = rot;
I'm not sure what you are trying to do here, but it's probably not that.
The second issue is:
Rotation = XMMatrixRotationAxis(rotaxis, -rot);
XMMatrixRotationAxis
returns a XMMATRIX
which you are trying to assign to a XMVECTOR
which doesn't work.
You need to review your usage. If Rotation
is supposed to be a quaternion (which fits in a XMVECTOR
) then you need to use XMQuaternion*
functions instead of XMMatrix*
.
I'd recommend using C++-style type declaration instead of putting them all at the top. It's a lot easier to read and follow the types.
Note if you are new to DirectXMath, you should take a look at the SimpleMath wrapper in the DirectX Tool Kit for DX11 / DX12.