#
luxiaotao1123
2024-07-31 c06d11bbb8c87baaa8d7e70e82217873249a43e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React, { useState, useEffect, useRef } from 'react';
import { useThree, useFrame } from '@react-three/fiber';
import {
    PerspectiveCamera,
} from '@react-three/drei';
import { useStore } from '@/store';
 
const Camera = (props) => {
    const cameraRef = useRef();
    const { camera } = useThree();
 
    const store = useStore();
 
    useFrame((state, delta) => {
        const { autoCruise, lookAt } = store;
 
        if (autoCruise) {
            cameraRef.current.position.set(lookAt.x - 0, lookAt.y + 200, lookAt.z + 500);
            camera.lookAt(lookAt.x, lookAt.y + 100, lookAt.z);
        }
    })
 
    return (
        <>
            <PerspectiveCamera
                ref={cameraRef}
                makeDefault
                position={[0, 350, 1150]}
                fov={48}
                near={1}
                far={100000}
                maxDistance={10}
            />
        </>
    );
};
 
export default Camera;