Three.js通过点击按钮更改相机lookat

jli*_*gda 3 javascript three.js

我想lookat在点击按钮或链接时更改相机位置.这是我的代码:

HTML:

 <a href="#" id="testButton">TEST</a>
Run Code Online (Sandbox Code Playgroud)

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);
}; 
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?这是测试页面(等待埃菲尔铁塔加载).

Wes*_*ley 6

对于OrbitControlsTrackballControls,相机"看着" controls.target,这是一个THREE.Vector3().

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

controls.target.set( x, y, z );
Run Code Online (Sandbox Code Playgroud)

three.js r.67