1

当有人单击按钮以在对象周围移动相机时,我正在尝试。但我不想移动对象(它需要居中)。

我有:

和js函数

function MoveUp()
{
    camera.position.y -=50;
}
function MoveDown()
{
    camera.position.y +=50;
}

但是当我单击按钮时,这是向下/向上移动对象。是否有任何可能只是移动相机周围以及如何?我的对象只是立方体..示例:

var geometry = new THREE.CubeGeometry( 50, 50, 50 );
        var material = new THREE.MeshFaceMaterial( [
        new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'drvo.jpg' ) } ),
        new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'drvo.jpg' ) } ),
        new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'drvo.jpg' ) } ),
        new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'beton.jpg' ) } ),
        new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'beton.jpg' ) } ),
        new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'beton.jpg' ) } )
    ] );

    cube = new THREE.Mesh( geometry, material );
    cube.position.z = 450;
    scene.add(cube);
4

2 回答 2

1

Take a look at the RollControls.js at three.js/examples/js/controls/RollControls.js and also at the examples two directories up. Since the controls are there, why try to do it yourself.

于 2013-02-07T13:30:32.223 回答
1

您正在更改相机位置,同时保持其方向。我猜您想重新定位相机,使其指向您的立方体(实际上,将其居中)。移动相机后,尝试camera.lookAt(cube.position);这需要是您的 MoveUp 和 MoveDown 中的最后一件事

于 2013-02-07T12:56:52.253 回答