void CASW_VGUI_Queen_Health_Panel::PositionAroundQueen() { C_BaseEntity *pEnt = GetQueen(); if (!pEnt) return; // find the volume this entity takes up Vector mins, maxs; pEnt->GetRenderBoundsWorldspace(mins,maxs); // pull out all 8 corners of this volume Vector worldPos[8]; Vector screenPos[8]; worldPos[0] = mins; worldPos[1] = mins; worldPos[1].x = maxs.x; worldPos[2] = mins; worldPos[2].y = maxs.y; worldPos[3] = mins; worldPos[3].z = maxs.z; worldPos[4] = mins; worldPos[5] = maxs; worldPos[5].x = mins.x; worldPos[6] = maxs; worldPos[6].y = mins.y; worldPos[7] = maxs; worldPos[7].z = mins.z; // convert them to screen space for (int k=0;k<8;k++) { debugoverlay->ScreenPosition( worldPos[k], screenPos[k] ); } // find the rectangle bounding all screen space points Vector topLeft = screenPos[0]; Vector bottomRight = screenPos[0]; for (int k=0;k<8;k++) { topLeft.x = MIN(screenPos[k].x, topLeft.x); topLeft.y = MIN(screenPos[k].y, topLeft.y); bottomRight.x = MAX(screenPos[k].x, bottomRight.x); bottomRight.y = MAX(screenPos[k].y, bottomRight.y); } int BracketSize = 0; // todo: set by screen res? // pad it a bit topLeft.x -= BracketSize * 2; topLeft.y -= BracketSize * 2; bottomRight.x += BracketSize * 2; bottomRight.y += BracketSize * 2; int w = ScreenWidth() * 0.6f; int h = ScreenHeight() * 0.02f; SetBounds( (bottomRight.x + topLeft.x) * 0.5f - w * 0.5f, topLeft.y, w, h); }