示例#1
0
        /// <summary>
        /// Updates the UI based on the passed <see cref="SensorQuaternion"/> <paramref name="sensorQuaternion"/>
        /// representing a <see cref="SensorFrame.rotation"/> value.
        /// </summary>
        /// <param name="sensorQuaternion"></param>
        public void UpdateUI(SensorQuaternion sensorQuaternion)
        {
            SensorId id = _rotationSource == RotationSensorSource.NineDof ? SensorId.RotationNineDof : SensorId.RotationSixDof;
            var      currentDeviceConfig = _wearableControl.CurrentDeviceConfig;
            var      style = currentDeviceConfig.GetSensorConfig(id).isEnabled
                                ? _colorPalette.GetCustomizedActiveStyle()
                                : _colorPalette.InactiveTitleElementStyle;

            var rotValue3 = _vizMode == VisualizationMode.Quaternion
                                ? sensorQuaternion.value.XYZ()
                                : sensorQuaternion.value.eulerAngles;

            var positiveFormat = _vizMode == VisualizationMode.Quaternion
                                ? DebuggingConstants.QUATERNION_COMPONENT_FORMAT_POSITIVE
                                : DebuggingConstants.EULER_DATA_COMPONENT_FORMAT_POSITIVE;

            var negativeFormat = _vizMode == VisualizationMode.Quaternion
                                ? DebuggingConstants.QUATERNION_COMPONENT_FORMAT_NEGATIVE
                                : DebuggingConstants.EULER_DATA_COMPONENT_FORMAT_NEGATIVE;

            // Update Rotation
            var isRotationEnabled = currentDeviceConfig.GetSensorConfig(id).isEnabled;
            var childElementColor = isRotationEnabled
                                ? _colorPalette.ActiveDataTextColor
                                : _colorPalette.InactiveDataTextColor;

            Color rotTitleTextColor;
            Color rotTitleElementColor;

            if (isRotationEnabled)
            {
                rotTitleTextColor    = style.textColor;
                rotTitleElementColor = style.elementColor;
            }
            else
            {
                rotTitleTextColor    = _colorPalette.InactiveTitleElementStyle.textColor;
                rotTitleElementColor = _colorPalette.InactiveTitleElementStyle.elementColor;
            }

            _rotationTitleText.color  = rotTitleTextColor;
            _rotationTitleImage.color = rotTitleElementColor;

            _rotationXText.color = childElementColor;
            _rotationXText.text  = string.Format(
                rotValue3.x >= 0
                                        ? positiveFormat
                                        : negativeFormat,
                DebuggingConstants.X_FIELD,
                Mathf.Abs(rotValue3.x));

            _rotationYText.color = childElementColor;
            _rotationYText.text  = string.Format(
                rotValue3.y >= 0
                                        ? positiveFormat
                                        : negativeFormat,
                DebuggingConstants.Y_FIELD,
                Mathf.Abs(rotValue3.y));

            _rotationZText.color = childElementColor;
            _rotationZText.text  = string.Format(
                rotValue3.z >= 0
                                        ? positiveFormat
                                        : negativeFormat,
                DebuggingConstants.Z_FIELD,
                Mathf.Abs(rotValue3.z));

            _rotationWText.color = childElementColor;
            if (_vizMode == VisualizationMode.Quaternion)
            {
                _rotationWText.text = string.Format(
                    sensorQuaternion.value.w >= 0
                                                ? positiveFormat
                                                : negativeFormat,
                    DebuggingConstants.W_FIELD,
                    Mathf.Abs(sensorQuaternion.value.w));
            }
            else
            {
                _rotationWText.text = string.Empty;
            }

            if (_rotationUncertaintyText != null)
            {
                var font = float.IsInfinity(sensorQuaternion.measurementUncertainty) ? _fontAlpha : _fontNumeric;
                if (_rotationUncertaintyText.font != font)
                {
                    _rotationUncertaintyText.font = font;
                }

                _rotationUncertaintyText.color = _rotationSource == RotationSensorSource.SixDof
                                                                                                        ? _colorPalette.InactiveUncertaintyTextColor
                                                                                                        : rotTitleTextColor;

                _rotationUncertaintyText.text = string.Format(
                    DebuggingConstants.UNCERTAINTY_FORMAT,
                    sensorQuaternion.measurementUncertainty).ToUpper();
            }

            var unitsLabelValue = _vizMode == VisualizationMode.Quaternion
                                ? string.Empty
                                : DebuggingConstants.EULER_UNITS;

            _rotationSourceText.color = rotTitleTextColor;
            _rotationSourceText.text  = string.Format(
                DebuggingConstants.ROTATION_SOURCE_FORMAT,
                _rotationSource == RotationSensorSource.NineDof ? NINE_DOF_LABEL : SIX_DOF_LABEL,
                unitsLabelValue);

            UpdateTextAnchors();
        }
        /// <summary>
        /// Updates the UI based on the passed <see cref="SensorQuaternion"/> <paramref name="sensorQuaternion"/>
        /// representing a <see cref="SensorFrame.rotation"/> value.
        /// </summary>
        /// <param name="sensorQuaternion"></param>
        public void UpdateUI(SensorQuaternion sensorQuaternion)
        {
            SensorId id = _rotationSource == RotationSensorSource.NineDof ? SensorId.RotationNineDof : SensorId.RotationSixDof;
            var      currentDeviceConfig = _wearableControl.CurrentDeviceConfig;
            var      style = currentDeviceConfig.GetSensorConfig(id).isEnabled
                                ? _colorPalette.GetCustomizedActiveStyle()
                                : _colorPalette.InactiveTitleElementStyle;

            var rotValue3 = _vizMode == VisualizationMode.Quaternion
                                ? sensorQuaternion.value.XYZ()
                                : sensorQuaternion.value.eulerAngles;

            var positiveFormat = _vizMode == VisualizationMode.Quaternion
                                ? DebuggingConstants.QuaternionComponentFormatPositive
                                : DebuggingConstants.EulerDataComponentFormatPositive;

            var negativeFormat = _vizMode == VisualizationMode.Quaternion
                                ? DebuggingConstants.QuaternionComponentFormatNegative
                                : DebuggingConstants.EulerDataComponentFormatNegative;

            // Update Rotation
            var isRotationEnabled = currentDeviceConfig.GetSensorConfig(id).isEnabled;
            var childElementColor = isRotationEnabled
                                ? _colorPalette.ActiveDataTextColor
                                : _colorPalette.InactiveDataTextColor;

            Color rotTitleTextColor;
            Color rotTitleElementColor;

            if (isRotationEnabled)
            {
                rotTitleTextColor    = style.textColor;
                rotTitleElementColor = style.elementColor;
            }
            else
            {
                rotTitleTextColor    = _colorPalette.InactiveTitleElementStyle.textColor;
                rotTitleElementColor = _colorPalette.InactiveTitleElementStyle.elementColor;
            }

            _rotationTitleText.color  = rotTitleTextColor;
            _rotationTitleImage.color = rotTitleElementColor;

            _rotationXText.color = childElementColor;
            _rotationXText.text  = string.Format(
                rotValue3.x >= 0
                                        ? positiveFormat
                                        : negativeFormat,
                DebuggingConstants.XField,
                Mathf.Abs(rotValue3.x));

            _rotationYText.color = childElementColor;
            _rotationYText.text  = string.Format(
                rotValue3.y >= 0
                                        ? positiveFormat
                                        : negativeFormat,
                DebuggingConstants.YField,
                Mathf.Abs(rotValue3.y));

            _rotationZText.color = childElementColor;
            _rotationZText.text  = string.Format(
                rotValue3.z >= 0
                                        ? positiveFormat
                                        : negativeFormat,
                DebuggingConstants.ZField,
                Mathf.Abs(rotValue3.z));

            _rotationWText.color = childElementColor;
            if (_vizMode == VisualizationMode.Quaternion)
            {
                _rotationWText.text = string.Format(
                    sensorQuaternion.value.w >= 0
                                                ? positiveFormat
                                                : negativeFormat,
                    DebuggingConstants.WField,
                    Mathf.Abs(sensorQuaternion.value.w));
            }
            else
            {
                _rotationWText.text = string.Empty;
            }

            if (_rotationUncertaintyText != null)
            {
                var font = float.IsInfinity(sensorQuaternion.measurementUncertainty) ? _fontAlpha : _fontNumeric;
                if (_rotationUncertaintyText.font != font)
                {
                    _rotationUncertaintyText.font = font;
                }

                _rotationUncertaintyText.color = _rotationSource == RotationSensorSource.SixDof
                                                                                                        ? _colorPalette.InactiveUncertaintyTextColor
                                                                                                        : rotTitleTextColor;

                _rotationUncertaintyText.text = string.Format(
                    DebuggingConstants.UncertaintyFormat,
                    sensorQuaternion.measurementUncertainty).ToUpper();
            }

            var unitsLabelValue = _vizMode == VisualizationMode.Quaternion
                                ? string.Empty
                                : DebuggingConstants.EulerUnits;

            _rotationSourceText.color = rotTitleTextColor;
            _rotationSourceText.text  = string.Format(
                DebuggingConstants.RotationSourceFormat,
                _rotationSource == RotationSensorSource.NineDof ? NineDofLabel : SixDofLabel,
                unitsLabelValue);

            UpdateTextAnchors();
        }
