Saturday, May 18, 2024
HomeiOS DevelopmentChanging gyroscope values constantly throughout Android and iOS with Matter.js

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


I’m utilizing the Matter gyro demo in my mission and it really works completely on Android. Nevertheless, I am not in a position to 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 fitting as a substitute of down. I believed I may 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 fitting once more, despite the fact that on my iPad it pulled down.

I ended up writing a bit software that permit me observe the readings of beta / gamma, and I can affirm the readings are totally different on iOS when in comparison with Android. I additionally stumbled throughout this library referred to 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 constantly throughout Android and iOS gadgets?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments