src/core/sensors.js
/**
 * Requests access to AbsoluteOrientationSensor (accelerometer, gyroscope, magnetometer) and then starts these sensors
 */
Requests access to AbsoluteOrientationSensor (accelerometer, gyroscope, magnetometer) and then starts these sensors
Requests access to AbsoluteOrientationSensor ( accelerometer gyroscope magnetometer ) and then starts these sensors
function startOrientationSensor() {
    Promise.all([navigator.permissions.query({name: "accelerometer"}),
            navigator.permissions.query({name: "magnetometer"}),
            navigator.permissions.query({name: "gyroscope"})])
    .then(results => {
        if (results.every(result => result.state === "granted")) {
            sensor.onerror = event => console.log(event.error.name, event.error.message);
            sensor.onreading = () => {
                sensor.populateMatrix(sensorMat4);
                quat.set(sensorQuat, sensor.quaternion[0], sensor.quaternion[1],
                        sensor.quaternion[2], sensor.quaternion[3]);
            };
            sensor.start();
        } else {
            console.log("No permissions to use AbsoluteOrientationSensor.");
        }
    });
}
function startOrientationSensor ( ) { Promise . all ( [ navigator . permissions . query ( { name : "accelerometer" } ) , navigator . permissions . query ( { name : "magnetometer" } ) , navigator . permissions . query ( { name : "gyroscope" } ) ] ) . then ( results => { if ( results . every ( result => result . state === "granted" ) ) { sensor . onerror = event => console . log ( event . error . name , event . error . message ) ; sensor . onreading = ( ) => { sensor . populateMatrix ( sensorMat4 ) ; quat . set ( sensorQuat , sensor . quaternion [ 0 ] , sensor . quaternion [ 1 ] , sensor . quaternion [ 2 ] , sensor . quaternion [ 3 ] ) ; } ; sensor . start ( ) ; } else { console . log ( "No permissions to use AbsoluteOrientationSensor." ) ; } } ) ; }
Requests access to AbsoluteOrientationSensor (accelerometer, gyroscope, magnetometer) and then starts these sensors
Requests access to AbsoluteOrientationSensor ( accelerometer gyroscope magnetometer ) and then starts these sensors
// both sensor.quaternion and gl-matrix.quat have x,y,z,w order within the float[4] array // TODO: handle this properly