Opengl 计算旋转矩阵偏移量
我们正在一个虚拟现实环境中使用HMD,并且有连续的跟踪器数据作为四元数。我们从中计算出一个漫游矩阵,剩下的就让OpenGL来做 现在我们要在开始时设置一个特定的方向,这意味着重置来自跟踪器的数据并始终计算偏移量 编辑: 经过更多的测试后,我们认为以下是正确的,因为我们通过改变计算和资源中的轴从左手坐标系切换到右手坐标系Opengl 计算旋转矩阵偏移量,opengl,matrix,lwjgl,rotational-matrices,Opengl,Matrix,Lwjgl,Rotational Matrices,我们正在一个虚拟现实环境中使用HMD,并且有连续的跟踪器数据作为四元数。我们从中计算出一个漫游矩阵,剩下的就让OpenGL来做 现在我们要在开始时设置一个特定的方向,这意味着重置来自跟踪器的数据并始终计算偏移量 编辑: 经过更多的测试后,我们认为以下是正确的,因为我们通过改变计算和资源中的轴从左手坐标系切换到右手坐标系 public void trackerPositionUpdate(TrackerUpdate u, TrackerRemote tracker) { if (!isr
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键时很难找到重置位置的例程。当您说位置正确,但“某个轴”被否定时,它始终是一个轴吗?听起来你在处理右手坐标系和左手坐标系。当我们在没有方向重置(偏移)的情况下进行跟踪时,跟踪方向是正确的。据我所知,我们切换到旋转矩阵中的轴(计算中有两列)。这只适用于跟踪,但在尝试重置时似乎会导致问题。不幸的是,我要到下周才能测试任何解决方案。