Hi, so I am making an Assault Cube ESP (with directx9) in c++. This is my first ESP so sorry if this is an obvious mistake, but I have done a lot of research and I still have no idea what's wrong. Well, I know the problem lies within my W2S function, I just don't know what I did wrong. I am going to share a screenshot of the values from the W2S function, what the ESP looks like, how I made the W2S and my ESP function. I'm not gonna include the directx9 drawing functions I used b/c I've already tested it out many times, and it draws in the correct place at all times. Thanks in advanced!
W2S:
Code:
bool WorldToScreen(Vector3 pos, Vector2 &screenPos, int windowWidth, int windowHeight)
{
Vector3 screenCoord;
screenCoord.x = pos.x * viewMatrix[0] + pos.y * viewMatrix[4] + pos.z * viewMatrix[8] + viewMatrix[12];
screenCoord.y = pos.x * viewMatrix[1] + pos.y * viewMatrix[5] + pos.z * viewMatrix[9] + viewMatrix[13];
screenCoord.w = pos.x * viewMatrix[3] + pos.y * viewMatrix[7] + pos.z * viewMatrix[11] + viewMatrix[15];
if (screenCoord.w < 0.1f)
return false;
Vector3 ndc;
ndc.x = screenCoord.x / screenCoord.w;
ndc.y = screenCoord.y / screenCoord.w;
screenPos.x = (windowWidth / 2 * ndc.x) + (ndc.x + windowWidth / 2);
screenPos.y = -(windowHeight / 2 * ndc.y) + (ndc.y + windowHeight / 2);
std::cout << "X Pos " << screenPos.x << "Y Pos " << screenPos.y << std::endl;
return true;
}
ESP Function:
Code:
void ESP(HANDLE hProc)
{
// View Matrix
ReadProcessMemory(hProc, (BYTE*)viewMatrixAddress, &viewMatrix, sizeof(viewMatrix), NULL);
Entity entity[32];
Vector2 entityScreenPos[32];
std::vector<unsigned int> pos = { xPosOffset, yPosOffset, zPosOffset };
for (int i = 1; i < 32; i++)
{
FindEntityPos(hProc, entityList[i], pos, entity[i].position);
bool draw = WorldToScreen(entity[i].position, entityScreenPos[i], windowRect.right - windowRect.left, windowRect.bottom - windowRect.top);
if (draw == true)
{
DrawESP(entityScreenPos[i].x, entityScreenPos[i].y, 50, 100, i);
}
else
{
continue;
}
}
}