three.js-如何围绕lookAt(object)和相机位置之间的线旋转相机

时间:2020-10-19 19:31:34

标签: three.js

我目前正试图通过观察一个对象围绕目标对象和摄像机之间的直线旋转摄像机。

我以为我可以绕Z轴旋转,但是我错了。 我猜是因为所有轴都旋转了,所以lookAt(object)起作用了。

很抱歉,这里附近已经存在解决方案,但我找不到它。.

感谢您的帮助!

draw3d(renderer) {
        let targetPlayer = this.players[this.followPlayer];

        let mesh = targetPlayer.three.mesh;

        let d = 4;

        let relativeCameraOffset = new THREE.Vector3(0, d / 1.2, 2 * d);
        let cameraOffset = relativeCameraOffset.applyMatrix4(mesh.matrixWorld);
        this.three.camera.position.x = cameraOffset.x;
        this.three.camera.position.z = cameraOffset.z;
        this.three.camera.position.y = cameraOffset.y;
        this.three.camera.lookAt(mesh.position);

        // ROTATE CAMERA LOOKAT BY PLAYERS STEERING
        // camera.rotation.z = targetPlayer.steering;

        renderer.render(this.three.scene, this.three.camera);
    }

1 个答案:

答案 0 :(得分:1)

我认为您要寻找的是rotation.z而不是camera.rotateZ(degs)。如您所见in the docsrotateZ()进行当前旋转,并执行局部空间Z旋转。