【问题标题】:How to pan the camera by code in react-three/fiber and react-three/drei如何通过 react-three/fiber 和 react-three/drei 中的代码平移相机
【发布时间】:2022-01-19 17:29:34
【问题描述】:

我可以使用带有OrbitControls 的鼠标将相机从默认位置[0,0,0] 平移到[100,100,0]。但是仍然无法通过代码进行平移。

<Canvas
        camera={{
          position: [0, 0, 100],
          up: [0, 0, 1],
        }}
      >
        <OrbitControls />
        <ambientLight />
        <FakeSphere position={[0, 0, 0]} color="red" />
        <FakeSphere position={[100, 100, 0]} color="blue" />
      </Canvas>

请有什么想法。

【问题讨论】:

    标签: three.js react-three-fiber react-three-drei


    【解决方案1】:

    我们需要将相机移动到 [100,100,100] 并注视到 [100,100,0]

    useEffect(() => {
        if (!controls || !camera) return;
    
        camera.position.set(100, 100, 100);
        controls.target.set(100, 100, 0);
      }, [camera, controls]);
    

    【讨论】:

      猜你喜欢
      • 2021-12-23
      • 1970-01-01
      • 2021-07-02
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 2023-02-01
      • 2020-10-31
      相关资源
      最近更新 更多