In Three.js, I would like to use THREE.quaternion so that the camera object rotates to the selected object.
I searched on the Internet but did not find an example / demo or document on how to use this quaternion class.
I try using the following code:
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; }
But that will not work. Did I miss something? Please help. Thanks in advance.
user1533481
source share