private void Update() { if (_calibrating) { // While calibrating, continuously sample the gyroscope and wait for it to fall below a motion // threshold. When that happens, or a timeout is exceeded, grab a sample from the rotation sensor and // use that as the reference rotation. SensorFrame frame = _wearableControl.LastSensorFrame; bool didWaitEnough = Time.unscaledTime > _calibrationStartTime + _minCalibrationTime; bool isStationary = frame.angularVelocity.value.magnitude < _calibrationMotionThreshold; bool didTimeout = Time.unscaledTime > _calibrationStartTime + _maxCalibrationTime; if ((didWaitEnough && isStationary) || didTimeout) { _referenceRotation = frame.rotation; _calibrating = false; // Pass along the reference to the rotation matcher on the widget. _widgetRotationMatcher.SetRelativeReference(frame.rotation); if (CalibrationCompleted != null) { CalibrationCompleted.Invoke(); } // Spawn the first target after calibration completes. Invoke("SpawnTarget", _spawnDelay); } } }
void Update() { if (_calibrating) { SensorFrame frame = _wearableControl.LastSensorFrame; bool didWaitEnough = Time.unscaledTime > _calibrationStartTime + 5; bool isStationary = frame.angularVelocity.value.magnitude < 1; bool didTimeout = Time.unscaledTime > _calibrationStartTime + 10; if ((didWaitEnough && isStationary) || didTimeout) { _referenceRotation = frame.rotation; _calibrating = false; // Pass along the reference to the rotation matcher on the widget. _matcher.SetRelativeReference(frame.rotation); if (CalibrationCompleted != null) { CalibrationCompleted.Invoke(); } } } }
/// <summary> /// Alternates which rotation mode is currently selected, and changes the text to match. /// </summary> /// <param name="isOn"></param> /// <exception cref="ArgumentOutOfRangeException"></exception> private void OnReferenceToggleClicked(bool isOn) { switch (_matcher.ReferenceMode) { case RotationMatcher.RotationReference.Absolute: // Was reset, now will center. Button allows users to reset again. _matcher.SetRelativeReference(); _referenceLabel.text = ResetLabel; break; case RotationMatcher.RotationReference.Relative: // Was centered, now will reset. Button allows users to center again. _matcher.SetAbsoluteReference(); _referenceLabel.text = CenterLabel; break; default: throw new ArgumentOutOfRangeException("ReferenceMode", _matcher.ReferenceMode, null); } }
/// <summary> /// Sets rotation to relative mode using the current orientation. /// </summary> public void SetRelativeReference() { _matcher.SetRelativeReference(_wearableControl.LastSensorFrame.rotationSixDof); }