我们正在开发一个带有HMD的虚拟现实环境,并且连续的跟踪器数据将作为四元数。我们从中计算出一个roatation Matrix,让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);
然后我们将方向矩阵与模型视图矩阵相乘。 这样可以正常使用,但在按Enter键时我们无法找到重置位置的例程。