在 Three.js 中,我想使用 THREE.quaternion 使相机对象旋转到所选对象。
我确实在网上搜索过,但没有找到关于如何使用这个四元数类的示例/演示或文档。
我用以下代码试试运气:
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.y = 10;
camera.position.z = 0;
camera.position.x = radious;
camera.useQuaternion = true;
// I did use the TrackballTrackballControls. Maybe it causes the problem so I put it here
controls = new THREE.TrackballControls( camera, document.getElementById(_canvasElement) );
// function to make the camera rotate to the object
function focusOn3DObject(obj){
obj.useQuaternion = true;
obj.quaternion = new THREE.Quaternion(obj.position.x, obj.position.y, obj.position.z, 1);
var newQuaternion = new THREE.Quaternion();
THREE.Quaternion.slerp(camera.quaternion, obj.quaternion, newQuaternion, 0.07);
camera.quaternion = newQuaternion;
}
但它不起作用。我错过了什么?请帮忙。提前致谢。