Sunday, June 23, 2024
HomeIOS DevelopmentChanging gyroscope values persistently throughout Android and iOS with Matter.js

Changing gyroscope values persistently throughout Android and iOS with Matter.js


I’m utilizing the Matter gyro demo in my venture and it really works completely on Android. Nevertheless, I am not capable of obtain constant outcomes on iOS.

That is the related snippet I’ve taken from the gyro demo:

if (window.display screen.orientation.angle === 0) {
  engine.gravity.x = Frequent.clamp(occasion.gamma, -90, 90) / 90
  engine.gravity.y = Frequent.clamp(occasion.beta, -90, 90) / 90
} else if (window.display screen.orientation.angle === 90) {
  engine.gravity.x = Frequent.clamp(occasion.beta, -90, 90) / 90
  engine.gravity.y = Frequent.clamp(-event.gamma, -90, 90) / 90
} else if (window.display screen.orientation.angle === 180) {
  engine.gravity.x = Frequent.clamp(occasion.gamma, -90, 90) / 90
  engine.gravity.y = Frequent.clamp(-event.beta, -90, 90) / 90
} else if (window.display screen.orientation.angle === -90) {
  engine.gravity.x = Frequent.clamp(-event.beta, -90, 90) / 90
  engine.gravity.y = Frequent.clamp(occasion.gamma, -90, 90) / 90
}

Nevertheless, if I run this on my iPad Air (fifth gen) working iOS 17.4.1 the gravity pulls to the best as a substitute of down. I believed I might sniff the browser and write another beta / gamma to x / y conversion, which I did and it appears to be like like this:

if (window.display screen.orientation.angle === 0) {
  engine.gravity.x = Frequent.clamp(occasion.beta, -90, 90) / 90
  engine.gravity.y = Frequent.clamp(-event.gamma, -90, 90) / 90
} else if (window.display screen.orientation.angle === 90) {
  engine.gravity.x = Frequent.clamp(occasion.gamma, -90, 90) / 90
  engine.gravity.y = Frequent.clamp(occasion.beta, -90, 90) / 90
} else if (window.display screen.orientation.angle === 180) {
  engine.gravity.x = Frequent.clamp(-event.beta, -90, 90) / 90
  engine.gravity.y = Frequent.clamp(occasion.gamma, -90, 90) / 90
} else if (window.display screen.orientation.angle === 270) {
  engine.gravity.x = Frequent.clamp(-event.gamma, -90, 90) / 90
  engine.gravity.y = Frequent.clamp(-event.beta, -90, 90) / 90
}

Nevertheless, when my consumer examined the above on their iPad Professional (third gen) working iOS 16.4.1 gravity pulled to the best once more, despite the fact that on my iPad it pulled down.

I ended up writing just a little device that permit me observe the readings of beta / gamma, and I can verify the readings are completely different on iOS when in comparison with Android. I additionally stumbled throughout this library known as Full Tilt which appeared to handle the difficulty, however I can’t use because it has since fallen out of upkeep (I’m constructing with webpack).

Has anybody had any luck with the gyro and getting it to work persistently throughout Android and iOS units?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments