1개월 전 · Jul 18, 2026 8:32 PM
Formula for projecting 3D player coordinates onto a 2D rotating top-down radar:
CPP
Vector2 WorldToRadar(Vector3 localPos, Vector3 targetPos, float localYaw, float radarRadius, float zoomScale) {
float dx = targetPos.x - localPos.x;
float dy = targetPos.y - localPos.y;
// Convert local yaw to radians
float yawRad = localYaw * (3.14159265f / 180.0f);
// Rotate vector by camera orientation
float rotatedX = dx * cosf(yawRad) - dy * sinf(yawRad);
float rotatedY = dx * sinf(yawRad) + dy * cosf(yawRad);
// Scale distance
float screenX = rotatedX * zoomScale;
float screenY = rotatedY * zoomScale;
// Clamp to radar circular boundary
float dist = sqrtf(screenX * screenX + screenY * screenY);
if (dist > radarRadius) {
screenX = (screenX / dist) * radarRadius;
screenY = (screenY / dist) * radarRadius;
}
return Vector2(screenX, screenY);
}