Developer knowledge network · moderated exchange

UnreliableCode コミュニティ

開発者リサーチ、リバース エンジニアリング、コーディング コミュニティ

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 週間前 · 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 週間前 · 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 週間前 · Aug 2, 2026 10:06 AM
#3

Clean 2D box math.