make calibration function
This commit is contained in:
parent
7698848df3
commit
74b8b377c8
|
@ -168,6 +168,7 @@ function orientCursor() {
|
|||
}
|
||||
else {
|
||||
relOrientation = orientation;
|
||||
console.log("fallback orientation")
|
||||
}
|
||||
// Create a vector for each arrow's initial orientation
|
||||
let xInit = new THREE.Vector3(1, 0, 0); // x-arrow pointing in positive x-direction
|
||||
|
@ -188,8 +189,12 @@ function orientCursor() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function calibrate() {
|
||||
if (initialOrientation == null) {
|
||||
console.log("Oriented");
|
||||
initialOrientation = orientation;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if AbsoluteOrientationSensor is defined
|
||||
if (window.AbsoluteOrientationSensor) {
|
||||
|
@ -204,10 +209,7 @@ if (window.AbsoluteOrientationSensor) {
|
|||
// Normalize the quaternion
|
||||
orientation.normalize;
|
||||
// Set the initial orientation if it's not set already
|
||||
if (initialOrientation === null) {
|
||||
console.log("Oriented")
|
||||
initialOrientation = orientation;
|
||||
}
|
||||
calibrate();
|
||||
// Profiling
|
||||
let currTime = new Date().getTime()
|
||||
if (sampleSec < currTime - 1000) {
|
||||
|
@ -221,12 +223,12 @@ if (window.AbsoluteOrientationSensor) {
|
|||
|
||||
// Get the button element
|
||||
const checkbox = document.getElementById('gyro') as HTMLInputElement;
|
||||
console.log("checkboxgotted: "+ checkbox)
|
||||
console.log("checkboxgotted: " + checkbox)
|
||||
|
||||
// Check if the button was found
|
||||
if (checkbox) {
|
||||
// Add a click event listener to the button
|
||||
checkbox.addEventListener('change', function() {
|
||||
checkbox.addEventListener('change', function () {
|
||||
// If sensor is already running, stop it
|
||||
if (!this.checked) {
|
||||
sensor.stop();
|
||||
|
@ -254,4 +256,4 @@ if (window.AbsoluteOrientationSensor) {
|
|||
} else {
|
||||
// Log a message to the console if AbsoluteOrientationSensor is not supported
|
||||
console.log('AbsoluteOrientationSensor is not supported in this browser.');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue