Developer knowledge network ยท moderated exchange

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Knowledge indexLive
4Categories
919Threads
2.8KPosts
Tutorial

Screen-Space Coordinate Bounding Box Calculation with Perspective Distance Scaling [v2.4 Technical Discussion]

matrix_math_guy
Math Specialist
MEMBER
Rep: 105
Join Date: Aug 2018
Posts: 52
Thanks: 41
3 weeks ago ยท Aug 1, 2026 3:51 PM
#1

Calculating dynamic 2D bounding boxes from 3D player coordinates:

CPP
struct BoundingBox2D { float x, y, w, h; };

bool GetPlayerBoundingBox(Vector3 headWorld, Vector3 feetWorld, const Matrix4x4& vMatrix, BoundingBox2D& outBox) {
    Vector2 headScreen, feetScreen;
    if (!WorldToScreen(headWorld, headScreen, vMatrix) || !WorldToScreen(feetWorld, feetScreen, vMatrix)) return false;
    
    float height = feetScreen.y - headScreen.y;
    float width = height * 0.45f; // Standard character aspect ratio
    
    outBox.x = headScreen.x - (width * 0.5f);
    outBox.y = headScreen.y;
    outBox.w = width;
    outBox.h = height;
    return true;
}
imgui_artisan
UI Designer
MEMBER
Rep: 202
Join Date: Apr 2019
Posts: 54
Thanks: 28
3 weeks ago ยท Aug 1, 2026 9:05 PM
#2

The 0.45 aspect ratio multiplier fits character proportions accurately across all distances.

raycast_ryan
Ballistics Dev
MEMBER
Rep: 72
Join Date: Sep 2019
Posts: 32
Thanks: 16
3 weeks ago ยท Aug 2, 2026 10:06 AM
#3

Clean 2D box math.