try gravity mapping
This commit is contained in:
parent
b9b7be2aa4
commit
3fa91a3ec2
|
|
@ -80,13 +80,15 @@ rotation: from.x"
|
||||||
requestAnimationFrame(tick);
|
requestAnimationFrame(tick);
|
||||||
if (orientationEvent === undefined) return;
|
if (orientationEvent === undefined) return;
|
||||||
|
|
||||||
window.alpha.textContent = orientationEvent.alpha.toFixed(2);
|
window.alpha.textContent = Math.round(orientationEvent.alpha);
|
||||||
window.beta.textContent = orientationEvent.beta.toFixed(2);
|
window.beta.textContent = Math.round(orientationEvent.beta);
|
||||||
window.gamma.textContent = orientationEvent.gamma.toFixed(2);
|
window.gamma.textContent = Math.round(orientationEvent.gamma);
|
||||||
|
// Max out the gravity at around 3000
|
||||||
|
const gravity = { x: orientationEvent.gamma * 40, y: orientationEvent.beta * 20};
|
||||||
|
|
||||||
// if (event.alpha) {
|
window.gravity.textContent = `${Math.round(gravity.x)}, ${Math.round(gravity.y)}`;
|
||||||
// // ropes.forEach(rope => { rope.gravity = { x: 0, y: 0} })
|
|
||||||
// }
|
ropes.forEach(rope => { rope.gravity = gravity});
|
||||||
}
|
}
|
||||||
|
|
||||||
tick();
|
tick();
|
||||||
|
|
@ -96,24 +98,18 @@ rotation: from.x"
|
||||||
}
|
}
|
||||||
|
|
||||||
window.enableGravity = async function enableGravity() {
|
window.enableGravity = async function enableGravity() {
|
||||||
console.log('requesting')
|
|
||||||
if (DeviceOrientationEvent.requestPermission) {
|
if (DeviceOrientationEvent.requestPermission) {
|
||||||
try {
|
|
||||||
const permission = await DeviceOrientationEvent.requestPermission();
|
const permission = await DeviceOrientationEvent.requestPermission();
|
||||||
console.log('permission', permission)
|
|
||||||
if (permission === "granted") {
|
if (permission === "granted") {
|
||||||
window.addEventListener("deviceorientation", onDeviceOrientation);
|
console.info('Permission granted')
|
||||||
console.log('registered')
|
|
||||||
} else {
|
} else {
|
||||||
console.warn('Permission for device orientation rejected', permission)
|
console.warn('Permission for device orientation rejected', permission)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
window.addEventListener("deviceorientation", onDeviceOrientation);
|
window.addEventListener("deviceorientation", onDeviceOrientation);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue