openvr icon indicating copy to clipboard operation
openvr copied to clipboard

How to get roll,pitch,yaw from pose

Open Hellgringo83 opened this issue 10 years ago • 4 comments

I fetch new poses of the hmd and the controllers by waitGetPoses(). The result is a 3x4 matrix with the position in the last column. The 3x3 part is filled with a rotation matrix, I think? Getting the x,y,z position was quite easy but I'm to stupid to calculate the roll, pitch, yaw values out of the matrix. I'm really frustrated and I don't find anything in the documentation - internet.

Hellgringo83 avatar Sep 19 '16 15:09 Hellgringo83

http://gamedev.stackexchange.com/questions/50963/how-to-extract-euler-angles-from-transformation-matrix

JoeLudwig avatar Sep 19 '16 18:09 JoeLudwig

@Hellgringo83 hei,did you solve this problem?i meet the same question,could you tell me how to solve it. you can email me, [email protected].

thank you.

qywako avatar Apr 19 '17 01:04 qywako

If you look into hellovr_opengl_main.cpp you can see, that the _vr::k_unTrackedDeviceIndex_Hmd pose is not handled like the other controllers. You first need to call the invert() method (see line 1576). After that, you have the matrix that I expected in my first post and you can use the common methods to get the euler angles. I don't know why you have to do that. There is nothing you can find in the documentation and except of us nobody seems to be so dumb :).

Hellgringo83 avatar Apr 23 '17 08:04 Hellgringo83

@Hellgringo83 i try but failed.code like those:

    float cx[3][3];
double m[4][4];	
Matrix4 mat= m_rmat4DevicePose[unTrackedDevice];
//mat.invert();  //when unTrackedDevice==0,invert.
const float* pmat = mat.get();
const float matrixTemp[3][4]={
	pmat[0],pmat[1],pmat[2], pmat[3], 
	pmat[4],pmat[5],pmat[6], pmat[7],
	pmat[8],pmat[9],pmat[10],pmat[11]
};	
{  
	cx[0][0] =  matrixTemp[0][0];
	cx[0][1] =  matrixTemp[0][1];
	cx[0][2] = matrixTemp[0][2];
	cx[1][0] =  matrixTemp[1][0];
	cx[1][1] =  matrixTemp[1][1];
	cx[1][2] = matrixTemp[1][2];
	cx[2][0] = matrixTemp[2][0];
	cx[2][1] = matrixTemp[2][1];
	cx[2][2] = matrixTemp[2][2];
	GetRotation(cx,rot);
	pos.x = pmat[12];
	pos.y = pmat[13];
	pos.z = pmat[14];
}			 	

void Chellovr_engineDlg::GetRotation(float pose[3][3],Vector4& rot) { if (pose[0][0]>=pose[1][1]&&pose[0][0]>=pose[2][2]) { float s=sqrt(1+pose[0][0]-pose[1][1]-pose[2][2]); rot.x=(pose[2][1]-pose[1][2])/s; rot.y=s/4; rot.z=(pose[0][1]+pose[1][0])/s; rot.w=(pose[0][1]+pose[1][0])/s; } else if (pose[1][1]>=pose[0][0]&&pose[1][1]>=pose[2][2]) { float s=sqrt(1-pose[0][0]+pose[1][1]-pose[2][2]); rot.x=(pose[0][2]-pose[2][0])/s; rot.y=(pose[0][1]+pose[1][0])/s; rot.z=s/4; rot.w=(pose[2][1]+pose[1][2])/s; } else if (pose[2][2]>=pose[1][1]&&pose[2][2]>=pose[0][0]) { float s=sqrt(1-pose[0][0]-pose[1][1]+pose[2][2]); rot.x=(pose[1][0]-pose[0][1])/s; rot.y=(pose[0][2]+pose[2][0])/s; rot.z=(pose[1][2]-pose[2][1])/s; rot.w=s/4; } }

could you give me the soursecode?

qywako avatar May 03 '17 06:05 qywako