title: Transform mouse coordinates to 3d coordinates
body: <p>I have the following problem:
  I have my mouse coordinates and I have a Model (Data Points) and I want the 3d Coordinates of my mouse coordinates and my lookAt Vector of this coordinates, so that I can make a raycast with the object, so that I can see the 3d values of the data points. So I want to click with the mouse and then I want to see the coordinates of the datapoint I clicked at.</p>
  
  <p>I have the following from a tutorial, but it doesn't work. The ray origin and ray direction are not correct (I draw I line from ray origin in the ray direction and the ray origin isn't right:
  Can anyone help me? Here is the code:</p>
  
  <pre><code>    // Move the mouse cursor coordinates into the -1 to +1 range.
  pointX = ((2.0f * (float)mouseX) / (float) screen_width) - 1.0f;
  pointY = (((2.0f * (float)mouseY) / (float) screen_height) - 1.0f) * -1.0f;
  
  
  m_D3D-&gt;GetProjectionMatrix(projectionMatrix);
  
  pointX = pointX / projectionMatrix._11;
  pointY = pointY / projectionMatrix._22;
  
  // Get the inverse of the view matrix.
  m_Camera-&gt;GetViewMatrix(viewMatrix);
  D3DXMatrixInverse(&amp;inverseViewMatrix, NULL, &amp;viewMatrix);
  
  // Calculate the direction of the picking ray in view space.
  direction.x = (pointX * inverseViewMatrix._11) + (pointY * inverseViewMatrix._21)+ 
      inverseViewMatrix._31;
  direction.y = (pointX * inverseViewMatrix._12) + (pointY * inverseViewMatrix._22) 
      + inverseViewMatrix._32;
  direction.z = (pointX * inverseViewMatrix._13) + (pointY * inverseViewMatrix._23) 
      + inverseViewMatrix._33;
  
  // Get the origin of the picking ray which is the position of the camera.
  origin = m_Camera-&gt;GetPosition();
  
  // Get the world matrix and translate to the location of the sphere.
  m_Impact-&gt;GetWorldMatrix(worldMatrix);
  //D3DXMatrixTranslation(&amp;translateMatrix, -5.0f, 1.0f, 5.0f);
  //D3DXMatrixMultiply(&amp;worldMatrix, &amp;worldMatrix, &amp;translateMatrix); 
  
  // Now get the inverse of the translated world matrix.
  D3DXMatrixInverse(&amp;inverseWorldMatrix, NULL, &amp;worldMatrix);
  
  
  D3DXVec3TransformCoord(&amp;rayOrigin, &amp;origin, &amp;inverseWorldMatrix);
  D3DXVec3TransformNormal(&amp;rayDirection, &amp;direction, &amp;inverseWorldMatrix);
  
  // Normalize the ray direction.
  D3DXVec3Normalize(&amp;rayDirection, &amp;rayDirection);
  
  //collision_object-&gt;setTransform(col_matrix);
      collision_model-&gt;setTransform(col_matrix);
      float collision_point[3];
      //bool collision_result = collision_object -&gt;rayCollision(rayOrigin, 
               rayDirection, true);
      bool collision_result = collision_model -&gt;rayCollision(rayOrigin, 
              rayDirection, true);
  
               if(collision_result == true)
      {
          intersect = true;
          //collision_object-&gt;getCollisionPoint(collision_point, true);
          collision_model-&gt;getCollisionPoint(collision_point, false);
          *coordX = collision_point[0];
          *coordY = collision_point[1];
          *coordZ = collision_point[2];
  
  
  
      }
  </code></pre>