title: Projection matrix transformation 'wrapping around'
body: <p>I'm writing some code that has to transform a number of vertex coordinates to clip/projection space on the CPU (to integrate with an existing application; shaders are not an option here as the application provides its own shaders at a later point), for which I have a test case which intends to have the result be a basic 'camera-style' transformation + projection looking down a camera rotated around the X axis.</p>
  
  <p>The test case is as follows:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;xnamath.h&gt;
  #include &lt;stdio.h&gt;
  
  int main()
  {
      XMVECTOR atPos = XMVectorSet(925.0f, -511.0f, 0.0f, 0.0f);
      XMVECTOR eyePos = XMVectorSet(925.0f, -311.0f, 200.0f, 0.0f);
      XMVECTOR upDir = XMVectorSet(0.f, 0.f, 1.f, 0.0f);
  
      XMMATRIX viewMatrix = XMMatrixLookAtLH(eyePos, atPos, upDir);
      XMMATRIX projectionMatrix = XMMatrixPerspectiveFovLH(XMConvertToRadians(55.f), 1.0f, 0.1f, 5000.0f);
  
      XMMATRIX viewProjMatrix = viewMatrix * projectionMatrix;
  
      XMVECTOR coord1 = XMVectorSet(925.0f, -500.0f, 0.0f, 0.0f);
      XMVECTOR coord2 = XMVectorSet(925.0f, 0.0f, 0.0f, 0.0f);
      XMVECTOR coord3 = XMVectorSet(925.0f, -1000.0f, 0.0f, 0.0f);
  
      coord1 = XMVector3TransformCoord(coord1, viewProjMatrix);
      coord2 = XMVector3TransformCoord(coord2, viewProjMatrix);
      coord3 = XMVector3TransformCoord(coord3, viewProjMatrix);
  
      printf("    0: %g %g %g\n", XMVectorGetX(coord2), XMVectorGetY(coord2), XMVectorGetZ(coord2));
      printf(" -500: %g %g %g\n", XMVectorGetX(coord1), XMVectorGetY(coord1), XMVectorGetZ(coord1));
      printf("-1000: %g %g %g\n", XMVectorGetX(coord3), XMVectorGetY(coord3), XMVectorGetZ(coord3));
  
      getc(stdin);
  }
  </code></pre>
  
  <p>If I just transform by the view matrix, I'm noticing the Y value correctly moving correlated with the input Y value of the coordinates; but adding the projection matrix the Y value seems to wrap around making both the coordinate that are to the 'north' of the view and the coordinate to the 'south' of the view extend in the same direction in projection space, which results in the eventual faces transformed using similar code in the target application overlapping each other instead of drawing in the correct order.</p>
  
  <p>What am I doing wrong in this regard, and how can I get a valid result for at least this input (i.e. extending in the same manner as the input Y is advancing, even though these vertices are out of the given projection range, which I doubt should be a problem)?</p>