【问题标题】:LibGDX Camera rotation IssueLibGDX 相机旋转问题
【发布时间】:2018-08-20 14:39:28
【问题描述】:

我正在尝试围绕我的模型旋转透视相机。模型位于中心 (0,0,0) 点。这是我的旋转相机方法:

private void rotateCameraAroundModel() {
    camera.position.set(0,0,0);
    camera.position.rotate(Vector3.Y, 5);
    camera.position.add(0f, 0f, 200f);
    camera.up.set(Vector3.Y);
    camera.lookAt(0,0,0);
    camera.update();
}

我正试图回到中心,旋转 5 度,然后返回相同的距离。但是,轮换似乎不起作用,我不知道为什么,非常感谢任何帮助。

【问题讨论】:

  • 我不是 LibGDX 方面的专家; camera.position.rotate(Vector3.Y, 5); 应该是 camera.rotate(Vector3.Y, 5); 吗?此外,最后的 camera.lookAt(0,0,0); 会替换您的相机在该点之前可能看到的任何方向。
  • @SteveSmith 这确实使相机旋转,但现在模型“看起来”它正在围绕相机旋转。

标签: java android libgdx


【解决方案1】:

我想通了:)

private void rotateCameraAroundModel(float angle) {
    camera.position.set(centreX, centerY, centerZ);
    camera.rotate(Vector3.Y, (float) Math.toDegrees(angle)); // Rotate around Y axis by angle in degrees
    float x = (float) (centerX + radius * (Math.sin(totalPhi)));
    float z =  (float) (centerZ + radius * (Math.cos(totalPhi)));
    camera.position.add(x, 0f, z); //Move back out 2m using pythagorean theorem to calculate the position on the circle
    camera.up.set(Vector3.Y);
    camera.lookAt(0, 0, 0);
    camera.update();
}

所以我需要在旋转时计算圆上的新位置,我使用了一些基本的三角函数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多