ESP not working
Hey guys. This is my first attempt at an internal ESP, and its having some issues. If people are on the far left side of my screen, the esp will not work correctly, but if they’re on the right side it works fine.
bool ScreenTransform(const Vector& point, Vector& screen)
{
float w;
const VMatrix& worldToScreen = Interfaces.Engine->WorldToScreenMatrix();
screen.x = worldToScreen[0][0] * point[0] + worldToScreen[0][1] * point[1] + worldToScreen[0][2] * point[2] + worldToScreen[0][3];
screen.y = worldToScreen[1][0] * point[0] + worldToScreen[1][1] * point[1] + worldToScreen[1][2] * point[2] + worldToScreen[1][3];
w = worldToScreen[3][0] * point[0] + worldToScreen[3][1] * point[1] + worldToScreen[3][2] * point[2] + worldToScreen[3][3];
screen.z = 0.0f;
bool behind = false;
if (w < 0.001f)
{
behind = true;
screen.x *= 100000;
screen.y *= 100000;
}
else
{
behind = false;
float invw = 1.0f / w;
screen.x *= invw;
screen.y *= invw;
}
return behind;
}
bool WorldToScreen(const Vector& origin, Vector& screen)
{
if (!ScreenTransform(origin, screen))
{
int ScreenWidth, ScreenHeight;
Interfaces.Engine->GetScreenSize(ScreenWidth, ScreenHeight);
float x = ScreenWidth / 2;
float y = ScreenHeight / 2;
x += 0.5 * screen.x * ScreenWidth + 0.5;
y -= 0.5 * screen.y * ScreenHeight + 0.5;
screen.x = x;
screen.y = y;
return true;
}
return false;
}
here is how it’s called
void esp()
{
CBaseEntity* me = Interfaces.ClientEntList->GetClientEntity(Interfaces.Engine->GetLocalPlayer());
for (int players = 0; players < Interfaces.Globals->maxClients; players++)
{
CBaseEntity* entity = Interfaces.ClientEntList->GetClientEntity(players);
if (!entity) { continue; }
if (!me) { continue; }
if (entity == me) { continue; }
if (entity->isAlive()) { continue; }
if (entity->IsDormant()) { continue; }
if (!entity->GetClientClass()->m_ClassID == 35) { continue; }
Vector pos3D, pos;
Vector head3D, head;
Vector max = entity->GetCollideable()->OBBMaxs();
pos3D = entity->GetBonePosition(1);
head3D = pos3D + Vector(0, 0, max.z);
WorldToScreen(pos3D, pos);
WorldToScreen(head3D, head);
Interfaces.Surface->SetDrawColor(255, 0, 0, 255);
Interfaces.Surface->DrawLine(pos.x, pos.y, head.x, head.y);
}
}
|