Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 相对于行星表面/重力方向实施相机_Java_Opengl_Camera_Rotation_Position - Fatal编程技术网

Java 相对于行星表面/重力方向实施相机

Java 相对于行星表面/重力方向实施相机,java,opengl,camera,rotation,position,Java,Opengl,Camera,Rotation,Position,我目前正在尝试实现一个FPS相机功能,该功能将与设置向量相关。 在这种情况下,从行星中心到玩家位置是正常的。 这将使你能够环绕地球行走。不会让相机被行星的曲率扭曲 目前,我使用它来设置相机方向 Main.getMap().getLocalizedUpVector(shootPos, up); Main.getMap().getLocalizedAngle(shootPos, angle); matrice.rotate(angle.y, Rend

我目前正在尝试实现一个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函数返回的值在欧拉范围内。
但我不确定,有什么解决办法吗?

好的,在做其他事情的时候就想出来了

        matrice.setIdentity();

        Main.getMap().getLocalizedUpVector(shootPos, up);
        matrice.m02 = up.x; matrice.m12 = up.y; matrice.m22 = up.z;

        matrice.rotate(pitch, RenderElement.AXIS_PITCH);
        matrice.rotate(yaw, up);

        eye.set(matrice.m02, matrice.m12, matrice.m22);


        if(eye.length() > 0){
            eye.normalise();
        }
首先将矩阵设置为上方向向量,然后通过全局俯仰轴旋转该向量以获得俯仰。 绕上方向向量旋转以获得偏航

然后从矩阵中检索相对眼睛。

听起来像是(可能是虚构的)关于配备GPS的战斗机的故事,这些战斗机的自动驾驶仪在穿越赤道时将它们翻转过来。