1. ## ViewMatrix problem

I found some functions for processing 3D position to a point on a 2D screen.
But it is not working properly, here's the function:
Code:
```bool WorldToScreen2(float * from, float * to, float fovY, TWorldToScreenMatrix firstPersonTransform, int ScreenWidth, int ScreenHeight)
{
int height = ScreenHeight;
int width = ScreenWidth;
float aspect = (float)width /  (float)height;

D3DXVECTOR3 vOrigin = D3DXVECTOR3(firstPersonTransform.flMatrix[3][0],firstPersonTransform.flMatrix[3][1],firstPersonTransform.flMatrix[3][2]);
D3DXVECTOR3 vLeft    = D3DXVECTOR3(firstPersonTransform.flMatrix[0][0],firstPersonTransform.flMatrix[0][1],firstPersonTransform.flMatrix[0][2]);
D3DXVECTOR3 vUp        = D3DXVECTOR3(firstPersonTransform.flMatrix[1][0],firstPersonTransform.flMatrix[1][1],firstPersonTransform.flMatrix[1][2]);
D3DXVECTOR3 vForward = D3DXVECTOR3(firstPersonTransform.flMatrix[2][0],firstPersonTransform.flMatrix[2][1],firstPersonTransform.flMatrix[2][2]);

D3DXMATRIX viewMatrix;
D3DXMatrixIdentity(&viewMatrix);
viewMatrix._11 = vLeft.x; viewMatrix._12 = vUp.x; viewMatrix._13 = vForward.x;
viewMatrix._21 = vLeft.y; viewMatrix._22 = vUp.y; viewMatrix._23 = vForward.y;
viewMatrix._31 = vLeft.z; viewMatrix._32 = vUp.z; viewMatrix._33 = vForward.z;

viewMatrix._41 = -D3DXVec3Dot(&vOrigin, &vLeft);
viewMatrix._42 = -D3DXVec3Dot(&vOrigin, &vUp);
viewMatrix._43 = -D3DXVec3Dot(&vOrigin, &vForward);

D3DXMATRIXA16 Proj;
D3DXMatrixPerspectiveFovRH( &Proj, fovY,  aspect , 0.1f,  10000.0f);
D3DXMATRIXA16 viewProjecti******** = viewMatrix * Proj;

float mX = width * 0.5f ;
float mY = height * 0.5f ;

float w =
viewProjecti********(0,3) * from[0] +
viewProjecti********(1,3) * from[1] +
viewProjecti********(2,3) * from[2] +
viewProjecti********(3,3);

if( w < 0.0001f )
{
return false;
}

float x =
viewProjecti********(0,0) * from[0] +
viewProjecti********(1,0) * from[1] +
viewProjecti********(2,0) * from[2] +
viewProjecti********(3,0);

float y =
viewProjecti********(0,1) * from[0] +
viewProjecti********(1,1) * from[1] +
viewProjecti********(2,1) * from[2] +
viewProjecti********(3,1);

to[0] = mX + mX * x / w;
to[1] = mY - mY * y / w;

return true;
}```
My structure TWorldToScreenMatrix:
Code:
```typedef struct
{
float flMatrix [4][4];
}TWorldToScreenMatrix;```
Original code:
Code:
```bool cReader::worldToScreen(fb::Vec3 vWorldLocationVec3,fb::Vec3* vOut)
{
int height = getScreenHeight();
int width = getScreenWidth();
float aspect = (float)width /  (float)height;

fb::Mat4 firstPersonTransform;FLOAT fovY;
DWORD OffsetGameRenderer = 0x02384D78;
DWORD GameRenderer;
ReadProcessMemory(pHandle, (void*)(GameRenderer + 0x98), &fovY, sizeof(FLOAT), NULL);
ReadProcessMemory(pHandle, (void*)(GameRenderer + 0x50), &firstPersonTransform, sizeof(fb::Mat4), NULL);

D3DXVECTOR3 vOrigin = D3DXVECTOR3(firstPersonTransform[3][0],firstPersonTransform[3][1],firstPersonTransform[3][2]);
D3DXVECTOR3 vLeft    = D3DXVECTOR3(firstPersonTransform[0][0],firstPersonTransform[0][1],firstPersonTransform[0][2]);
D3DXVECTOR3 vUp        = D3DXVECTOR3(firstPersonTransform[1][0],firstPersonTransform[1][1],firstPersonTransform[1][2]);
D3DXVECTOR3 vForward = D3DXVECTOR3(firstPersonTransform[2][0],firstPersonTransform[2][1],firstPersonTransform[2][2]);

D3DXMATRIX viewMatrix;
D3DXMatrixIdentity(&viewMatrix);
viewMatrix._11 = vLeft.x; viewMatrix._12 = vUp.x; viewMatrix._13 = vForward.x;
viewMatrix._21 = vLeft.y; viewMatrix._22 = vUp.y; viewMatrix._23 = vForward.y;
viewMatrix._31 = vLeft.z; viewMatrix._32 = vUp.z; viewMatrix._33 = vForward.z;

viewMatrix._41 = -D3DXVec3Dot(&vOrigin, &vLeft);
viewMatrix._42 = -D3DXVec3Dot(&vOrigin, &vUp);
viewMatrix._43 = -D3DXVec3Dot(&vOrigin, &vForward);

D3DXMATRIXA16 Proj;
D3DXMatrixPerspectiveFovRH( &Proj, fovY,  aspect , 0.1f,  10000.0f);
D3DXMATRIXA16 viewProjecti******** = viewMatrix * Proj;

float mX = width * 0.5f ;
float mY = height * 0.5f ;

float w =
viewProjecti********(0,3) * vWorldLocationVec3.x +
viewProjecti********(1,3) * vWorldLocationVec3.y +
viewProjecti********(2,3) * vWorldLocationVec3.z +
viewProjecti********(3,3);

if( w < 0.0001f )
{
vOut->z = w;

return false;
}

float x =
viewProjecti********(0,0) * vWorldLocationVec3.x +
viewProjecti********(1,0) * vWorldLocationVec3.y +
viewProjecti********(2,0) * vWorldLocationVec3.z +
viewProjecti********(3,0);

float y =
viewProjecti********(0,1) * vWorldLocationVec3.x +
viewProjecti********(1,1) * vWorldLocationVec3.y +
viewProjecti********(2,1) * vWorldLocationVec3.z +
viewProjecti********(3,1);

vOut->x = mX + mX * x / w;
vOut->y = mY - mY * y / w;
vOut->z = w;

return true;
}```
Of course, functions ReadProcessMemory and Offset gave earlier in another function, but the data from it are used in my function WorldToScreen2.

Can anyone help me improve functionality or write a new that will work properly?

I would like to write the External Hack.

2. what is wrong? instead of using TWorldToScreenMatrix , use D3DXMATRIX