示例#3
0
        public void GetLatestSensorUpdatesInternal()
        {
            const string GetLengthMethod          = "length";
            const string GetFrameAtIndexMethod    = "getFrameAtIndex";
            const string GetAccelerationMethod    = "getAcceleration";
            const string GetAngularVelocityMethod = "getAngularVelocity";
            const string GetRotationSixDofMethod  = "getRotationSixDof";
            const string GetRotationNineDofMethod = "getRotationNineDof";

            const string GetWMethod           = "getW";
            const string GetXMethod           = "getX";
            const string GetYMethod           = "getY";
            const string GetZMethod           = "getZ";
            const string GetAccuracyMethod    = "getAccuracyValue";
            const string GetUncertaintyMethod = "getAccuracy";

            const string GetTimestampMethod = "getTimestamp";
            const string GetDeltaTimeMethod = "getDeltaTime";

            const string GetInput = "getInput";

            AndroidJavaObject androidObj = AndroidPlugin.GetFrames();
            int count = androidObj.Call <int>(GetLengthMethod);

            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    AndroidJavaObject frame = androidObj.Call <AndroidJavaObject>(GetFrameAtIndexMethod, i);

                    AndroidJavaObject accelValue      = frame.Call <AndroidJavaObject>(GetAccelerationMethod);
                    AndroidJavaObject angVelValue     = frame.Call <AndroidJavaObject>(GetAngularVelocityMethod);
                    AndroidJavaObject rotSixDofValue  = frame.Call <AndroidJavaObject>(GetRotationSixDofMethod);
                    AndroidJavaObject rotNineDofValue = frame.Call <AndroidJavaObject>(GetRotationNineDofMethod);

                    byte gesture = frame.Call <byte>(GetInput);

                    SensorVector3    accel      = new SensorVector3();
                    SensorVector3    gyro       = new SensorVector3();
                    SensorQuaternion rotSixDof  = new SensorQuaternion();
                    SensorQuaternion rotNineDof = new SensorQuaternion();

                    accel.value = new Vector3(
                        (float)accelValue.Call <double>(GetXMethod),
                        (float)accelValue.Call <double>(GetYMethod),
                        (float)accelValue.Call <double>(GetZMethod)
                        );
                    accel.accuracy = (SensorAccuracy)accelValue.Call <byte>(GetAccuracyMethod);

                    gyro.value = new Vector3(
                        (float)angVelValue.Call <double>(GetXMethod),
                        (float)angVelValue.Call <double>(GetYMethod),
                        (float)angVelValue.Call <double>(GetZMethod)
                        );
                    gyro.accuracy = (SensorAccuracy)angVelValue.Call <byte>(GetAccuracyMethod);

                    rotSixDof.value = new Quaternion(
                        (float)rotSixDofValue.Call <double>(GetXMethod),
                        (float)rotSixDofValue.Call <double>(GetYMethod),
                        (float)rotSixDofValue.Call <double>(GetZMethod),
                        (float)rotSixDofValue.Call <double>(GetWMethod)
                        );
                    rotSixDof.measurementUncertainty = (float)rotSixDofValue.Call <double>(GetUncertaintyMethod);

                    rotNineDof.value = new Quaternion(
                        (float)rotNineDofValue.Call <double>(GetXMethod),
                        (float)rotNineDofValue.Call <double>(GetYMethod),
                        (float)rotNineDofValue.Call <double>(GetZMethod),
                        (float)rotNineDofValue.Call <double>(GetWMethod)
                        );
                    rotNineDof.measurementUncertainty = (float)rotNineDofValue.Call <double>(GetUncertaintyMethod);


                    _currentSensorFrames.Add(
                        new SensorFrame
                    {
                        timestamp       = WearableConstants.Sensor2UnityTime * frame.Call <int>(GetTimestampMethod),
                        deltaTime       = WearableConstants.Sensor2UnityTime * frame.Call <int>(GetDeltaTimeMethod),
                        acceleration    = accel,
                        angularVelocity = gyro,
                        rotationSixDof  = rotSixDof,
                        rotationNineDof = rotNineDof,
                        gestureId       = (GestureId)gesture
                    }
                        );
                }
            }
        }
        /// <summary>
        /// Used internally by WearableControl to get the latest buffer of SensorFrame updates from
        /// the Wearable Device; the newest frame in that batch is set as the CurrentSensorFrame.
        /// </summary>
        private void GetLatestSensorUpdates()
        {
            _currentSensorFrames.Clear();

                        #if UNITY_IOS && !UNITY_EDITOR
            unsafe
            {
                BridgeSensorFrame *frames = null;
                int count = 0;
                WearableGetSensorFrames(&frames, &count);
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        var frame = frames + i;
                        _currentSensorFrames.Add(new SensorFrame {
                            timestamp       = WearableConstants.Sensor2UnityTime * frame->timestamp,
                            deltaTime       = WearableConstants.Sensor2UnityTime * frame->deltaTime,
                            acceleration    = frame->acceleration,
                            angularVelocity = frame->angularVelocity,
                            rotation        = frame->rotation,
                            gestureId       = frame->gestureId
                        });
                    }

                    _lastSensorFrame = _currentSensorFrames[_currentSensorFrames.Count - 1];

                    OnSensorsOrGestureUpdated(_lastSensorFrame);
                }
            }
                        #elif UNITY_ANDROID && !UNITY_EDITOR
            const string GetLengthMethod          = "length";
            const string GetFrameAtIndexMethod    = "getFrameAtIndex";
            const string GetAccelerationMethod    = "getAcceleration";
            const string GetAngularVelocityMethod = "getAngularVelocity";
            const string GetRotationMethod        = "getRotation";

            const string GetWMethod           = "getW";
            const string GetXMethod           = "getX";
            const string GetYMethod           = "getY";
            const string GetZMethod           = "getZ";
            const string GetAccuracyMethod    = "getAccuracyValue";
            const string GetUncertaintyMethod = "getAccuracy";

            const string GetTimestampMethod = "getTimestamp";
            const string GetDeltaTimeMethod = "getDeltaTime";

            const string GetInput = "getInput";

            AndroidJavaObject androidObj = AndroidPlugin.GetFrames();
            int count = androidObj.Call <int>(GetLengthMethod);

            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    AndroidJavaObject frame = androidObj.Call <AndroidJavaObject>(GetFrameAtIndexMethod, i);

                    AndroidJavaObject accelValue  = frame.Call <AndroidJavaObject>(GetAccelerationMethod);
                    AndroidJavaObject angVelValue = frame.Call <AndroidJavaObject>(GetAngularVelocityMethod);
                    AndroidJavaObject rotValue    = frame.Call <AndroidJavaObject>(GetRotationMethod);

                    byte gesture = frame.Call <byte>(GetInput);

                    SensorVector3    accel = new SensorVector3();
                    SensorVector3    gyro  = new SensorVector3();
                    SensorQuaternion rot   = new SensorQuaternion();

                    accel.value = new Vector3(
                        (float)accelValue.Call <double>(GetXMethod),
                        (float)accelValue.Call <double>(GetYMethod),
                        (float)accelValue.Call <double>(GetZMethod)
                        );
                    accel.accuracy = (SensorAccuracy)accelValue.Call <byte>(GetAccuracyMethod);

                    gyro.value = new Vector3(
                        (float)angVelValue.Call <double>(GetXMethod),
                        (float)angVelValue.Call <double>(GetYMethod),
                        (float)angVelValue.Call <double>(GetZMethod)
                        );
                    gyro.accuracy = (SensorAccuracy)angVelValue.Call <byte>(GetAccuracyMethod);

                    rot.value = new Quaternion(
                        (float)rotValue.Call <double>(GetXMethod),
                        (float)rotValue.Call <double>(GetYMethod),
                        (float)rotValue.Call <double>(GetZMethod),
                        (float)rotValue.Call <double>(GetWMethod)
                        );
                    rot.measurementUncertainty = (float)rotValue.Call <double>(GetUncertaintyMethod);

                    _currentSensorFrames.Add(
                        new SensorFrame
                    {
                        timestamp       = WearableConstants.Sensor2UnityTime * frame.Call <int>(GetTimestampMethod),
                        deltaTime       = WearableConstants.Sensor2UnityTime * frame.Call <int>(GetDeltaTimeMethod),
                        acceleration    = accel,
                        angularVelocity = gyro,
                        rotation        = rot,
                        gestureId       = (GestureId)gesture
                    }
                        );
                }

                _lastSensorFrame = _currentSensorFrames[_currentSensorFrames.Count - 1];

                OnSensorsOrGestureUpdated(_lastSensorFrame);
            }
                        #endif
        }