如何旋转90度摄像机控制角度左右旋转三个.js?

时间:2018-04-02 06:11:27

标签: javascript canvas three.js

我创建了2个按钮leftright。如果我点击left button相机每次旋转90度。我打电话给leftMode函数。我的相机旋转不起作用。怎么做这个旋转角度90度?请告诉我,我的代码有什么错误?

camera3D = new THREE.PerspectiveCamera(angle, width / height, near, far);
camera3D.position.set(0, 10, 500);

/* Floor  */
        var geometry = new THREE.PlaneGeometry(10000, 10000, 10, 10);
        var material = new THREE.MeshBasicMaterial({
            color: 0x444444
        });
        var floor = new THREE.Mesh(geometry, material);
        floor.material.side = THREE.DoubleSide;
        floor.position.set(0, 0, 0);
        floor.rotation.x = Math.PI / 2;
        floor.castShadow = true;
        scene3D.add(floor);

        renderer3D.setClearColor(0x81aff9);
        renderer3D.setSize(width, height);

        controls = new THREE.OrbitControls(camera3D, renderer3D.domElement);
        canvas3D.appendChild(renderer3D.domElement);
        controls.rotateSpeed = 0.75;
        controls.zoomSpeed = 1.2;

this.leftMode = function(){

            console.log(camera3D.rotation);
            console.log(camera3D.position);

            //camera3D.position.x = 500 * Math.cos( 0 );
            //camera3D.position.y = camera3D.position.y;
            //camera3D.position.z = camera3D.position.z;

            //camera3D.rotation.order = (2 * Math.PI) + camera3D.rotation.x;

            //camera3D.position.x = (2 * Math.PI) + camera3D.rotation.x;

            camera3D.rotation.x = camera3D.rotation.x + 90*Math.PI/180;
        }

0 个答案:

没有答案