0

我们正在开发一个带有 HMD 的虚拟现实环境,并以四元数的形式提供连续的跟踪器数据。我们从中计算出一个旋转矩阵,然后让 OpenGL 完成剩下的工作。

现在我们想在开始时设置一个特定的方向,这意味着重置来自跟踪器的数据并始终计算偏移量。

编辑:经过更多测试后,我们认为以下是正确的,因为我们通过更改计算中的轴和源来从左手坐标系切换到右手坐标系。

public void trackerPositionUpdate(TrackerUpdate u, TrackerRemote tracker) {

    if (!isreset){

        //Set reference reset-viewpoint here
        Matrix4f.setIdentity(reset);
        reset.m00=1;
        reset.m11=-1;
        reset.m22=1;

        //get quaternion
        float qx = (float)u.quat[0];
        float qy = (float)u.quat[1];
        float qz = (float)u.quat[2];
        float qw = (float)u.quat[3];

        //quaternion to rotation matrix for reset reasons - axis 2 and 3 switched
        orientation.m00 = 1.0f - (2.0f*(qy*qy) + 2.0f*(qz*qz));
        orientation.m02 = 2.0f*qx*qy - 2.0f*qz*qw;
        orientation.m01 = 2.0f*qx*qz + 2.0f*qy*qw;
        orientation.m03 = 0.0f;

        orientation.m10 = 2.0f*qx*qy + 2.0f*qz*qw;
        orientation.m12 = 1.0f - (2.0f*qx*qx + 2.0f*qz*qz);
        orientation.m11 = 2.0f*qy*qz - 2.0f*qx*qw;
        orientation.m13 = 0.0f;

        orientation.m20 = 2.0f*qx*qz - 2.0f*qy*qw;
        orientation.m22 = 2.0f*qy*qz + 2.0f*qx*qw;
        orientation.m21 = 1.0f - (2.0f*qx*qx + 2.0f*qy*qy);
        orientation.m23 = 0.0f;

        orientation.m30 = 0.0f;
        orientation.m32 = 0.0f;
        orientation.m31 = 0.0f;
        orientation.m33 = 1.0f;


        //this inverts the elevation and needs to be set for the tracker to work correctly with the audio coordinate system
        orientation.m01 *= -1 ;
        orientation.m11 *= -1 ;
        orientation.m21 *= -1 ;
        orientation.m31 *= -1 ;

        //invert matrix
        orientation.invert();

        //Mreset = Mdest * Morientation^(-1)
        Matrix4f.mul(reset, orientation, reset);
        isreset=true;
        System.out.println("Ivas_VRPNTracker# bool isreset: " + isreset);
    }


    // Get quaternion from trackerinput
    float qx = (float)u.quat[0];
    float qy = (float)u.quat[1];
    float qz = (float)u.quat[2];
    float qw = (float)u.quat[3];


    //original :x = 0,y = 1 , z = 2;
    Tracker_X         = u.pos[0];
    Tracker_Y         = u.pos[2];
    Tracker_Z         = -u.pos[1];

    //1st row
    orientation.m00 = 1.0f - (2.0f*(qy*qy) + 2.0f*(qz*qz));
    orientation.m02 = 2.0f*qx*qy - 2.0f*qz*qw;
    orientation.m01 = 2.0f*qx*qz + 2.0f*qy*qw;
    orientation.m03 = 0.0f;

    //2nd row
    orientation.m10 = 2.0f*qx*qy + 2.0f*qz*qw;
    orientation.m12 = 1.0f - (2.0f*qx*qx + 2.0f*qz*qz);
    orientation.m11 = 2.0f*qy*qz - 2.0f*qx*qw;
    orientation.m13 = 0.0f;

    //3rd row
    orientation.m20 = 2.0f*qx*qz - 2.0f*qy*qw;
    orientation.m22 = 2.0f*qy*qz + 2.0f*qx*qw;
    orientation.m21 = 1.0f - (2.0f*qx*qx + 2.0f*qy*qy);
    orientation.m23 = 0.0f;

    //4th row
    orientation.m30 = 0.0f;
    orientation.m32 = 0.0f;
    orientation.m31 = 0.0f;
    orientation.m33 = 1.0f;


    //this inverts the elevation and needs to be set for the tracker to work correctly with the audio coordinate system
    orientation.m01 *= -1 ;
    orientation.m11 *= -1 ;
    orientation.m21 *= -1 ;
    orientation.m31 *= -1 ;


    //define reset by multiplication with rotational reset matrix
    //Mview = Morientationcurrent * Mreset
    Matrix4f.mul(orientation,reset, orientation);

然后我们将方向矩阵与模型视图矩阵相乘。这很好用,但是我们很难找到在按下回车键时重置位置的例程。

4

0 回答 0