mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
Merge pull request #236 from karelpak1/fix-pitch-quickinput
fix: correct input pitch offset for initial turret rotation
This commit is contained in:
1 file changed
+13
-14
+13
-14
@@ -21,19 +21,20 @@ export function QuickInputs() {
|
|||||||
const turretModelDefinition =
|
const turretModelDefinition =
|
||||||
tankModelDefinition.turrets[protagonist.turret.id];
|
tankModelDefinition.turrets[protagonist.turret.id];
|
||||||
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
||||||
const initialGunPitch =
|
const initialTurretPitch =
|
||||||
tankModelDefinition.initial_turret_rotation?.pitch ?? 0;
|
tankModelDefinition.initial_turret_rotation?.pitch ?? 0;
|
||||||
const hasImprovedVerticalStabilizer = useEquipment(122);
|
const hasImprovedVerticalStabilizer = useEquipment(122);
|
||||||
const hasDownImprovedVerticalStabilizer = useEquipment(124);
|
const hasDownImprovedVerticalStabilizer = useEquipment(124);
|
||||||
|
|
||||||
|
function displayPitch(pitch: number) {
|
||||||
|
return radToDeg(pitch) - initialTurretPitch;
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function syncInputValues(data: ModelTransformEventData) {
|
function syncInputValues(data: ModelTransformEventData) {
|
||||||
if (!pitchInput.current || !yawInput.current) return;
|
if (!pitchInput.current || !yawInput.current) return;
|
||||||
|
|
||||||
pitchInput.current.value = (
|
pitchInput.current.value = displayPitch(data.pitch).toFixed(1);
|
||||||
radToDeg(data.pitch) +
|
|
||||||
(tankModelDefinition.initial_turret_rotation?.pitch ?? 0)
|
|
||||||
).toFixed(1);
|
|
||||||
yawInput.current.value = radToDeg(data.yaw).toFixed(1);
|
yawInput.current.value = radToDeg(data.yaw).toFixed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ export function QuickInputs() {
|
|||||||
return () => {
|
return () => {
|
||||||
modelTransformEvent.off(handleTransformEvent);
|
modelTransformEvent.off(handleTransformEvent);
|
||||||
};
|
};
|
||||||
}, [initialGunPitch]);
|
}, [initialTurretPitch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
@@ -115,19 +116,17 @@ export function QuickInputs() {
|
|||||||
size="1"
|
size="1"
|
||||||
radius="full"
|
radius="full"
|
||||||
style={{ flex: 1, textAlign: "right" }}
|
style={{ flex: 1, textAlign: "right" }}
|
||||||
defaultValue={(
|
defaultValue={displayPitch(modelTransformEvent.last!.pitch).toFixed(1)}
|
||||||
radToDeg(modelTransformEvent.last!.pitch) + initialGunPitch
|
|
||||||
).toFixed(1)}
|
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
const value = Number(pitchInput.current!.value);
|
const value = Number(pitchInput.current!.value);
|
||||||
if (isNaN(value)) {
|
if (isNaN(value)) {
|
||||||
pitchInput.current!.value = (
|
pitchInput.current!.value = displayPitch(
|
||||||
radToDeg(modelTransformEvent.last!.pitch) + initialGunPitch
|
modelTransformEvent.last!.pitch,
|
||||||
).toFixed(1);
|
).toFixed(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [pitch, yaw] = applyPitchYawLimits(
|
const [pitch, yaw] = applyPitchYawLimits(
|
||||||
degToRad(value + initialGunPitch),
|
degToRad(value + initialTurretPitch),
|
||||||
modelTransformEvent.last!.yaw,
|
modelTransformEvent.last!.yaw,
|
||||||
gunModelDefinition.pitch!,
|
gunModelDefinition.pitch!,
|
||||||
turretModelDefinition.yaw,
|
turretModelDefinition.yaw,
|
||||||
@@ -135,8 +134,8 @@ export function QuickInputs() {
|
|||||||
hasDownImprovedVerticalStabilizer,
|
hasDownImprovedVerticalStabilizer,
|
||||||
);
|
);
|
||||||
modelTransformEvent.dispatch({ pitch, yaw });
|
modelTransformEvent.dispatch({ pitch, yaw });
|
||||||
pitchInput.current!.value = (
|
pitchInput.current!.value = displayPitch(
|
||||||
radToDeg(modelTransformEvent.last!.pitch) + initialGunPitch
|
modelTransformEvent.last!.pitch,
|
||||||
).toFixed(1);
|
).toFixed(1);
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
|
|||||||
Reference in new issue
Block a user