I am doing something like an augmented reality application in which I have an OpenGL scene that I want to maintain in accordance with gravity no matter how the iOS device moves. I thought that everything worked out with CMDeviceMotion.attitude.pitch, until I found that leaning against the iPhone, he bypasses this number. So I took the code from the pARk * example, and now I'm trying to isolate the rotation around vertical access. The scene I am painting doesnβt care what title the user stands with, the numbers will always be drawn at a given distance from the viewer. I think that when I figure out the rotation component of the vertical axis, I can flip it and multiply it by the rotation matrix, so keep the OpenGL shapes fixed when the user changes the title.
Here is my code:
CMDeviceMotion *d = motionManager.deviceMotion; if (d != nil) { CMRotationMatrix r = d.attitude.rotationMatrix; transformFromCMRotationMatrix(cameraTransform, &r); mat4f_t projectionCameraTransform; multiplyMatrixAndMatrix(projectionCameraTransform, projectionTransform, cameraTransform); GLKMatrix4 rotMatrix = GLKMatrix4Make(projectionCameraTransform[0], projectionCameraTransform[1], projectionCameraTransform[2], projectionCameraTransform[3], projectionCameraTransform[4], projectionCameraTransform[5], projectionCameraTransform[6], projectionCameraTransform[7], projectionCameraTransform[8], projectionCameraTransform[9], projectionCameraTransform[10], projectionCameraTransform[11], projectionCameraTransform[12], projectionCameraTransform[13], projectionCameraTransform[14], projectionCameraTransform[15]); }
Then I use rotMatrix, as usual, in OpenGL.
Thoughts, suggestions? Thanks in advance.
* The pARk sample code sets up several points in real space, gives the user's location and the relative direction of these points and draws them on the screen, so they appear on the horizon, indicating their location.