正交相机在场景中的方向

时间:2019-06-11 08:14:13

标签: angular typescript

场景的中心是右上角的对象是方向立方体1。相机在场景中自由旋转。同时,我需要旋转立方体并向用户展示相机从哪一侧看场景。

问题的实质:我从以下角度计算摄像机的角度:

var pLocal = new THREE.Vector3(0, 0, -1);
var pWorld = pLocal.applyMatrix4(this.camera.matrixWorld);
var dir = pWorld.sub(this.camera.position).normalize();
console.log(this.graduse(dir.x), this.graduse(dir.y), this.graduse(dir.z));

I made a small table depending on the angle[2].

In practice, it turns out that while the camera moves around the cube, the angles of Y and Z change. It is impossible to make the angle of rotation of the orientation cube along the Y axis calculated accurately and smoothly. This is especially noticeable when moving from the front side to the back side.

我试图用系数设置比例变化定律:

[private tableCubeViewRotateCalc: number\[\]\[\] = \[\[-1.58, 90.6\], \[1.58, 0.6\], \[1.58, 0.6\]\];

    var vector = new THREE.Vector3(0, 0, 0);
    this.camera.getWorldDirection(vector);

    result_angle.y = this.tableCubeViewRotateCalc\[2\]\[0\] * (this.graduse(vector.x)) + this.tableCubeViewRotateCalc\[2\]\[1\];
    if (this.graduse(vector.z) < 0) {//for view back
      if (result_angle.y > 0) {
        result_angle.y += this.tableCubeViewRotateCalc\[0\]\[0\] * (this.graduse(vector.z)) + this.tableCubeViewRotateCalc\[0\]\[1\];
      } else {
        result_angle.y -= this.tableCubeViewRotateCalc\[0\]\[0\] * (this.graduse(vector.z)) + this.tableCubeViewRotateCalc\[0\]\[1\];
      }
    }]

however, this method does not provide the desired accuracy.

我阅读了很多有关游戏中矢量几何的文章,但是,我没有找到解决该问题的方法。

需要在Y和Z之间建立某种三角关系才能准确地计算相机角度

0 个答案:

没有答案