【发布时间】: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();
}
*/
确定方向的正确方法是什么?
【问题讨论】:
-
@AngelAngel,这些链接仅对正交相机有用。
-
@Nolesh 为什么这只适用于正交相机?至少
Interpolation应该可以用于Vector3,所以它可以在你的情况下使用。 -
@Springrbua,我更新了问题
标签: java 3d libgdx opengl-es-2.0 perspectivecamera