单击按钮或链接时,我想更改相机的lookat位置。这是我的代码:

HTML:

 <a href="#" id="testButton">TEST</a>

JS:
render();
function render() {
    trackballControls.update(60);
    requestAnimationFrame(render);
    webGLRenderer.render(scene, camera);
}

// test button function
// this does not work
var testButton = document.getElementById('testButton');
testButton.onclick = function ()
{
     camera.lookAt(new THREE.Vector3(50,60,70));
};

// another test button function
// this does work but then the camera bounces back to what it was looking at before
var testButton2 = document.getElementById('testButton');
testButton2.onclick = function ()
{
     camera.lookAt(new THREE.Vector3(50,60,70));
     webGLRenderer.render(scene, camera);
};

我究竟做错了什么? Here is the test page(等待埃菲尔铁塔加载)。

最佳答案

对于OrbitControlsTrackballControls,摄像机“注视” controls.target,它是THREE.Vector3()

要更改目标,请使用以下模式:

controls.target.set( x, y, z );

three.js r.67

09-11 17:45