Ulbertain Ulbertain - 3 years ago 131
Swift Question

How to turn CMRotationmatrix to initial position

I have a rotation matrix that I get from the motion manager. It rotates an object. Now I want to reset the Rotation, meaning that I press a button on the iPhone and the rotation is set back to the start without turning the iPhone to the start position.

I was able to achieve this by saving the initial values of m11 to m33 of the rotation matrix to an array and do this: (current position m11 to m33) - (position when pressing the reset button m11 to m33 - initial position of m11 to m33).

This leads to the current rotation matrix having the exact values as the initial matrix and therefore resetting the rotation. However, if I now turn the iPhone the resulting turning of the object is nonsense as are the values of the rotation matrix.

So what is the proper formula of calculating this / What is the formula to turn back the rotation matrix as many degrees in x/y/z as the iPhone has been turned until now?

Thanks a lot.

Answer Source

The answer is to take the initial transformation matrix and divide every new transformation matrix by it. My problem was that I did the calculation wrong. So a look at how to divide by a matrix helped.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download