Help WorldToScreen
I'm trying to create a WorldToScreen, this is my function:
But it doesn't convert properly to a 2D position.
The interesting fact is that FOV works perfectly, so, the function only returns TRUE if the player is in my field of view.
Is the problem at the matrixes or at the 3d player position?
If the problem is at matrixes, can someone help me to get ViewMatrix, ProjectMatrix and WorldMatrix of CrossFire?
Thanks
Code:
function WorldToScreen(pDev: IDirect3DDevice9; vWorld: TD3DXVECTOR3; pos: TD3DXVECTOR3): bool;
var
projection, view, world: TD3DXMATRIX;
g_ViewPort: TD3DViewport9;
begin
pDev.GetViewport(g_ViewPort);
pDev.GetTransform(D3DTS_VIEW, view);
pDev.GetTransform(D3DTS_PROJECTION, projection);
pDev.GetTransform(D3DTS_WORLD, world);
pDev.GetViewport(g_ViewPort);
g_ViewPort.X := 0;
g_ViewPort.Y := 0;
g_ViewPort.MinZ := 0;
g_ViewPort.MaxZ := 1;
D3DXVec3Project(Pos, vWorld, g_ViewPort, projection, view, world);
if (Pos.z < 1.0) and (Pos.x > 0.0) and (Pos.y > 0.0) and (Pos.x < g_ViewPort.Width) and (pos.y < g_ViewPort.Height)
then begin
vWorld.x := pos.x;
vWorld.y := pos.y;
vWorld.z := pos.z;
result := true;
end else begin
result := false;
end;
end;
The interesting fact is that FOV works perfectly, so, the function only returns TRUE if the player is in my field of view.
Is the problem at the matrixes or at the 3d player position?
If the problem is at matrixes, can someone help me to get ViewMatrix, ProjectMatrix and WorldMatrix of CrossFire?
Thanks

Your code sucks big time. Sure you can do this in even one line, but small code is not always good code. Most times it's even the other way around.