mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-19 20:03:51 +01:00
feat: gun pitch
This commit is contained in:
1 parent
0d5b2aedc7
commit
9bd26ef3bf
2 files changed
+122
-43
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { OrbitControls } from '@react-three/drei';
|
||||
import { useThree } from '@react-three/fiber';
|
||||
import { RefObject, useEffect, useRef } from 'react';
|
||||
import { RefObject, memo, useEffect, useRef } from 'react';
|
||||
import { Box3, Group, Vector3 } from 'three';
|
||||
import { OrbitControls as OrbitControlsImpl } from 'three-stdlib';
|
||||
|
||||
@@ -9,23 +9,24 @@ interface TankAlignmentProps {
|
||||
orbit: boolean;
|
||||
}
|
||||
|
||||
export function TankAlignment({ model, orbit }: TankAlignmentProps) {
|
||||
const controls = useRef<OrbitControlsImpl>(null);
|
||||
const camera = useThree((state) => state.camera);
|
||||
export const TankAlignment = memo(
|
||||
({ model, orbit }: TankAlignmentProps) => {
|
||||
const controls = useRef<OrbitControlsImpl>(null);
|
||||
const camera = useThree((state) => state.camera);
|
||||
|
||||
useEffect(() => {
|
||||
const box = new Box3().setFromObject(model.current!);
|
||||
const diameter = Math.max(box.max.x - box.min.x, box.max.z - box.min.z);
|
||||
useEffect(() => {
|
||||
const box = new Box3().setFromObject(model.current!);
|
||||
controls.current?.target.set(0, (2 * box.min.y + box.max.y) / 3, 0);
|
||||
camera.position.set(-5, (box.min.y + box.max.y) / 2, -15);
|
||||
}, []);
|
||||
|
||||
controls.current?.target.set(0, (2 * box.min.y + box.max.y) / 3, 0);
|
||||
camera.position.set(-5, (box.min.y + box.max.y) / 2, -15);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<OrbitControls
|
||||
ref={controls}
|
||||
enabled={orbit}
|
||||
target={new Vector3(0, 2, 0)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<OrbitControls
|
||||
ref={controls}
|
||||
enabled={orbit}
|
||||
target={new Vector3(0, 2, 0)}
|
||||
/>
|
||||
);
|
||||
},
|
||||
() => false,
|
||||
);
|
||||
Reference in new issue
Block a user