distinctdan / cordova-plugin-device-motion

Apache Cordova Plugin device-motion
Apache License 2.0
3 stars 1 forks source link

Retrieve DeviceOrientation (Alpha, Beta, Gamma) values #1

Open francois-dibulo opened 4 years ago

francois-dibulo commented 4 years ago

First big thank you for reviving the plugin and making this fork!

I wonder if it would also be possible to retrieve the device orientation data, meaning rotation details in terms of degrees such as alpha, beta, gamma values in the same callback?

Thank you!

distinctdan commented 4 years ago

I appreciate the interest, but unfortunately rotations are more complicated because the angles you get depend on which of the 6 rotation orders you choose. You run into gimbal lock points at certain angles, so you want to choose the rotation order that works best for your application. Devices with magnetic sensors can help overcome this, but unfortunately not all android devices have one.

This plugin doesn't currently use the compass, so it'd add a small bit of complication to add conditional support for it. If this plugin did support rotation, it'd probably be best to have it return a quaternion or rotation matrix, then have the user convert to whatever angles they want in JS using a library like gl-matrix. That way, the plugin isn't locked into a particular rotation order. Adding rotation support is more than I'm willing to do at the moment, but I'd be open to PR's if you'd like to take a crack at it.