DeviceOrientationManager
A manager which will help you to control DeviceOrientation easily.
This manager supports graceful degradation, configurable frequency and smoothing.
Usage
Install:
npm i device-orientation-manager --save
Then:
import DeviceOrientationManager from 'device-orientation-manager';
const options = {
freq: 10,
enableMouseOrTouch?: 'auto',
container?: HTMLElement,
orientation?: 0 | 90 | 180 | -90 | 'auto',
filterSmoothing?: number,
filterWindowSize?: number
}
const doManager: DeviceOrientationManager = new DeviceOrientationManager(options);
doManager.freq = 30;
doManager.addEventListener(
'orientationchange',
orientation => {
console.log(orientation);
}
);
doManager.addEventListener(
'deviceorientation',
({yaw, pitch, roll, order, orientation}) => {
console.log({
yaw,
pitch,
roll,
orientation,
order
});
const q0 = new Quaternion();
const q1 = new Quaternion().rotateX(-Math.PI * 80 / 180);
const euler = new Euler();
euler.set(pitch, yaw, roll, order);
camera.quaternion.fromEuler(euler);
camera.quaternion.multiply(q1);
camera.quaternion.multiply(q0.setAxisAngle(new Vector3(0, 0, 1), -orientation));
}
);
doManager.start();
doManager.stop();