ThreeJS camera.lookAt() has no effect, is there something I'm doing wrong?

前端 未结 6 410
半阙折子戏
半阙折子戏 2021-02-05 02:13

In Three.js, I want a camera to be pointed at a point in 3D space.

For this purpose, I tried using the camera.lookAt function like so:

camer         


        
6条回答
  •  抹茶落季
    2021-02-05 02:37

    In my opinion, we are not supposed to mess with the original code. I found a way around to achieve the objective of looking at any particular point. After having declared your "control" variable, simply execute these two lines of code:

    // Assuming you know how to set the camera and myCanvas variables
    control = new THREE.OrbitControls(camera, myCanvas);
    
    // Later in your code
    control.object.position.set(camX, camY, camZ);
    control.target = new THREE.Vector3(targetX, targetY, targetZ);
    

    Keep in my mind that this will switch the center of the focus to your new target. In other words, your new target will be the center of all rotations of the camera. Some parts will be difficult to look at as you became familiar to manipulate the camera assuming the default center. Try zoom in as much as you can and you will have a sense of what I am saying Hope this help.

提交回复
热议问题