title: Calculating 3D Coordinate
body: <p>I have recently been trying to calculate a 3D point out of a mouse position. So far I have this: </p>
  
  <pre><code>const D3DXMATRIX* pmatProj = g_Camera.GetProjMatrix();
  
  POINT ptCursor;
  GetCursorPos( &amp;ptCursor );
  ScreenToClient( DXUTGetHWND(), &amp;ptCursor );
  
  // Compute the vector of the pick ray in screen space
  D3DXVECTOR3 v;
  v.x = ( ( ( 2.0f * ptCursor.x ) / pd3dsdBackBuffer-&gt;Width ) - 1 ) / pmatProj-&gt;_11;
  v.y = -( ( ( 2.0f * ptCursor.y ) / pd3dsdBackBuffer-&gt;Height ) - 1 ) / pmatProj-&gt;_22;
  v.z = 1.0f;
  
  // Get the inverse view matrix
  const D3DXMATRIX matView = *g_Camera.GetViewMatrix();
  const D3DXMATRIX matWorld = *g_Camera.GetWorldMatrix();
  D3DXMATRIX mWorldView = matWorld * matView;
  D3DXMATRIX m;
  D3DXMatrixInverse( &amp;m, NULL, &amp;mWorldView );
  
  // Transform the screen space pick ray into 3D space
  vPickRayDir.x = v.x * m._11 + v.y * m._21 + v.z * m._31;
  vPickRayDir.y = v.x * m._12 + v.y * m._22 + v.z * m._32;
  vPickRayDir.z = v.x * m._13 + v.y * m._23 + v.z * m._33;
  vPickRayOrig.x = m._41;
  vPickRayOrig.y = m._42;
  vPickRayOrig.z = m._43;
  </code></pre>
  
  <p>However, as my mathematical skills are lacklustre, I am unsure how to utilise the direction and origin to produce a position. What calculations/formulas do I need to perform to produce the desired results? </p>