如何旋转Z轴的方向?

时间:2015-01-03 16:28:46

标签: three.js camera rotation

我最近开始使用Three.js来处理我的游戏项目,但我无法让相机四处走动。

问题是:我可以在X轴上旋转摄像机,但是当它朝向Z轴时,它总是朝着相同的方向,因为旋转视图时Z轴不会改变。到目前为止,这是我的代码:

var circle = Math.PI / 180;

    var scene = new THREE.Scene();
    var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );

    var renderer = new THREE.WebGLRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );

    var geometry = new THREE.BoxGeometry( 10, 15, 3 );
    var material = new THREE.MeshBasicMaterial( { color: 0x05ff68 } );
    var cube = new THREE.Mesh( geometry, material );
    scene.add( cube );

    var geometry2 = new THREE.BoxGeometry(10,10,10);
    var sphere = new THREE.Mesh( geometry2, material );
    scene.add(sphere);

    sphere.position.set(-20,0,0);

    camera.position.z = 30;
    camera.position.x = 0;
    camera.position.y = 10;

    camera.rotation.y = 0 * circle;
    camera.rotation.x = 0 * circle;

    cube.position.set(20,0,0)

    function render() {
        requestAnimationFrame( render );
        renderer.render( scene, camera );
    }

    render();

    function checkKey(e) {

        e = e || window.event;

        if (e.keyCode == '87') {
            camera.position.y -= 2;
        }
        else if (e.keyCode == '83') {
            camera.position.y += 2;
        }
        else if (e.keyCode == '65') {
            camera.rotation.y += 2 * circle;
        }
         else if (e.keyCode == '68') {
            camera.rotation.y -= 2 * circle;
        };

    } 

我需要知道如何改变Z的方向。

https://lh6.googleusercontent.com/-7oNrCaq35yU/VKhJ71EowUI/AAAAAAAAAA0/XwrWI0tn3Zo/w769-h577-no/camera1.png

https://lh3.googleusercontent.com/-5L_cAUIkMgQ/VKhKMNe6seI/AAAAAAAAABI/xk_kLqpM6_A/w769-h577-no/camera2.png

https:lh3.googleusercontent.com/-ZNnvGOUkd-g/VKhKSs4-eaI/AAAAAAAAABY/P2VnnsI7Jbg/w769-h577-no/camera3.png

https:lh6.googleusercontent.com/-lNnhq2CqFxE/VKhKTT32HWI/AAAAAAAAABg/IJoCxjYq57U/w769-h577-no/camera4.png

https://lh4.googleusercontent.com/-OWus1HMs8gg/VKhKUAnZGBI/AAAAAAAAABo/VArAhWSpEsQ/w769-h577-no/camera5.png

0 个答案:

没有答案