CSGO: Weird ESP Box behavior
For unknown reason my ESP Boxes showing weird stuff.
My WorldToScreen (flicker free since I draw in SDL_GL_SwapWindow)
bool Utils::WorldToScreen(const Vector &origin, Vector &screen) {
const VMatrix& w2sMatrix = *(VMatrix*)(ViewMatrixPointer);
Vector4D clipCoords(
(origin.x * w2sMatrix.m[0][0]) + (origin.y * w2sMatrix.m[0][1]) + (origin.z * w2sMatrix.m[0][2]) + w2sMatrix.m[0][3],
(origin.x * w2sMatrix.m[1][0]) + (origin.y * w2sMatrix.m[1][1]) + (origin.z * w2sMatrix.m[1][2]) + w2sMatrix.m[1][3],
0.0f,
(origin.x * w2sMatrix.m[3][0]) + (origin.y * w2sMatrix.m[3][1]) + (origin.z * w2sMatrix.m[3][2]) + w2sMatrix.m[3][3]
);
if (clipCoords.w < 0.1f) {
return false;
}
Vector screenCoords((clipCoords.x / clipCoords.w), (clipCoords.y / clipCoords.w), 0.0f);
screen.x = ((Glob::SDLResW / 2) * screenCoords.x) + (screenCoords.x + (Glob::SDLResW / 2));
screen.y = -((Glob::SDLResH / 2) * screenCoords.y) + (screenCoords.y + (Glob::SDLResH / 2));
return true;
}
My GetBox function:
void CEsp::GetBox(C_CSPlayer *PlayerEntity, float *x, float *y, float *w, float *h) {
Vector origin, min, max;
origin = *PlayerEntity->GetOrigin();
min = PlayerEntity->Collideable()->OBBMins() + origin;
max = PlayerEntity->Collideable()->OBBMaxs() + origin;
Vector pointList[] = {
Vector(min.x, min.y, min.z),
Vector(min.x, max.y, min.z),
Vector(max.x, max.y, min.z),
Vector(max.x, min.y, min.z),
Vector(max.x, max.y, max.z),
Vector(min.x, max.y, max.z),
Vector(min.x, min.y, max.z),
Vector(max.x, min.y, max.z)
};
Vector flb, brt, blb, frt, frb, brb, blt, flt;
if (
!Utils::WorldToScreen(pointList[3], flb) ||
!Utils::WorldToScreen(pointList[5], brt) ||
!Utils::WorldToScreen(pointList[0], blb) ||
!Utils::WorldToScreen(pointList[4], frt) ||
!Utils::WorldToScreen(pointList[2], frb) ||
!Utils::WorldToScreen(pointList[1], brb) ||
!Utils::WorldToScreen(pointList[6], blt) ||
!Utils::WorldToScreen(pointList[7], flt)
) {
return;
}
Vector arr[] = { flb, brt, blb, frt, frb, brb, blt, flt };
float left = flb.x;
float top = flb.y;
float right = flb.x;
float bottom = flb.y;
for (int i = 1; i < 8; i++) {
if (left > arr[i].x) {
left = arr[i].x;
}
if (bottom < arr[i].y) {
bottom = arr[i].y;
}
if (right < arr[i].x) {
right = arr[i].x;
}
if (top > arr[i].y) {
top = arr[i].y;
}
}
*x = left;
*y = top;
*w = right - left;
*h = bottom - top;
}
bool CEsp::GetBox(C_CSPlayer *PlayerEntity, float *x, float *y, float *w, float *h) // ...
// ...
if (
!Utils::WorldToScreen(pointList[3], flb) ||
!Utils::WorldToScreen(pointList[5], brt) ||
!Utils::WorldToScreen(pointList[0], blb) ||
!Utils::WorldToScreen(pointList[4], frt) ||
!Utils::WorldToScreen(pointList[2], frb) ||
!Utils::WorldToScreen(pointList[1], brb) ||
!Utils::WorldToScreen(pointList[6], blt) ||
!Utils::WorldToScreen(pointList[7], flt)
) {
return false;
}
// ...
void CEsp::DrawESPForPlayer(C_CSPlayer *PlayerEntity, Color clrTeam) // ...
// ...
float x, y, w, h;
if (!GetBox(PlayerEntity, &x, &y, &w, &h)) {
return;
}
// ...
|