mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
fix: capture model transform
This commit is contained in:
1 parent
e68b4bea5d
commit
5b76a08167
1 file changed
+14
-5
@@ -5,11 +5,15 @@ import {
|
|||||||
TrackDefinition,
|
TrackDefinition,
|
||||||
TurretDefinition,
|
TurretDefinition,
|
||||||
} from '@blitzkit/core';
|
} from '@blitzkit/core';
|
||||||
|
import { invalidate } from '@react-three/fiber';
|
||||||
import { type RefObject, useEffect } from 'react';
|
import { type RefObject, useEffect } from 'react';
|
||||||
import { Euler, Group, Vector3 } from 'three';
|
import { Euler, Group, Vector3 } from 'three';
|
||||||
import { degToRad } from 'three/src/math/MathUtils.js';
|
import { degToRad } from 'three/src/math/MathUtils.js';
|
||||||
import { correctZYTuple } from '../core/blitz/correctZYTuple';
|
import { correctZYTuple } from '../core/blitz/correctZYTuple';
|
||||||
import { modelTransformEvent } from '../core/blitzkit/modelTransform';
|
import {
|
||||||
|
modelTransformEvent,
|
||||||
|
type ModelTransformEventData,
|
||||||
|
} from '../core/blitzkit/modelTransform';
|
||||||
import { Duel } from '../stores/duel';
|
import { Duel } from '../stores/duel';
|
||||||
import { useTankModelDefinition } from './useTankModelDefinition';
|
import { useTankModelDefinition } from './useTankModelDefinition';
|
||||||
|
|
||||||
@@ -33,8 +37,11 @@ export function useTankTransform(
|
|||||||
const gunPosition = new Vector3();
|
const gunPosition = new Vector3();
|
||||||
const gunRotation = new Euler();
|
const gunRotation = new Euler();
|
||||||
|
|
||||||
function handleModelTransform() {
|
function handleModelTransform(modelTransform?: ModelTransformEventData) {
|
||||||
const { yaw, pitch } = duelStore.getState().protagonist;
|
const duel = duelStore.getState();
|
||||||
|
const yaw = modelTransform?.yaw ?? duel.protagonist.yaw;
|
||||||
|
const pitch = modelTransform?.pitch ?? duel.protagonist.pitch;
|
||||||
|
|
||||||
gunPosition
|
gunPosition
|
||||||
.set(0, 0, 0)
|
.set(0, 0, 0)
|
||||||
.sub(hullOrigin)
|
.sub(hullOrigin)
|
||||||
@@ -80,6 +87,8 @@ export function useTankTransform(
|
|||||||
turretPosition.add(turretOrigin).add(hullOrigin);
|
turretPosition.add(turretOrigin).add(hullOrigin);
|
||||||
turretContainer.current?.position.copy(turretPosition);
|
turretContainer.current?.position.copy(turretPosition);
|
||||||
turretContainer.current?.rotation.copy(turretRotation);
|
turretContainer.current?.rotation.copy(turretRotation);
|
||||||
|
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleModelTransform();
|
handleModelTransform();
|
||||||
@@ -89,11 +98,11 @@ export function useTankTransform(
|
|||||||
const unsubscribes = [
|
const unsubscribes = [
|
||||||
duelStore.subscribe(
|
duelStore.subscribe(
|
||||||
(state) => state.protagonist.pitch,
|
(state) => state.protagonist.pitch,
|
||||||
handleModelTransform,
|
() => handleModelTransform(),
|
||||||
),
|
),
|
||||||
duelStore.subscribe(
|
duelStore.subscribe(
|
||||||
(state) => state.protagonist.yaw,
|
(state) => state.protagonist.yaw,
|
||||||
handleModelTransform,
|
() => handleModelTransform(),
|
||||||
),
|
),
|
||||||
() => modelTransformEvent.off(handleModelTransform),
|
() => modelTransformEvent.off(handleModelTransform),
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in new issue
Block a user