I have some DirectX C++ code that uses xnamath.h
. I wanted to migrate to "brand new" DirectXMath
, so I've changed:
#include <xnamath.h>
to
#include <DirectXMath.h>
I have also added DirectX
namespace, e.g.:
DirectX::XMFLOAT3 vector;
I was ready for troubles, and here they come!
During compilation, I got error:
error C2676: binary '-' : 'DirectX::XMVECTOR' does not define this operator
or a conversion to a type acceptable to the predefined operator
For the line that worked fine for xnamth.h
:
DirectX::XMVECTOR RayDir = CursorObjectSpace - RayOrigin;
I don't really know how to fix it. I don't think that operator-
is "not supported" anymore, but what can cause that error and how to fix it?
Here is more complex source code:
DirectX::XMVECTOR RayOrigin = DirectX::XMVectorSet(cPos.getX(), cPos.getY(), cPos.getZ(), 0.0f);
POINT mouse;
GetCursorPos(&mouse);
DirectX::XMVECTOR CursorScreenSpace = DirectX::XMVectorSet(mouse.x, mouse.y, 0.0f, 0.0f);
RECT windowRect;
GetWindowRect(*hwnd, &windowRect);
DirectX::XMVECTOR CursorObjectSpace = XMVector3Unproject( CursorScreenSpace, windowRect.left, windowRect.top, screenSize.getX(), screenSize.getY(), 0.0f, 1.0f, XMLoadFloat4x4(&activeCamera->getProjection()), XMLoadFloat4x4(&activeCamera->getView()), DirectX::XMMatrixIdentity());
DirectX::XMVECTOR RayDir = CursorObjectSpace - RayOrigin;
I'm working on Windows 7 x64, project target is x32 debug and it worked fine for xnamath.h
so far.
The working solution would be:
DirectX::XMVECTOR RayDir = DirectX::XMVectorSet( //write more, do less..
DirectX::XMVectorGetX(CursorObjectSpace) - DirectX::XMVectorGetX(RayOrigin),
DirectX::XMVectorGetY(CursorObjectSpace) - DirectX::XMVectorGetY(RayOrigin),
DirectX::XMVectorGetZ(CursorObjectSpace) - DirectX::XMVectorGetZ(RayOrigin),
DirectX::XMVectorGetW(CursorObjectSpace) - DirectX::XMVectorGetW(RayOrigin)
); //oh my God, I'm so creepy solution
But it is soo creepy compare to previous, working for xnamath
:
XMVECTOR RayDir = CursorObjectSpace - RayOrigin;
I really don't belive it's the only way and I cannot just use operator-
like above.
I also have exact the same problem for operator/
.