LibGDX - 透视相机平滑平移和方向

LibGDX - perspective camera smooth translation & direction

我正在尝试在我的游戏中实现流畅的 3D 相机。所以,我有一些保留的位置和方向,我想通过将它们应用到我的相机来改变我的相机的视图。现在我正在这样做:

//Reserved positions and directions

//View #1
Vector3 pos1 = new Vector3(0, 5, -10);
Vector3 dir1 = new Vector3(0, 0, 10);

//View #2
Vector3 pos2 = new Vector3(5, 2, 5);
Vector3 dir2 = new Vector3(-2, 2, 7);

//Applying view #2
camera.position.set(pos2);
camera.lookAt(dir2);

有效,但我需要顺利完成。我看过一个similar question for 2D camera,但它不适合我,因为正交相机不需要方向和Z轴。

更新:

我尝试使用针对 2D 相机描述的方法。所以,定位是按需工作的,但我不能对方向说同样的话。方向的行为是错误的。它在 Z 轴上旋转相机。在我看来,我也必须更新 Up 矢量。

float lerp = 0.01f;
Vector3 position = camera.position;
position.x += (pos2.x - position.x) * lerp;
position.y += (pos2.y - position.y) * lerp;
position.z += (pos2.z - position.z) * lerp;

Vector3 direction = camera.direction;
direction.x += (dir2.x - direction.x) * lerp;
direction.y += (dir2.y - direction.y) * lerp;
direction.z += (dir2.z - direction.z) * lerp;

//CODE FROM LIBGDX'S CAMERA
//LookAt function
/*
tmpVec.set(x, y, z).sub(position).nor();
    if (!tmpVec.isZero()) {
        float dot = tmpVec.dot(up); // up and direction must ALWAYS be orthonormal vectors
        if (Math.abs(dot - 1) < 0.000000001f) {
            // Collinear
            up.set(direction).scl(-1);
        } else if (Math.abs(dot + 1) < 0.000000001f) {
            // Collinear opposite
            up.set(direction);
        }
        direction.set(tmpVec);
        normalizeUp();
    }
*/

设置方向的正确方法是什么?

我会使用 Univesal Tween Engine,这是一个几乎可以插值任何东西的库。

您必须编写一个 Vector3Accessor class(这将非常简单),但是您将拥有各种控件和选项以实现流畅的移动。它具有非常丰富的 API 并且被大量用于这类事情。

我强烈建议您花一点时间研究它作为一种选择 - 它会给您带来更好的结果,一旦您知道它,您就会发现它在您的应用