【问题标题】:LibGDX - perspective camera smooth translation & directionLibGDX - 透视相机平滑平移和方向
【发布时间】:2015-04-29 10:51:28
【问题描述】:

我正在尝试在我的游戏中实现流畅的 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();
    }
*/

确定方向的正确方法是什么?

【问题讨论】:

标签: java 3d libgdx opengl-es-2.0 perspectivecamera


【解决方案1】:

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

您必须编写一个 Vector3Accessor 类(这将非常简单),但随后您将拥有用于平滑移动的各种控件和选项。它有一个非常丰富的 API,并且经常用于这类事情。

我强烈建议您花一点时间来研究它作为一个选项 - 它会给您带来更好的结果,一旦您了解它,您就会在您的应用中发现它的各种其他很酷的用途。

【讨论】:

    猜你喜欢
    • 2014-07-25
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 2012-09-17
    • 2014-05-27
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    相关资源
    最近更新 更多