Three.js补间相机.lookat

bee*_*eek 6 javascript three.js tween.js

我正在尝试补间摄像机.使用Tween.js在Three.js中查看但收效甚微.

这有效

    selectedHotspot = object;

    var tween = new TWEEN.Tween(camera.lookAt( object.position),600).start();
Run Code Online (Sandbox Code Playgroud)

但是将相机直接旋转到object.position.

如何获得良好的平滑旋转?

这是渲染功能

  function update() {

    lat = Math.max(-85, Math.min(85, lat));
    phi = THREE.Math.degToRad(90 - lat);
    theta = THREE.Math.degToRad(lon);

    target.x = 512 * Math.sin(phi) * Math.cos(theta);
    target.y = 512 * Math.cos(phi);
    target.z = 512 * Math.sin(phi) * Math.sin(theta);


    if(!selectedHotspot)
        camera.lookAt(target);


    renderer.render(scene, camera);

}
Run Code Online (Sandbox Code Playgroud)

UPDATE

好吧,我无法在相机上做任何事情.我认为一定有别的错误.渲染函数中是否还有其他内容?

mrd*_*oob 10

我认为你的代码应该是这样的:

// backup original rotation
var startRotation = new THREE.Euler().copy( camera.rotation );

// final rotation (with lookAt)
camera.lookAt( object.position );
var endRotation = new THREE.Euler().copy( camera.rotation );

// revert to original rotation
camera.rotation.copy( startRotation );

// Tween
new TWEEN.Tween( camera ).to( { rotation: endRotation }, 600 ).start();
Run Code Online (Sandbox Code Playgroud)

  • 现在应该是`new TWEEN.Tween(camera.rotation).to({x: endRotation.x, y: endRotation.y, z: endRotation.z}, 500).start()`吗? (3认同)

zwc*_*oud 5

mrdoob 答案的四元数版本

// backup original rotation
var startRotation = camera.quaternion.clone();

// final rotation (with lookAt)
camera.lookAt( lookAt );
var endRotation = camera.quaternion.clone();

// revert to original rotation
camera.quaternion.copy( startRotation );

// Tween
var lookAtTween = new TWEEN.Tween( camera.quaternion ).to( endRotation, 600 ).start();
Run Code Online (Sandbox Code Playgroud)