mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 07:43:49 +01:00
feat: rotation inputs in static mode
This commit is contained in:
1 parent
c6184acf26
commit
b559878667
4 files changed
+228
-31
No files matched your search
@@ -24,7 +24,7 @@ export const TankModel = memo(() => {
|
|||||||
const hullContainer = useRef<Group>(null);
|
const hullContainer = useRef<Group>(null);
|
||||||
const turretContainer = useRef<Group>(null);
|
const turretContainer = useRef<Group>(null);
|
||||||
const gunContainer = useRef<Group>(null);
|
const gunContainer = useRef<Group>(null);
|
||||||
const mutateTankopediaTemporary = TankopediaEphemeral.useMutation();
|
const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
|
||||||
const tankModelDefinition = useTankModelDefinition();
|
const tankModelDefinition = useTankModelDefinition();
|
||||||
const turretModelDefinition =
|
const turretModelDefinition =
|
||||||
tankModelDefinition.turrets[protagonist.turret.id];
|
tankModelDefinition.turrets[protagonist.turret.id];
|
||||||
@@ -68,7 +68,7 @@ export const TankModel = memo(() => {
|
|||||||
position.set(event.clientX, event.clientY);
|
position.set(event.clientX, event.clientY);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
mutateTankopediaTemporary((draft) => {
|
mutateTankopediaEphemeral((draft) => {
|
||||||
draft.controlsEnabled = false;
|
draft.controlsEnabled = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ export const TankModel = memo(() => {
|
|||||||
translateTexture(deltaX + deltaY);
|
translateTexture(deltaX + deltaY);
|
||||||
}
|
}
|
||||||
function handlePointerUp() {
|
function handlePointerUp() {
|
||||||
mutateTankopediaTemporary((draft) => {
|
mutateTankopediaEphemeral((draft) => {
|
||||||
draft.controlsEnabled = true;
|
draft.controlsEnabled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -124,21 +124,21 @@ export const TankModel = memo(() => {
|
|||||||
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
if (isTurret) {
|
if (!isTurret) return;
|
||||||
position.set(event.clientX, event.clientY);
|
|
||||||
yaw = protagonist.yaw;
|
|
||||||
pitch = protagonist.pitch;
|
|
||||||
|
|
||||||
mutateTankopediaTemporary((draft) => {
|
position.set(event.clientX, event.clientY);
|
||||||
draft.controlsEnabled = false;
|
yaw = protagonist.yaw;
|
||||||
});
|
pitch = protagonist.pitch;
|
||||||
mutateTankopediaTemporary((draft) => {
|
|
||||||
draft.shot = undefined;
|
mutateTankopediaEphemeral((draft) => {
|
||||||
draft.highlightArmor = undefined;
|
draft.controlsEnabled = false;
|
||||||
});
|
});
|
||||||
window.addEventListener('pointermove', handlePointerMove);
|
mutateTankopediaEphemeral((draft) => {
|
||||||
window.addEventListener('pointerup', handlePointerUp);
|
draft.shot = undefined;
|
||||||
}
|
draft.highlightArmor = undefined;
|
||||||
|
});
|
||||||
|
window.addEventListener('pointermove', handlePointerMove);
|
||||||
|
window.addEventListener('pointerup', handlePointerUp);
|
||||||
}
|
}
|
||||||
async function handlePointerMove(event: PointerEvent) {
|
async function handlePointerMove(event: PointerEvent) {
|
||||||
const duel = duelStore.getState();
|
const duel = duelStore.getState();
|
||||||
@@ -166,7 +166,7 @@ export const TankModel = memo(() => {
|
|||||||
draft.protagonist.pitch = normalizeAngleRad(pitch);
|
draft.protagonist.pitch = normalizeAngleRad(pitch);
|
||||||
draft.protagonist.yaw = normalizeAngleRad(yaw);
|
draft.protagonist.yaw = normalizeAngleRad(yaw);
|
||||||
});
|
});
|
||||||
mutateTankopediaTemporary((draft) => {
|
mutateTankopediaEphemeral((draft) => {
|
||||||
draft.controlsEnabled = true;
|
draft.controlsEnabled = true;
|
||||||
});
|
});
|
||||||
window.removeEventListener('pointermove', handlePointerMove);
|
window.removeEventListener('pointermove', handlePointerMove);
|
||||||
@@ -206,10 +206,10 @@ export const TankModel = memo(() => {
|
|||||||
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
mutateTankopediaTemporary((draft) => {
|
mutateTankopediaEphemeral((draft) => {
|
||||||
draft.controlsEnabled = false;
|
draft.controlsEnabled = false;
|
||||||
});
|
});
|
||||||
mutateTankopediaTemporary((draft) => {
|
mutateTankopediaEphemeral((draft) => {
|
||||||
draft.shot = undefined;
|
draft.shot = undefined;
|
||||||
draft.highlightArmor = undefined;
|
draft.highlightArmor = undefined;
|
||||||
});
|
});
|
||||||
@@ -242,7 +242,7 @@ export const TankModel = memo(() => {
|
|||||||
modelTransformEvent.emit({ pitch, yaw });
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
}
|
}
|
||||||
function handlePointerUp() {
|
function handlePointerUp() {
|
||||||
mutateTankopediaTemporary((draft) => {
|
mutateTankopediaEphemeral((draft) => {
|
||||||
draft.controlsEnabled = true;
|
draft.controlsEnabled = true;
|
||||||
});
|
});
|
||||||
mutateDuel((draft) => {
|
mutateDuel((draft) => {
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ export function StaticArmorSceneComponent({
|
|||||||
}),
|
}),
|
||||||
[thickness],
|
[thickness],
|
||||||
);
|
);
|
||||||
|
|
||||||
const outlineMaterial = useMemo(
|
const outlineMaterial = useMemo(
|
||||||
() =>
|
() =>
|
||||||
new LineBasicMaterial({
|
new LineBasicMaterial({
|
||||||
@@ -110,10 +109,19 @@ export function StaticArmorSceneComponent({
|
|||||||
[thickness],
|
[thickness],
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
// if (clip) {
|
||||||
* hook inside an if statement?? don't panic! I assure you the static prop
|
// /**
|
||||||
* never mutates :)
|
// * hook inside an if statement?? don't panic! I assure you the clip prop
|
||||||
*/
|
// * never mutates :)
|
||||||
|
// */
|
||||||
|
// useFrame(() => {
|
||||||
|
// surfaceMaterial.clippingPlanes!.forEach((plane) => {
|
||||||
|
// // console.log(plane.normal);
|
||||||
|
// plane.applyMatrix4(node.matrix);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function handleHighlightArmor(selectedName?: string) {
|
function handleHighlightArmor(selectedName?: string) {
|
||||||
if (selectedName === undefined) {
|
if (selectedName === undefined) {
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
|
import { ThreeEvent, useThree } from '@react-three/fiber';
|
||||||
import { memo, useRef } from 'react';
|
import { memo, useRef } from 'react';
|
||||||
import { Group, Plane, Vector3 } from 'three';
|
import { Group, Plane, Vector2, Vector3 } from 'three';
|
||||||
|
import { applyPitchYawLimits } from '../../core/blitz/applyPitchYawLimits';
|
||||||
import { correctZYTuple } from '../../core/blitz/correctZYTuple';
|
import { correctZYTuple } from '../../core/blitz/correctZYTuple';
|
||||||
|
import { hasEquipment } from '../../core/blitzkit/hasEquipment';
|
||||||
|
import { modelTransformEvent } from '../../core/blitzkit/modelTransform';
|
||||||
import { nameToArmorId } from '../../core/blitzkit/nameToArmorId';
|
import { nameToArmorId } from '../../core/blitzkit/nameToArmorId';
|
||||||
import { resolveArmor } from '../../core/blitzkit/resolveThickness';
|
import { resolveArmor } from '../../core/blitzkit/resolveThickness';
|
||||||
|
import { normalizeAngleRad } from '../../core/math/normalizeAngleRad';
|
||||||
import { useArmor } from '../../hooks/useArmor';
|
import { useArmor } from '../../hooks/useArmor';
|
||||||
import { useModel } from '../../hooks/useModel';
|
import { useModel } from '../../hooks/useModel';
|
||||||
import { useTankModelDefinition } from '../../hooks/useTankModelDefinition';
|
import { useTankModelDefinition } from '../../hooks/useTankModelDefinition';
|
||||||
import { useTankTransform } from '../../hooks/useTankTransform';
|
import { useTankTransform } from '../../hooks/useTankTransform';
|
||||||
import * as Duel from '../../stores/duel';
|
import * as Duel from '../../stores/duel';
|
||||||
|
import * as TankopediaEphemeral from '../../stores/tankopediaEphemeral';
|
||||||
import * as TankopediaPersistent from '../../stores/tankopediaPersistent';
|
import * as TankopediaPersistent from '../../stores/tankopediaPersistent';
|
||||||
import { ModelTankWrapper } from '../Armor/components/ModelTankWrapper';
|
import { ModelTankWrapper } from '../Armor/components/ModelTankWrapper';
|
||||||
import { ArmorType } from '../Armor/components/SpacedArmorScene';
|
import { ArmorType } from '../Armor/components/SpacedArmorScene';
|
||||||
@@ -41,6 +47,10 @@ export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
|||||||
const hullOrigin = correctZYTuple(trackModelDefinition.origin);
|
const hullOrigin = correctZYTuple(trackModelDefinition.origin);
|
||||||
const turretOrigin = correctZYTuple(tankModelDefinition.turretOrigin);
|
const turretOrigin = correctZYTuple(tankModelDefinition.turretOrigin);
|
||||||
const gunOrigin = correctZYTuple(turretModelDefinition.gunOrigin);
|
const gunOrigin = correctZYTuple(turretModelDefinition.gunOrigin);
|
||||||
|
const mutateDuel = Duel.useMutation();
|
||||||
|
const canvas = useThree((state) => state.gl.domElement);
|
||||||
|
const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
|
||||||
|
const duelStore = Duel.useStore();
|
||||||
const maskOrigin =
|
const maskOrigin =
|
||||||
gunModelDefinition.mask === undefined
|
gunModelDefinition.mask === undefined
|
||||||
? undefined
|
? undefined
|
||||||
@@ -127,11 +137,67 @@ export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
|||||||
thickness === undefined ||
|
thickness === undefined ||
|
||||||
(!showPrimaryArmor && !spaced) ||
|
(!showPrimaryArmor && !spaced) ||
|
||||||
(!showSpacedArmor && spaced)
|
(!showSpacedArmor && spaced)
|
||||||
)
|
) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const position = new Vector2();
|
||||||
|
const delta = new Vector2();
|
||||||
|
let pitch = 0;
|
||||||
|
let yaw = 0;
|
||||||
|
|
||||||
|
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
position.set(event.clientX, event.clientY);
|
||||||
|
yaw = protagonist.yaw;
|
||||||
|
pitch = protagonist.pitch;
|
||||||
|
|
||||||
|
mutateTankopediaEphemeral((draft) => {
|
||||||
|
draft.controlsEnabled = false;
|
||||||
|
});
|
||||||
|
mutateTankopediaEphemeral((draft) => {
|
||||||
|
draft.shot = undefined;
|
||||||
|
draft.highlightArmor = undefined;
|
||||||
|
});
|
||||||
|
window.addEventListener('pointermove', handlePointerMove);
|
||||||
|
window.addEventListener('pointerup', handlePointerUp);
|
||||||
|
}
|
||||||
|
async function handlePointerMove(event: PointerEvent) {
|
||||||
|
const duel = duelStore.getState();
|
||||||
|
const hasImprovedVerticalStabilizer = await hasEquipment(
|
||||||
|
122,
|
||||||
|
duel.protagonist.tank.equipment,
|
||||||
|
duel.protagonist.equipmentMatrix,
|
||||||
|
);
|
||||||
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
|
|
||||||
|
delta.set(event.clientX, event.clientY).sub(position);
|
||||||
|
position.set(event.clientX, event.clientY);
|
||||||
|
|
||||||
|
[pitch, yaw] = applyPitchYawLimits(
|
||||||
|
pitch,
|
||||||
|
yaw + delta.x * (Math.PI / boundingRect.width),
|
||||||
|
gunModelDefinition.pitch,
|
||||||
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
|
);
|
||||||
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
|
}
|
||||||
|
function handlePointerUp() {
|
||||||
|
mutateDuel((draft) => {
|
||||||
|
draft.protagonist.pitch = normalizeAngleRad(pitch);
|
||||||
|
draft.protagonist.yaw = normalizeAngleRad(yaw);
|
||||||
|
});
|
||||||
|
mutateTankopediaEphemeral((draft) => {
|
||||||
|
draft.controlsEnabled = true;
|
||||||
|
});
|
||||||
|
window.removeEventListener('pointermove', handlePointerMove);
|
||||||
|
window.removeEventListener('pointerup', handlePointerUp);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<group position={hullOrigin}>
|
<group position={hullOrigin} onPointerDown={onPointerDown}>
|
||||||
<group key={node.uuid} position={turretOrigin}>
|
<group key={node.uuid} position={turretOrigin}>
|
||||||
<StaticArmorSceneComponent
|
<StaticArmorSceneComponent
|
||||||
name={node.name}
|
name={node.name}
|
||||||
@@ -163,11 +229,67 @@ export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
|||||||
thickness === undefined ||
|
thickness === undefined ||
|
||||||
(!showPrimaryArmor && !spaced) ||
|
(!showPrimaryArmor && !spaced) ||
|
||||||
(!showSpacedArmor && spaced)
|
(!showSpacedArmor && spaced)
|
||||||
)
|
) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const position = new Vector2();
|
||||||
|
const delta = new Vector2();
|
||||||
|
let pitch = 0;
|
||||||
|
let yaw = 0;
|
||||||
|
|
||||||
|
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
mutateTankopediaEphemeral((draft) => {
|
||||||
|
draft.controlsEnabled = false;
|
||||||
|
});
|
||||||
|
mutateTankopediaEphemeral((draft) => {
|
||||||
|
draft.shot = undefined;
|
||||||
|
draft.highlightArmor = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
position.set(event.clientX, event.clientY);
|
||||||
|
pitch = protagonist.pitch;
|
||||||
|
yaw = protagonist.yaw;
|
||||||
|
|
||||||
|
window.addEventListener('pointermove', handlePointerMove);
|
||||||
|
window.addEventListener('pointerup', handlePointerUp);
|
||||||
|
}
|
||||||
|
async function handlePointerMove(event: PointerEvent) {
|
||||||
|
const duel = duelStore.getState();
|
||||||
|
const hasImprovedVerticalStabilizer = await hasEquipment(
|
||||||
|
122,
|
||||||
|
duel.protagonist.tank.equipment,
|
||||||
|
duel.protagonist.equipmentMatrix,
|
||||||
|
);
|
||||||
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
|
delta.set(event.clientX, event.clientY).sub(position);
|
||||||
|
position.set(event.clientX, event.clientY);
|
||||||
|
|
||||||
|
[pitch, yaw] = applyPitchYawLimits(
|
||||||
|
pitch - delta.y * (Math.PI / boundingRect.height),
|
||||||
|
yaw + delta.x * (Math.PI / boundingRect.width),
|
||||||
|
gunModelDefinition.pitch,
|
||||||
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
|
);
|
||||||
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
|
}
|
||||||
|
function handlePointerUp() {
|
||||||
|
mutateTankopediaEphemeral((draft) => {
|
||||||
|
draft.controlsEnabled = true;
|
||||||
|
});
|
||||||
|
mutateDuel((draft) => {
|
||||||
|
draft.protagonist.pitch = normalizeAngleRad(pitch);
|
||||||
|
draft.protagonist.yaw = normalizeAngleRad(yaw);
|
||||||
|
});
|
||||||
|
window.removeEventListener('pointermove', handlePointerMove);
|
||||||
|
window.removeEventListener('pointerup', handlePointerUp);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<group position={hullOrigin}>
|
<group position={hullOrigin} onPointerDown={onPointerDown}>
|
||||||
<group
|
<group
|
||||||
key={node.uuid}
|
key={node.uuid}
|
||||||
position={turretOrigin.clone().add(gunOrigin)}
|
position={turretOrigin.clone().add(gunOrigin)}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { ThreeEvent } from '@react-three/fiber';
|
||||||
|
import { Vector2 } from 'three';
|
||||||
|
import { applyPitchYawLimits } from '../blitz/applyPitchYawLimits';
|
||||||
|
import { normalizeAngleRad } from '../math/normalizeAngleRad';
|
||||||
|
import { hasEquipment } from './hasEquipment';
|
||||||
|
import { modelTransformEvent } from './modelTransform';
|
||||||
|
|
||||||
|
export function tankTransformHandlers() {
|
||||||
|
const position = new Vector2();
|
||||||
|
const delta = new Vector2();
|
||||||
|
let pitch = 0;
|
||||||
|
let yaw = 0;
|
||||||
|
|
||||||
|
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
if (isTurret) {
|
||||||
|
position.set(event.clientX, event.clientY);
|
||||||
|
yaw = protagonist.yaw;
|
||||||
|
pitch = protagonist.pitch;
|
||||||
|
|
||||||
|
mutateTankopediaTemporary((draft) => {
|
||||||
|
draft.controlsEnabled = false;
|
||||||
|
});
|
||||||
|
mutateTankopediaTemporary((draft) => {
|
||||||
|
draft.shot = undefined;
|
||||||
|
draft.highlightArmor = undefined;
|
||||||
|
});
|
||||||
|
window.addEventListener('pointermove', handlePointerMove);
|
||||||
|
window.addEventListener('pointerup', handlePointerUp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function handlePointerMove(event: PointerEvent) {
|
||||||
|
const duel = duelStore.getState();
|
||||||
|
const hasImprovedVerticalStabilizer = await hasEquipment(
|
||||||
|
122,
|
||||||
|
duel.protagonist.tank.equipment,
|
||||||
|
duel.protagonist.equipmentMatrix,
|
||||||
|
);
|
||||||
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
|
|
||||||
|
delta.set(event.clientX, event.clientY).sub(position);
|
||||||
|
position.set(event.clientX, event.clientY);
|
||||||
|
|
||||||
|
[pitch, yaw] = applyPitchYawLimits(
|
||||||
|
pitch,
|
||||||
|
yaw + delta.x * (Math.PI / boundingRect.width),
|
||||||
|
gunModelDefinition.pitch,
|
||||||
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
|
);
|
||||||
|
modelTransformEvent.emit({ pitch, yaw });
|
||||||
|
}
|
||||||
|
function handlePointerUp() {
|
||||||
|
mutateDuel((draft) => {
|
||||||
|
draft.protagonist.pitch = normalizeAngleRad(pitch);
|
||||||
|
draft.protagonist.yaw = normalizeAngleRad(yaw);
|
||||||
|
});
|
||||||
|
mutateTankopediaTemporary((draft) => {
|
||||||
|
draft.controlsEnabled = true;
|
||||||
|
});
|
||||||
|
window.removeEventListener('pointermove', handlePointerMove);
|
||||||
|
window.removeEventListener('pointerup', handlePointerUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { onPointerDown };
|
||||||
|
}
|
||||||
Reference in new issue
Block a user