I've created the following widget (see demo here) to mimic the sensors tab on the chrome developer tab:
My code listens to the orientation event of the device and tries to convert the values to fit the css transform scale, like so:
let phone = document.querySelector(".phone");
window.addEventListener('deviceorientation', (event) => {
phone.style.transform =
"rotateY(" + ( event.alpha) + "deg) "
+
"rotateX(" + (90 - event.beta) + "deg) "
+
"rotateZ(" + (event.gamma ) + "deg)";
})
However, if I play around enough with the values, my widget and the chrome widget get out of sync. Obviously, my calculations are wrong, what am I missing?
To test my code, just go to the demo open the dev tools sensors tab and play around with the widget.
Any help would be appreciated.
Update: to get to the sensors tab: Open dev tools, press Esc, on the second panel click the 3dots on the left and choose sensors.
Update:
Example of problematic values are:
alpha: -77.6163
beta:-173.4458
gamma:-40.4889