我可以使用 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);
但现在我希望圆锥体从旧目标平滑缓慢地平移到新目标。我想我可以通过计算以圆锥中心 Cxyz 为中心并从先前目标位置 Pxyz 到新目标位置 Nxyz 的圆弧上的中间点来实现。
请有人指点我合适的:(a) 实用程序或 (b) 三 Angular 算法或 (c) 计算此类弧上中间点的 xyz 坐标的代码示例? (我将根据所需的扫描速率和帧之间的时间间隔提供点之间的 Angular 增量)。
最佳答案
您想从一个方向平稳过渡到另一个方向。
在您的情况下,您将预先计算目标四元数:
myCone.lookAt( s1.position );
q1 = new THREE.Quaternion().copy( myCone.quaternion );
myCone.lookAt( s2.position );
q2 = new THREE.Quaternion().copy( myCone.quaternion );
然后,在你的渲染循环中:
myCone.quaternion.slerpQuaternions( q1, q2, time ); // 0 < time < 1
three.js r.141
关于javascript - THREE.js lookAt - 如何在新旧目标位置之间平滑平移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30292831/