I have a function where I can calculate the point in 3D space given x & y screen co-ordinates below;

void Graphics::ScreenToWorld(float mousePosX,float mousePosY,float nDepth) { // Get matrices and the viewport. D3DXMATRIX pm; // projection matrix D3DXMATRIX vm; // view matrix D3DXMATRIX wm; // world matrix D3DVIEWPORT9 vp; // viewport md3dDevice->GetTransform(D3DTS_PROJECTION,&pm); md3dDevice->GetTransform(D3DTS_VIEW,&vm); D3DXMatrixIdentity(&wm); // make the world matrix an identity matrix md3dDevice->GetViewport(&vp); // Call the D3DXVec3Unproject function twice to determine two points // in our world space. Having two points we will be able to find // a line in the world space. One point is for the z-near plane // (which is usually z=0.0f) and another point is for z-far plane // (which is usually z=1.0f). We grab the z-planes from the viewport. D3DXVECTOR3 p1; D3DXVec3Unproject(&p1, &D3DXVECTOR3(mousePosX,mousePosY, vp.MinZ), &vp, &pm, &vm, &wm); D3DXVECTOR3 p2; D3DXVec3Unproject(&p2, &D3DXVECTOR3(mousePosX,mousePosY, vp.MaxZ), &vp, &pm, &vm, &wm); // We calculate an intersection of the line found previously // with a plane z=0.0f. Equations of a line in 3-D space can // be found on the following websites: // http://mathforum.org...html#threelines // http://mathforum.org...view/65721.html // Here, wx, wy, and wz represent coordinates in the world space. fWorldZ=nDepth; fWorldX=((fWorldZ-p1.z)*(p2.x-p1.x))/(p2.z-p1.z)+p1.x; fWorldY=((fWorldZ-p1.z)*(p2.y-p1.y))/(p2.z-p1.z)+p1.y; // w is the point in the world space corresponding to the p point // in the screen coordinates. //D3DXVECTOR3 w(wx, wy, wz); }

How would I do the opposite? If I had a point in the word x,y,z - how would I get the screen co-ordinates for that point?

Any help would be greatly appreciated.