3주 전 · Aug 1, 2026 3:51 PM
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;
}