Hi
I have the x,y,z coordinates and the pitch/yaw of my player entity. Same with the enemy players. I tried to find out their screen location via World2Screen.
This is my function
Code:
D3DXVECTOR3 *World2Screen(LPDIRECT3DDEVICE9 pDevice, D3DXVECTOR3 &vScreenCoord, D3DXVECTOR3 vEnemy)
{
if( !pDevice ) return NULL;
D3DXMATRIX matProj;
float fAspect = (float)(1280) / 720;
D3DXMatrixPerspectiveFovRH(&matProj, (float)(D3DX_PI/180*90), fAspect, 0.1, -1);
float *pX = (float*)(*(DWORD*)(Base)+0x60);
float *pY = (float*)(*(DWORD*)(Base)+0x68);
float *pZ = (float*)(*(DWORD*)(Base)+0x64);
float *pitch = (float*)(*(DWORD*)(Base)+0x6C);
float *yaw = (float*)(*(DWORD*)(Base)+0x70);
D3DXVECTOR3 vEye ( *pX, *pY, *pZ);
D3DXVECTOR3 vTarget ( *pX + *yaw, *pY + (*pitch * -1), *pZ);
D3DXVECTOR3 vUp ( 0, 0, 1 );
D3DXMATRIX matView;
D3DXMatrixLookAtRH( &matView, &vEye, &vTarget, &vUp);
D3DVIEWPORT9 viewPort;
D3DXMATRIX identity;
pDevice->GetViewport( &viewPort );
D3DXMatrixIdentity( &identity );
D3DXVec3Project(&vScreenCoord, &vEnemy, &viewPort, &matProj, &matView, &identity );
if(vScreenCoord.z < 1)
return &vScreenCoord;
return NULL;
}
It kind of works but the 2d coordinates are absolutely not correct. I will post some screenshots l8r.
[img]http://img7.imagebanan*****m/img/z4bk0r00/fu1.png[/img]
[img]http://img6.imagebanan*****m/img/l03mfttv/fu2.png[/img]