Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Core Motion in landscape mode
    text
    copied!<p>I am currently working on augmented reality and for that purpose I'd like to use the gyroscope and Core Motion. I've studied the Apple <a href="http://developer.apple.com/library/ios/#samplecode/pARk/Introduction/Intro.html" rel="nofollow">pARk</a> sample code, I understand most of the maths I've spend time on reading documentation because at first glance it was not clear! Everything is fine until I try to make it work in landscape mode.</p> <p>I won't explain all the theory here it would be too long. But for those who experienced it, my problem is, we take the rotation matrix of the attitude to apply this rotation to our coordinates. Ok, it is fine until here, but it seems Core Motion doesn't adapt it to Landscape Mode. I saw similar questions on this subject but it looks like no one has a solution. </p> <p>So I tried to make my own, here is what I think:</p> <p>Everytime we rotate the device to landscape, a rotation of +-90° is made (depending on Landscape Left or right). I decided to create a 4X4 rotation matrix to apply this rotation. And then multiply it to the cameraTransform matrix (adaption of the attitude's 3X3 CMRotationMatrix to 4X4), we obtain then the matrix cameraTransformRotated:</p> <pre><code>- (void)createMatLandscape{ switch(cameraOrientation){ case UIDeviceOrientationLandscapeLeft: landscapeRightTransform[0] = cos(degreesToRadians(90)); landscapeRightTransform[1] = -sin(degreesToRadians(90)); landscapeRightTransform[2] = 0; landscapeRightTransform[3] = 0; landscapeRightTransform[4] = sin(degreesToRadians(90)); landscapeRightTransform[5] = cos(degreesToRadians(90)); landscapeRightTransform[6] = 0; landscapeRightTransform[7] = 0; landscapeRightTransform[8] = 0; landscapeRightTransform[9] = 0; landscapeRightTransform[10] = 1; landscapeRightTransform[11] = 0; landscapeRightTransform[12] = 0; landscapeRightTransform[13] = 0; landscapeRightTransform[14] = 0; landscapeRightTransform[15] = 1; multiplyMatrixAndMatrix(cameraTransformRotated, cameraTransform, landscapeRightTransform); break; case UIDeviceOrientationLandscapeRight: landscapeLeftTransform[0] = cos(degreesToRadians(-90)); landscapeLeftTransform[1] = -sin(degreesToRadians(-90)); landscapeLeftTransform[2] = 0; landscapeLeftTransform[3] = 0; landscapeLeftTransform[4] = sin(degreesToRadians(-90)); landscapeLeftTransform[5] = cos(degreesToRadians(-90)); landscapeLeftTransform[6] = 0; landscapeLeftTransform[7] = 0; landscapeLeftTransform[8] = 0; landscapeLeftTransform[9] = 0; landscapeLeftTransform[10] = 1; landscapeLeftTransform[11] = 0; landscapeLeftTransform[12] = 0; landscapeLeftTransform[13] = 0; landscapeLeftTransform[14] = 0; landscapeLeftTransform[15] = 1; multiplyMatrixAndMatrix(cameraTransformRotated, cameraTransform, landscapeLeftTransform); break; default: cameraTransformRotated[0] = cameraTransform[0]; cameraTransformRotated[1] = cameraTransform[1]; cameraTransformRotated[2] = cameraTransform[2]; cameraTransformRotated[3] = cameraTransform[3]; cameraTransformRotated[4] = cameraTransform[4]; cameraTransformRotated[5] = cameraTransform[5]; cameraTransformRotated[6] = cameraTransform[6]; cameraTransformRotated[7] = cameraTransform[7]; cameraTransformRotated[8] = cameraTransform[8]; cameraTransformRotated[9] = cameraTransform[9]; cameraTransformRotated[10] = cameraTransform[10]; cameraTransformRotated[11] = cameraTransform[11]; cameraTransformRotated[12] = cameraTransform[12]; cameraTransformRotated[13] = cameraTransform[13]; cameraTransformRotated[14] = cameraTransform[14]; cameraTransformRotated[15] = cameraTransform[15]; break; } } </code></pre> <p>Then just before we update all the points I do this:</p> <pre><code>multiplyMatrixAndMatrix(projectionCameraTransform, projectionTransform, cameraTransformRotated); </code></pre> <p>After that the rest of the code remains unchanged, I just want the annotation to be displayed properly in landscape orientation. For now this is the only idea I have, the rendering in landscape is not good, I move the device to the right or the left hand-side, the annotations go down or up (like it was when I didn't add this code).</p> <p>Has anyone come up with a solution? I'll keep on searching, especially on the CMRotationMatrix, it doesn't seem it is a typical rotation matrix, I can't find any documentation saying precisely what are the different elements of this matrix. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload