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