2024-01-03 12:21:30 -06:00
|
|
|
import { OrbitControls } from '@react-three/drei';
|
|
|
|
|
import { useThree } from '@react-three/fiber';
|
2024-01-04 13:37:36 -06:00
|
|
|
import { useEffect, useRef } from 'react';
|
2024-01-03 12:21:30 -06:00
|
|
|
import { OrbitControls as OrbitControlsClass } from 'three-stdlib';
|
2024-01-04 13:06:40 -06:00
|
|
|
import { useTankopedia } from '../../../../../stores/tankopedia';
|
2024-01-03 12:21:30 -06:00
|
|
|
|
2024-01-04 13:37:36 -06:00
|
|
|
export function Controls() {
|
2024-01-03 12:21:30 -06:00
|
|
|
const camera = useThree((state) => state.camera);
|
|
|
|
|
const orbitControls = useRef<OrbitControlsClass>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-01-04 13:37:36 -06:00
|
|
|
camera.position.set(-5, 4, -20);
|
|
|
|
|
orbitControls.current?.target.set(0, 1.5, 0);
|
2024-01-13 16:48:20 -06:00
|
|
|
|
|
|
|
|
const unsubscribe = useTankopedia.subscribe(
|
|
|
|
|
(state) => state.model.visual.controlsEnabled,
|
|
|
|
|
(enabled) => {
|
|
|
|
|
if (orbitControls.current) orbitControls.current.enabled = enabled;
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return unsubscribe;
|
2024-01-04 13:37:36 -06:00
|
|
|
}, []);
|
2024-01-03 12:21:30 -06:00
|
|
|
|
2024-01-06 18:17:04 -06:00
|
|
|
return (
|
2024-01-12 20:22:53 -06:00
|
|
|
<OrbitControls
|
|
|
|
|
ref={orbitControls}
|
2024-01-13 16:48:20 -06:00
|
|
|
enabled={useTankopedia.getState().model.visual.controlsEnabled}
|
2024-01-12 20:22:53 -06:00
|
|
|
rotateSpeed={0.25}
|
|
|
|
|
enableDamping={false}
|
|
|
|
|
/>
|
2024-01-06 18:17:04 -06:00
|
|
|
);
|
2024-01-03 12:21:30 -06:00
|
|
|
}
|