Developer knowledge network · moderated exchange

مجتمع الكود غير الموثوق به

أبحاث المطورين، مجتمع الهندسة العكسية والترميز

Knowledge indexيعيش
4Categories
919Threads
2.8Kدعامات
Tutorial

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

matrix_math_guy
Math Specialist
MEMBER
مندوب: 105
تاريخ الانضمام: Aug 2018
دعامات: 52
شكرًا: 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
مندوب: 202
تاريخ الانضمام: Apr 2019
دعامات: 54
شكرًا: 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
مندوب: 72
تاريخ الانضمام: Sep 2019
دعامات: 32
شكرًا: 16
3 weeks ago · Aug 2, 2026 10:06 AM
#3

Clean 2D box math.