I have been experimenting with the Coremotion APIS, with the goal of transforming the coordinates from the phone reference system to the "earth" reference system as the one that is stored in the CMAttitude object. What I tried till now is by getting the CMRotationMatrix
CMRotationMatrix r = motionManager.deviceMotion.attitude.rotationMatrix;
and do a matrix multiplication with
CMAcceleration a = motionManager.deviceMotion.gravity;
in the following way (typedef float vec3f[3])
vec3f accelerationInReferenceSystem;
accelerationInReferenceSystem[0] = a.x * r.m11 + a.y * r.m12 + a.z * r.m13;
accelerationInReferenceSystem[1] = a.x * r.m21 + a.y * r.m22 + a.z * r.m23;
accelerationInReferenceSystem[2] = a.x * r.m31 + a.y * r.m32 + a.z * r.m33;
But, no luck. I am not that keen in 3D graphics, and there's not much documentation on how to use the various CMRotationMatrix, quaternions, etc. Before going this way, I have tried to log the values of d.attitude.pitch, d.attitude.roll and d.attitude.yaw. For what I have read, it's not the way to go, but besides that, I have found that the value returned by d.attitude.pitch spans just PI radians so I would need to include the yaw in the computation of the pitch angle from 0 to 2PI in order to understand where the head of the phone is heading. It seemed to me that using the rotation matrix would be the good way to go. Also, I wonder if I need to use a matrix that is the inverse of the current rotation matrix in order to take the coordinates into the system identified by r.attitude, thank you if you can help!