Files
blitzkit/packages/website/src/components/InitialCameraAligner.tsx
T

31 lines
987 B
TypeScript
Raw Normal View History

2026-03-31 14:11:45 -05:00
import { useEffect } from "react";
import { degToRad } from "three/src/math/MathUtils.js";
import { Duel } from "../../../../../../stores/duel";
2026-09-23 17:25:51 -05:00
import { api } from "../api/dynamic";
import { applyPitchYawLimits } from "../core/blitz/applyPitchYawLimits";
import { modelTransformEvent } from "../core/blitzkit/modelTransform";
2025-08-12 13:43:11 -05:00
2026-08-30 14:26:08 -05:00
const modelDefinitions = await api.models();
2025-08-12 13:43:11 -05:00
2026-09-23 17:25:51 -05:00
export function InitialCameraAligner() {
2025-08-12 13:43:11 -05:00
const tank = Duel.use((state) => state.protagonist.tank);
const turret = Duel.use((state) => state.protagonist.turret);
const gun = Duel.use((state) => state.protagonist.gun);
const tankModel = modelDefinitions.models[tank.id];
const turretModel = tankModel.turrets[turret.id];
2025-08-18 12:06:14 -05:00
const gunModel = turretModel.guns[gun.id];
2025-08-12 13:43:11 -05:00
useEffect(() => {
const [pitch, yaw] = applyPitchYawLimits(
degToRad(8),
degToRad(25),
2026-03-31 14:11:45 -05:00
gunModel.pitch!,
2025-08-12 13:43:11 -05:00
turretModel.yaw,
);
modelTransformEvent.dispatch({ pitch, yaw });
}, []);
return null;
}