Three.js ThreeJS-阻止slerp相机旋转四处漂移

Three.js ThreeJS-阻止slerp相机旋转四处漂移,three.js,rotation,quaternions,Three.js,Rotation,Quaternions,我目前正在处理一个场景,其中一个对象位于中心(0,0,0),另外6个对象围绕它旋转。我在一个外部物体的后面和稍上方安装了一个摄像头,向后看中心(摄像头,注视(0,0,0)等) 我想单击一个对象,只是为了让相机朝向并面对单击的对象。我使用Quaternion.slerp来实现这一点,它可以工作,但是当相机移动时,它会缓慢地漂移,然后慢慢聚焦到物体的中心 因此,如果我点击相机视场左侧的一个对象,它在向左摆动之前会向右漂移一点,反之亦然 我发现了一些关于slerp运动的帮助,我希望简单地适应它: 设

我目前正在处理一个场景,其中一个对象位于中心(0,0,0),另外6个对象围绕它旋转。我在一个外部物体的后面和稍上方安装了一个摄像头,向后看中心(摄像头,注视(0,0,0)等)

我想单击一个对象,只是为了让相机朝向并面对单击的对象。我使用Quaternion.slerp来实现这一点,它可以工作,但是当相机移动时,它会缓慢地漂移,然后慢慢聚焦到物体的中心

因此,如果我点击相机视场左侧的一个对象,它在向左摆动之前会向右漂移一点,反之亦然

我发现了一些关于slerp运动的帮助,我希望简单地适应它:

设置

    this._endQ = new Quaternion();
    this._iniQ = new Quaternion().copy(this._camera.quaternion);
    this._curQ = new Quaternion();

    this._vec3 = new Vector3();

    const euler = new Euler(this._cameraLookAtDestination.x, this._cameraLookAtDestination.y, this._cameraLookAtDestination.z);

    this._endQ.setFromEuler(euler);
    Quaternion.slerp(this._iniQ, this._endQ, this._curQ, pointInTime);

    this._vec3.x = this._cameraLookAtDestination.x;
    this._vec3.y = this._cameraLookAtDestination.y;
    this._vec3.z = this._cameraLookAtDestination.z;
    this._vec3.applyQuaternion(this._curQ);

    this._camera.lookAt(this._vec3);
在renderloop中

    this._endQ = new Quaternion();
    this._iniQ = new Quaternion().copy(this._camera.quaternion);
    this._curQ = new Quaternion();

    this._vec3 = new Vector3();

    const euler = new Euler(this._cameraLookAtDestination.x, this._cameraLookAtDestination.y, this._cameraLookAtDestination.z);

    this._endQ.setFromEuler(euler);
    Quaternion.slerp(this._iniQ, this._endQ, this._curQ, pointInTime);

    this._vec3.x = this._cameraLookAtDestination.x;
    this._vec3.y = this._cameraLookAtDestination.y;
    this._vec3.z = this._cameraLookAtDestination.z;
    this._vec3.applyQuaternion(this._curQ);

    this._camera.lookAt(this._vec3);
这是正常的slerp行为,还是我遗漏了什么

编辑:


我还注意到,每次单击要查看的对象时,相机似乎都会重置其方向,然后旋转。不幸的是,我认为提供的代码没有包含足够的上下文,任何人都无法提供帮助。作为一个暗箭伤人的例子——你似乎在用一个3D向量初始化Euler类(除非我完全误解了)。然而,Euler构造函数。这可能是个问题吗?抱歉@martin_pr这是我使用slerp的问题。首先,我将错误的参数传递给了slerp(总是好的),其次(这听起来可能完全错误),slerp函数是“球面插值”,它创建了一条圆形路径,从奇点看,它是有意义的,但是,由于我的参数是错误的,我在摄像机前跟踪这条圆形的路径,所以它似乎在四处漂移。当我的参数被解析时,我实际上只是把
这个.\u curQ
传给了我的相机,它工作正常,对不起,麻烦了