【问题标题】:LibGDX 3D Camera spasm when player looks directly up or down当玩家直接向上或向下看时,LibGDX 3D 相机痉挛
【发布时间】:2016-04-14 23:27:34
【问题描述】:

我的情况

我正在制作一个 3D LibGDX 游戏。我正在使用基于here 的自定义相机控制器。在确定将玩家移动到哪里时,它不需要使用 delta Y,这样无论他们向上还是向下看,他们都可以保持在同一水平面上。

我的问题

我的问题是,每当玩家向上或向下看太远时,相机都会开始闪烁。我相信它试图向上或向下看。我的问题是我不想要那样。在以前的项目中,我曾尝试设置如下限制:

if(camera.direction.y + deltaY >= 0.9){
    return;
}

(代码可能不完全正确),但是当这种情况发生时,玩家通常看不到足够的东西。

我的代码

我的代码有一个链接here

【问题讨论】:

  • 如果您执行以下操作会发生什么: Vector3 right = camera.position.sub(camera.direction).crs(up).nor(); camera.rotateAround(camera.position, right, deltaY); camera.rotate(Vector3.Y, deltaX);您首先获得正确的矢量并围绕其自己的正确矢量(上下)旋转相机,然后围绕其 Y 轴旋转。从来没有遇到过麻烦。
  • 听起来您正在体验Gimbal Lock。您应该研究四元数来操纵相机或限制它完全上下看。

标签: java 3d libgdx perspectivecamera


【解决方案1】:

在 Github 的一位优秀人员的帮助下,我修复了我的代码。这是我的新FirstPersonCameraController#touchDragged

float deltaX = -Gdx.input.getDeltaX() * degreesPerPixel;
float deltaY = -Gdx.input.getDeltaY() * degreesPerPixel;
camera.direction.rotate(camera.up, deltaX);
Vector3 oldPitchAxis = tmp.set(camera.direction).crs(camera.up).nor();
Vector3 newDirection = tmp2.set(camera.direction).rotate(tmp, deltaY);
Vector3 newPitchAxis = tmp3.set(tmp2).crs(camera.up);
if (!newPitchAxis.hasOppositeDirection(oldPitchAxis))
    camera.direction.set(newDirection);

(我删除了一些特定于我的游戏的部分)

【讨论】:

    猜你喜欢
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多