三个JS Camera Orientation以180度而不是360度返回值

时间:2015-11-12 18:39:43

标签: javascript camera three.js compass

我试图在带有飞行控制的Three.JS场景中插入指南针。我把一个北点放在远离我的飞机的地方,并用它作为北方参考。我希望指南针根据从相机到空间点的角度旋转。我已经使用以下方法来确定角度,但是当它旋转而不是从181延伸到360时,它吐出的角度从1到180然后再回落到179.请知道为什么会这样?

var vector = new THREE.Vector3(0, 0, -1);
    vector.applyQuaternion(camera.quaternion);
    angle = vector.angleTo(north.position);

    var degree = angle * (180 / 3.14159);
    console.log(degree);

    compass2.rotation.y = (angle);

我将链接到该项目,以便您可以看到问题的实际效果。

www.googledrive.com/host/0B_XkORRtWN2OcGstUjE5R0RRRWc/PDSFlythrough.html

1 个答案:

答案 0 :(得分:0)

解决!我选择了一个不同的系统,在这个系统中,我将辅助摄像机放在一个圆柱体中,端盖关闭并设置为显示网格的背面。然后我简单地添加了代码以匹配从camera1到camera1的旋转角度。即时罗盘!

//Load Compass Model
    var compassGeometry = new THREE.CylinderGeometry(30, 30, 30, 20, 1, 1); 
    var compassMaterial = new THREE.MeshPhongMaterial({
        map: THREE.ImageUtils.loadTexture('assets/CompassTexture.svg')
    });
    compass2 = new THREE.Mesh(compassGeometry, compassMaterial);
    compass2.material.side = THREE.BackSide;
    compass2.rotation.x = 1.57;
    compass2.rotation.y = 0.10;
    scene2.add(compass2)

 //Animate
    function animate() {
        requestAnimFrame(animate);
        controls.update(1);

        //match camera2 rotation to camera1
        camera2.rotation.x = camera.rotation.x;
        camera2.rotation.y = camera.rotation.y;
        camera2.rotation.z = camera.rotation.z;

        render();
    }

Working Version