Dear All
It is my first post in here, and may be this has been discussed several times.
I am having no success finding the screen coordinates fron a 3D Primitive Point/Coordinate
I am using the following code:
D3DMATRIX matrix;
D3DXVECTOR4 position;
D3DXVECTOR4 input;
D3DVIEWPORT9 viewport;
GetVertexShaderConstantF(0, (float *)&matrix, 4);
GetViewport(&viewport);
input.x = 0.0f; // ==> I replace the 0.0 with my x coordinate
input.y = 0.0f; // ==> I replace the 0.0 with my y coordinate
input.z = 0.0f; // ==> I replace the 0.0 with my z coodinate
input.w = 1.0f;
D3DXMatrixTranspose((D3DXMATRIX *)&matrix, (D3DXMATRIX *)&matrix);
position.x = input.x * matrix._11 + input.y * matrix._21 + input.z * matrix._31 + matrix._41;
position.y = input.x * matrix._12 + input.y * matrix._22 + input.z * matrix._32 + matrix._42;
position.z = input.x * matrix._13 + input.y * matrix._23 + input.z * matrix._33 + matrix._43;
position.w = input.x * matrix._14 + input.y * matrix._24 + input.z * matrix._34 + matrix._44;
float x = ((position.x / position.w) * (viewport.Width / 2)) + viewport.X + (viewport.Width / 2);
float y = viewport.Y + (viewport.Height / 2) - ((position.y / position.w) * (viewport.Height / 2));
The matrix variable holds the World x View x Projection matrix retrieved from the Shader.
I also tried the D3DXVec3TransformCoord and D3DXVec3Project code snippets but without success.
I tested drawing these points in screen and they not nearly match the sprites/objects which they represent after going through the DirectX drawing Pipeline.
I appreciate any help!
Thanks
fs1