【问题标题】:Camera controls are opposite to what they should be. Why?相机控制与应有的相反。为什么?
【发布时间】:2017-05-21 13:33:12
【问题描述】:

我正在 Three.js 中创建一个可玩的迷宫。所有的物体——地板、天花板和墙壁——都放置在正 X 轴和 Z 轴内。摄像头是这样放置的:

camera = new THREE.PerspectiveCamera(45,
                                         window.innerWidth / window.innerHeight,
                                         0.1,
                                         1000
    );
    camera.position.set(0, 0.25, 0);

    // The camera is placed pointing to the nearest open path from the
    // initial position. Check mazeGenerator.js for the reference of
    // "coordinates".
    if(grid[1][0] == coordinates.W)
    {
        camera.lookAt(new THREE.Vector3(1, 0.25, 0));
    }
    else
    {
        camera.lookAt(new THREE.Vector3(0, 0.25, 1));
    }

它会这样移动:

function keyboardCheck()
{
    var movementSpeed = 0.02;
    var rotationSpeed = 0.03;

    if(keyboard.pressed('w') || keyboard.pressed('up'))
    {
        camera.translateZ(-movementSpeed);
    }

    if(keyboard.pressed('a') || keyboard.pressed('left'))
    {
        camera.rotateY(rotationSpeed);
    }

    if(keyboard.pressed('d') || keyboard.pressed('right'))
    {
        camera.rotateY(-rotationSpeed);
    }
}

如果我在没有lookAt 功能的情况下放置相机,它似乎面向[0, 0, 0],但当然我想做的是通过使相机面对可能的最近的开放路径来帮助玩家一点。

为了让它向前移动,我必须减小 Z,否则当你按下“向前移动”键时它会向后移动。这让我觉得即使我告诉相机看某个方向,对象的 Z 轴与世界的 Z 轴相反。

问题本身就是:为什么会这样?

非常感谢您。

【问题讨论】:

    标签: graphics three.js camera axis


    【解决方案1】:

    相机正在向下看它的负 z 轴,因此要向前移动,请执行以下操作:

    camera.translateZ( - distance );
    

    所有其他对象都被认为是在看它们的正 z 轴方向,因此要向前移动其他对象,您可以使用

    object.translateZ( distance );
    

    three.js r.85

    【讨论】:

      猜你喜欢
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多