this function is part of my library:
D3DXVECTOR2 Project3DTo2D( D3DXVECTOR3* point, int cameraID )
{
D3DXMATRIX VP = dbGetViewMatrix( cameraID ) * dbGetProjectionMatrix( cameraID );
D3DXVECTOR4 trans;
D3DXVec3Transform( &trans, point, &VP );
D3DXVECTOR2 screen = D3DXVECTOR2( trans.x, -trans.y ) / trans.w;
screen.x += 1.0f;
screen.y += 1.0f;
screen *= 0.5f;
return screen;
}
Just make sure you #include "d3dx9math.h" first.
This will return a range between 0.0 and 1.0 when inside the screen, you can then multiply it by the screenWith/Height on the .x and .y members of the return vector respectively.