From 9d71e24e7982f6915e5f832512925bee9b245f35 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 20 八月 2024 16:13:26 +0800
Subject: [PATCH] #

---
 src/components/camera.jsx |   55 ++++++++++++++++---------------------------------------
 1 files changed, 16 insertions(+), 39 deletions(-)

diff --git a/src/components/camera.jsx b/src/components/camera.jsx
index 1fbbc1b..666889a 100644
--- a/src/components/camera.jsx
+++ b/src/components/camera.jsx
@@ -1,54 +1,31 @@
-// 娣诲姞鍦烘櫙鐩告満
-import { useThree, PerspectiveCameraProps } from '@react-three/fiber';
+import React, { useState, useEffect, useRef } from 'react';
+import { useThree, useFrame } from '@react-three/fiber';
 import {
     PerspectiveCamera,
-    CameraControls,
-    PresentationControls,
-    FlyControls,
-    OrbitControls,
-    FirstPersonControls,
-    MapControls,
 } from '@react-three/drei';
-import React, { useState, useEffect } from 'react';
+import { useStore } from '@/store';
 
 const Camera = (props) => {
-    const threeObj = useThree();
-    const camera = threeObj.camera;
+    const cameraRef = useRef();
+    const { camera } = useThree();
 
-    const [choiceCtrls, setChoiceCtrls] = useState(true);
-    const mobxStore = useContext(ThreeStoreContext);
+    const store = useStore();
 
-    const flyCtrl = () => {
-        return (
-            <group>
-                <FirstPersonControls
-                    far={100000}
-                    movementSpeed={100}
-                    activeLook={false}
-                    lookVertical={true}
-                ></FirstPersonControls>
-                {/* <OrbitControls /> */}
-                <MapControls zoomSpeed={0.1} />
-            </group>
-        );
-    };
+    useFrame((state, delta) => {
+        const { autoCruise, lookAt } = store;
 
-    const ctrl = () => {
-        return (
-            <group>
-                {/* 鐩告満鎺у埗鍣� */}
-                {/* <PresentationControls /> */}
-                <CameraControls />
-                {/* <PointerCtrl /> */}
-            </group>
-        );
-    };
+        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 (
         <>
-            {choiceCtrls ? ctrl() : flyCtrl()}
             <PerspectiveCamera
+                ref={cameraRef}
                 makeDefault
-                position={[-100, 200, 1000]}
+                position={[0, 600, 1150]}
                 fov={48}
                 near={1}
                 far={100000}

--
Gitblit v1.9.1