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

时间:2013-12-31 23:55:30

标签: javascript three.js

点击按钮或链接时,我想更改相机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(等待埃菲尔铁塔加载)。

1 个答案:

答案 0 :(得分:5)

对于OrbitControlsTrackballControls,相机“查看”controls.target,即THREE.Vector3()

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

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

three.js r.67