THREE.js LookAt - 如何在新旧目标位置之间平滑平移?

ste*_*eOw 3 javascript three.js

JSfiddle 示例

我可以使用 THREE.js“lookAt”函数让我的锥体依次指向每个目标球体(红色、绿色、黄色、蓝色)。

// Initialisation

c_geometry = new THREE.CylinderGeometry(3, 40, 120, 40, 10, false);
c_geometry.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI / 2 ) );
c_material = new THREE.MeshNormalMaterial()
myCone = new THREE.Mesh(c_geometry, c_material);
scene.add(myCone);

// Application (within the Animation loop)

myCone.lookAt(target.position); 
Run Code Online (Sandbox Code Playgroud)

但现在我希望锥体能够平稳、缓慢地从旧目标平移到新目标。我想我可以通过计算以圆锥中心 Cxyz 为中心并从先前目标位置 Pxyz 到新目标位置 Nxyz 的圆弧上的中间点来实现。

请有人给我指出合适的:(a) 实用程序或 (b) 三角算法或 (c) 用于计算此类弧上中间点的 xyz 坐标的代码示例?(我将根据所需的扫描速率和帧之间的时间间隔提供点之间的角度增量)。

Wes*_*ley 5

您希望顺利地从一种方向过渡到另一种方向。

在您的情况下,您将预先计算目标四元数:

myCone.lookAt( s1.position ); 
q1 = new THREE.Quaternion().copy( myCone.quaternion );

myCone.lookAt( s2.position );
q2 = new THREE.Quaternion().copy( myCone.quaternion );
Run Code Online (Sandbox Code Playgroud)

然后,在渲染循环中:

myCone.quaternion.slerpQuaternions( q1, q2, time ); // 0 < time < 1
Run Code Online (Sandbox Code Playgroud)

三.js r.141