try gravity mapping

This commit is contained in:
“chrisshank” 2024-12-20 15:11:06 -08:00
parent b9b7be2aa4
commit 3fa91a3ec2
1 changed files with 16 additions and 20 deletions

View File

@ -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,23 +98,17 @@ 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") { console.info('Permission granted')
window.addEventListener("deviceorientation", onDeviceOrientation); } else {
console.log('registered') console.warn('Permission for device orientation rejected', permission)
} else {
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>