【发布时间】:2013-11-13 00:27:14
【问题描述】:
我目前正在尝试实现一个与设置向量相关的 FPS 相机功能。 在这种情况下,它将是从行星中心到玩家位置的法线。 这将使您能够在地球上行走。相机不会因行星的曲率而失真。
目前,我使用它来设置相机方向。
Main.getMap().getLocalizedUpVector(shootPos, up);
Main.getMap().getLocalizedAngle(shootPos, angle);
matrice.rotate(angle.y, RenderElement.AXIS_YAW);
matrice.rotate(angle.x, RenderElement.AXIS_PITCH);
matrice.rotate(yaw,up);
right.set(matrice.m00, matrice.m10, matrice.m20);
if(right.length()>0){
right.normalise();
}
matrice.rotate(pitch, right);
eye.set(matrice.m02, matrice.m12, matrice.m22);
它调用这些函数。
public void getLocalizedUpVector(Vector3f pos, Vector3f res){
res.set(pos.x - center.x, pos.y - center.y, pos.z - center.z);
if(res.length() > 0){
res.normalise();
}
}
public void getLocalizedAngle(Vector3f pos, Vector3f angle){
float deltaX = pos.x - center.x;
float deltaY = pos.y - center.y;
float deltaZ = pos.z - center.z;
float distance = (float)Math.sqrt(deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ);
float yaw = -(float)Math.atan2(deltaX, deltaZ);
float pitch = (float)Math.asin(deltaY/distance);
angle.set(pitch, yaw, 0);
}
这个实现在地球的一半地区运行良好,但在另一边却搞砸了。 我怀疑这是因为我的 getLocalizedAngle 函数返回欧拉范围内的值。 但我不确定,有什么解决办法吗?
【问题讨论】:
-
这听起来像是(可能是杜撰的)关于配备 GPS 的战斗机在穿越赤道时的自动驾驶仪使它们倒转的故事。
标签: java opengl camera rotation position