   D3DXVec3Unproject always gives the same result!
  This is driving me insane!What I am trying to do is move an object to the location of the mouse pointer on mouse click. Here's my code:void render_frame(void){    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);    d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);    d3ddev->BeginScene();    // select which vertex format we are using    d3ddev->SetFVF(CUSTOMFVF);    // set the view transform    D3DXMATRIX matView;    // the view transform matrix    D3DXMatrixLookAtLH(&matView,&D3DXVECTOR3 (screen_x, screen_y, screen_z),    // the camera position&D3DXVECTOR3 (look_x, look_y, look_z), // the look-at position&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction    d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView    // set the projection transform    D3DXMATRIX matProjection;    // the projection transform matrix    D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45),    // the horizontal field of view (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio 1.0f,   // the near view-plane 100.0f);    // the far view-plane    d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection); // set the projection    D3DVIEWPORT9 viewport;    d3ddev->GetViewport(&viewport);    // select the vertex buffer to display    d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));    D3DXMATRIX matUnit;    // a matrix to store the translation for our unit    if (input->get_right_click())    {   string str;   POINT ptCursor; // get cursor position   GetCursorPos( &ptCursor );   ScreenToClient( hWnd, &ptCursor );   D3DXVECTOR3 result;D3DXVECTOR3 screenPoint; // set screen vectorscreenPoint.x = ptCursor.x;screenPoint.y = ptCursor.y;screenPoint.z = 1;ostringstream buffer;buffer << "before x: " << screenPoint.x << endl   << "before y: " << screenPoint.y << endl   << "before z: " << screenPoint.z << endl;buffer.flush();str = buffer.str();m_file_out.write (str.c_str(), str.length());//transform the mouse clicked locationD3DXVec3Unproject( &result, &screenPoint, &viewport, &matProjection, &matView, &matUnit );ostringstream buffer2;buffer2 << "after x: " << result.x << endl << "after y: " << result.y << endl << "after z: " << result.z << endl;buffer2.flush();str = buffer2.str();m_file_out.write (str.c_str(), str.length());m_file_out.flush();unit_x = result.x;unit_y = result.y;unit_z = result.z;    }    D3DXMatrixTranslation(&matUnit, unit_x, unit_y, unit_z);    // set a texture    d3ddev->SetTexture(0, texture_1);    // tell Direct3D about each world transform, and then draw another triangle    d3ddev->SetTransform(D3DTS_WORLD, &matUnit);    d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);    d3ddev->EndScene();d3ddev->Present(NULL, NULL, NULL, NULL);}Now if i click around the screen and check my log file I see this:before x: 115before y: 123before z: 1after x: -0.0182895after y: 0.024386after z: 0.999898before x: 601before y: 496before z: 1after x: -0.0182895after y: 0.024386after z: 0.999898before x: 135before y: 493before z: 1after x: -0.0182895after y: 0.024386after z: 0.999898So regardless where I click I get the same result!Can anyone help me on this? I've found a couple of examples and I'm trying to follow them, but I just can't see what I'm doing wrong.Thanks!   
  For one you're using matUnit before D3DXMatrixTranslation is called on it (which leaves matUnit in an undefined state AFAIK).Also, check the return value of GetViewport. If you've got a pure device the call will fail.   ;  Thanks Endurion. You lead me to the issue.I was missing a world transformation like:D3DXMATRIX m_World = D3DXMATRIX(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);d3ddev->SetTransform(D3DTS_WORLD, &m_World); And now it works... sort of there's a discrepancy where the object is always a little above the mouse pointer rather than dead on it.   