I'm looking at the core motion class CMAttitude
, it can express the device's orientation as a 3x3 rotational matrix. At the same time I've taken a look at the CATransform3D
, which encapsulates the view's attitude, as well as scaling. The CATransform3D
is a 4x4 matrix.
I've seen that the OpenGL rotational matrix is 4x4 and is simply 0001 padded in the 4th row and column.
I'm wandering if the CMAttitude's rotational matrix is related to CATransform's matrix?
Can I use the device's rotation in space obtained via a rotational matrix to transform a UIView using CATransform3D
? My intention is to let the user move the phone and apply the same transform to a UIView on the screen.
Bonus question: if they are related, how do I transform a CMAttitude's rotational matrix to CATransform3D?
Gyroscope is used to determine only the orientation of the device in space. There are many ways to parameterize the orientation itself (see the information about SO(3) group for theoretical information) - quaternions, Euler angles and 3x3 matrices are one of them.
The "embedding" of 3x3 matrix into the 4x4 matrix is not a GL-specific trick. It is a "semi-direct product" of the group of translations (which is isomorphic to all the 3D vectors) and the group of rotations (the SO(3) mentioned above).
To get the CATransform3D matrix from CMAttitude you have to suppose some position of your object. If it is zero, then just pad the matrix with 0001 as you've said.
This question might be of interest for you: Apple gyroscope sample code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With