3D 리플레이 1인칭 시야: 세로 70° 고정 대신 게임처럼 가로 103° (16:9 게임 화면을 창에 꽉 차게 잘라 보여 줌 — 가로로 긴 창에서 약 120° 까지 넓어지던 것) · 줌은 tan 배율

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-21 22:30:57 +09:00
parent c4f576941c
commit 59cfe1c377
3 changed files with 37 additions and 3 deletions

View File

@@ -4,7 +4,7 @@ import assert from 'node:assert/strict';
import type { ReplayFile } from '../../web/src/lib/replay.ts';
import { buildDirector, shotIndexAt, FIGHT_LEAD, type Shot } from '../../web/src/lib/director.ts';
import { boardAt, boardIndex, loadoutAt, sideSwaps, teamScoreAt } from '../../web/src/lib/scoreboard.ts';
import { fitDistance } from '../../web/src/lib/director.ts';
import { fitDistance, gameFov } from '../../web/src/lib/director.ts';
import * as THREE from '../../web/node_modules/three/build/three.module.js';
// 선수 0·1·4 아군, 2·3·5 상대. 라운드 1: 구매 0~30초, 교전 30초~, 끝 90초. 라운드 2: 100초~ (공수 교대: 시작 자리가 100m 옮겨 감)
@@ -180,3 +180,23 @@ test('전략 보기 카메라: 시야각 · 화면비 · 기울기를 넣어 구
assert.ok(edge > 0.84, `너무 멀다 ${edge}`);
}
});
test('1인칭 시야: 창이 넓어도 게임처럼 가로 103° · 좁은 창은 게임 세로 시야 · 줌은 배율만큼 좁아진다', () => {
const rad = (d: number) => (d * Math.PI) / 180;
const hfov = (aspect: number, zoom = 1) => (2 * Math.atan(Math.tan(rad(gameFov(aspect, zoom) / 2)) * aspect) * 180) / Math.PI;
// 16:9 = 게임 화면 그대로 (가로 103°, 세로 약 70.5°)
assert.ok(Math.abs(hfov(16 / 9) - 103) < 1e-9);
assert.ok(Math.abs(gameFov(16 / 9) - 70.53) < 0.01);
// 가로로 긴 창 (노트북의 리플레이 창 비율 2.5 등): 가로가 103° 를 넘지 않는다 (예전엔 세로 70° 고정이라 약 120°)
for (const a of [2, 2.5, 3.2]) assert.ok(Math.abs(hfov(a) - 103) < 1e-9, `화면비 ${a}: ${hfov(a)}`);
// 좁은 창: 게임 세로 시야 그대로, 가로는 103° 보다 좁다
for (const a of [1, 1.5]) {
assert.ok(Math.abs(gameFov(a) - gameFov(16 / 9)) < 1e-9);
assert.ok(hfov(a) < 103);
}
// 줌: 화면 가운데 물체가 배율만큼 크게 (tan 이 배율만큼 작아진다)
for (const z of [1.25, 2.5, 5]) {
const k = Math.tan(rad(gameFov(2.5) / 2)) / Math.tan(rad(gameFov(2.5, z) / 2));
assert.ok(Math.abs(k - z) < 1e-9, `배율 ${z}: ${k}`);
}
});

View File

@@ -16,7 +16,7 @@ import CrosshairPanel from './CrosshairPanel';
import { buildAnimIndex, rigInput } from '../lib/replayAnim';
import { abilityLook, type AbilityLook } from '../lib/abilities';
import { loadVfxDb, vfxCoverage, VfxObject, type Place, type VfxDb } from '../lib/vfx';
import { buildDirector, fitDistance, shotIndexAt, SHOT_LABEL } from '../lib/director';
import { buildDirector, fitDistance, gameFov, shotIndexAt, SHOT_LABEL } from '../lib/director';
import { boardIndex } from '../lib/scoreboard';
import ReplayScoreboard from './ReplayScoreboard';
@@ -1028,7 +1028,7 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
}
// 1인칭 팔 · 총: 들고 있는 무기 · 꺼낸 때 · 사격 · 재장전 · 줌 · 걷기
const fp = p && !isDead(replay, selIdx, t) ? fpState(selIdx, t) : null;
const zoomFov = fp ? 70 / (fp.zoom === 0 ? 1 : fp.sniper ? (fp.zoom >= 2 ? 5 : 2.5) : 1.25) : 70;
const zoomFov = gameFov(camera.aspect, fp ? (fp.zoom === 0 ? 1 : fp.sniper ? (fp.zoom >= 2 ? 5 : 2.5) : 1.25) : 1);
if (camera.fov !== zoomFov) {
camera.fov = zoomFov;
camera.updateProjectionMatrix();

View File

@@ -299,3 +299,17 @@ export function fitDistance(points: V3[], target: V3, dir: V3, fovDeg: number, a
}
return need;
}
/** 발로란트 시야: 16:9 화면에서 가로 103° (바꿀 수 없음) */
export const GAME_HFOV = 103;
const GAME_TAN_H = Math.tan(((GAME_HFOV / 2) * Math.PI) / 180);
/**
* 1인칭 세로 시야각(three.js fov). 게임 화면(16:9 · 가로 103°)을 이 창 비율에 꽉 차게 잘라 보여 준다:
* 16:9 보다 넓은 창은 가로 103° 를 지키고(위아래가 잘림), 좁은 창은 게임 세로 시야(약 70.5°)를 지킨다(양옆이 잘림).
* 그래서 어느 창에서도 게임보다 넓게 보이지 않는다. zoom 은 배율 (정조준 1.25 · 저격 2.5 · 5)
*/
export function gameFov(aspect: number, zoom = 1): number {
const tv = GAME_TAN_H / Math.max(aspect, 16 / 9) / zoom;
return (2 * Math.atan(tv) * 180) / Math.PI;
}