I am banging my head on the wall trying to understand this. See the next picture.
Suppose I have an iPhone resting on a table. At this time the rotation readings thru core motion are 0,0,0 for yaw, roll and pitch (picture A).
Then I roll it 90 degrees. Now it is sitting on the table with its left side, home button on the right. Now it reads 0,0,0 (picture B).
Now I yaw it 180 degrees. It is now sitting with its right side on the table. Home button on the left. It now reads 180,0,0 (picture C).
The problem comes if I roll it now. Suppose I roll it -45 degrees. I should be reading 180,-45,0 but instead I am reading 180,-45,180???? (picture D).
Why is that? Why is it giving me a value for pitch if I never changed that? How can be pitch influenced by a rotation in other angles? thanks.
The Android or iOS software then uses the accelerometer's data to tell how you're holding your phone and orients the screen appropriately so that when you want to switch from browsing the web to watching a wide-screen video, the screen rotates automatically.
To check if rotation lock is enabled, look at the top your screen, next to the battery icon. If rotation lock is on, you'll see the rotation lock icon—the lock with the curved arrow—to the left of the battery icon. If you don't see that icon, rotation lock is off.
To adjust the screen rotation settings: Swipe down from the top of the screen to open the Quick settings panel. Look for the screen orientation icon. Depending on your settings, you may need to look for the Portrait, Landscape, or Auto Rotate icon.
Given the case that you can live with delta movements, you can use "quaternion difference" operation. Let's say you have a previous rotation as quaternion called q1 and the current one q2. Then you can calculate the delta dQ between them so that q2 = q1*dQ is valid. All you have to do is build the inverse of q1 (q1^(-1)) and then you get:
dQ = q1^(-1) * q2
If deviceMotionInterval is high enough, you always have handy small Euler angles without any 90° singularities or other beasty stuff. The possible drawback of this solution might be a slight drift because of error propagation and the lack of feedback from your virtual space. Example: if you have your iPhone on a table showing a cube and then do a sequence of rotations, you might find a angular displacment of the cube when you put the phone back in starting position.
[EDIT:Forgot some part] To get rid of the drifting effect, you "only" need a way to express your last object's real position (q1) as a quaternion i.e. coordinates in your app as displayed on the screen. If you use tools like Unity it might be just reading the appropriate property of an the object. If you don't have easy access to it, you may have the possibility to track this position manually.
If you want to read more about this take a look at 3D math primer for graphics and game development, by Fletcher Dunn,Ian Parberry page 168.
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