Why do you set the ViewPort dimensions to zero?
Code:
bool worldToScreen(IDirect3DDevice9 &device, D3DXVECTOR3 worldPos,
D3DXVECTOR2 &screenPos)
{
D3DXMATRIX view, projection, world;
D3DVIEWPORT9 viewPort;
if ((device.GetTransform(D3DTS_VIEW, &view ) != D3D_OK) ||
(device.GetTransform(D3DTS_PROJECTION, &projection) != D3D_OK) ||
(device.GetTransform(D3DTS_WORLD, &world ) != D3D_OK) ||
(device.GetViewport(&viewPort) != D3D_OK))
{
return false;
}
D3DXVECTOR3 screenPos3D;
D3DXVec3Project(&screenPos3D, &worldPos, &viewPort, &projection, &view, &world);
if (screenPos3D.z >= 1)
{
return false;
}
screenPos.x = screenPos3D.x;
screenPos.y = screenPos3D.y;
return true;
}
Edit: As you are using Delphi, you have to make 'pos' an output parameter:
Code:
function WorldToScreen(pDev: IDirect3DDevice9; vWorld: TD3DXVECTOR3; var pos: TD3DXVECTOR3): Boolean;
Without the 'var' modifier you will work on a local copy.