/// <summary> /// Simulate a triggered gesture. If multiple gestures are triggered, they will be queued across sensor frames. /// </summary> /// <param name="gesture"></param> public void SimulateGesture(GestureId gesture) { if (gesture != GestureId.None) { _pendingGestures.Enqueue(gesture); } }
/// <summary> /// Recognizes a gesture sequence. It will always assume that the gesture ends on the last observation of that sequence. /// If the distance between the last observations of each sequence is too great, or if the overall DTW distance between /// the two sequence is too great, no gesture will be recognized /// </summary> /// <param name="seq"></param> /// <returns></returns> public IGesture Recognize(ArrayList seq) { double minDist = double.PositiveInfinity; GestureId gestureId = GestureId.Unknown; ThresholdSettings minSettings = null; for (int i = 0; i < sequences.Count; i++) { ThresholdSettings settings = (ThresholdSettings)recognitionSettings[i]; ArrayList example = (ArrayList)sequences[i]; if (this.Distance((double[])seq[seq.Count - 1], (double[])example[example.Count - 1]) < settings.FirstThreshold) { double d = dtw(seq, example, settings) / (example.Count); if (d < minDist) { minDist = d; gestureId = (GestureId)(sequenceIds[i]); minSettings = settings; } } } return(new Gesture() { Id = (minSettings != null && minDist < minSettings.MatchThreshold ? gestureId : GestureId.Unknown), MinDistance = minDist }); }
/// <summary> /// Constructs a new <see cref="MagicLeapKeyPoseGestureEvent"/>. /// </summary> /// <param name="id">The <see cref="GestureId"/> associated with the gesture.</param> /// <param name="state">The <see cref="GestureId"/> associated with the gesture.</param> /// <param name="keyPose">The <see cref="MagicLeapKeyPose"/> associated with the gesture.</param> /// <param name="hand">The <see cref="MagicLeapHand"/> associated with the gesture.</param> public MagicLeapKeyPoseGestureEvent(GestureId id, GestureState state, MagicLeapKeyPose keyPose, MagicLeapHand hand) { m_Id = id; m_State = state; m_KeyPose = keyPose; m_Hand = hand; }
/// <summary> /// Returns an appropriate <see cref="WearableGestureConfig"/> for the passed <see cref="GestureId"/> /// <paramref name="gestureId"/> /// </summary> /// <param name="gestureId"></param> /// <returns></returns> public WearableGestureConfig GetGestureConfig(GestureId gestureId) { WearableGestureConfig config; switch (gestureId) { case GestureId.DoubleTap: config = doubleTap; break; case GestureId.HeadNod: config = headNod; break; case GestureId.HeadShake: config = headShake; break; case GestureId.None: default: throw new ArgumentOutOfRangeException("gestureId", gestureId, null); } return(config); }
internal override void EnableGesture(GestureId gestureId) { if (_connectedDevice == null) { _gestureStatus[gestureId] = false; Debug.LogWarning(WearableConstants.EnableGestureWithoutDeviceWarning); return; } if (_gestureStatus[gestureId]) { return; } #if UNITY_IOS && !UNITY_EDITOR WearableEnableGesture((int)gestureId); WearableListenForGestureData(true); #elif UNITY_ANDROID && !UNITY_EDITOR // @TODO: The Android API appears to still be evolving here. If they keep adding separate // calls for each gesture we should turn this into a switch statement. if (gestureId == GestureId.DoubleTap) { Plugin.EnableDoubleTap(); } else { Debug.LogFormat(WearableConstants.EnableGestureNotSupportedWarning, Enum.GetName(typeof(GestureId), gestureId)); } #endif _gestureStatus[gestureId] = true; }
internal override void DisableGesture(GestureId gestureId) { if (!_gestureStatus[gestureId]) { return; } _gestureStatus[gestureId] = false; #if UNITY_IOS && !UNITY_EDITOR WearableDisableGesture((int)gestureId); // Are any gestures still active? If not, stop listening. bool anyActive = false; GestureId[] gestureValues = WearableConstants.GestureIds; for (int i = 0; i < gestureValues.Length; ++i) { if (gestureValues[i] != GestureId.None) { anyActive |= _gestureStatus[gestureValues[i]]; } } if (anyActive == false) { WearableListenForGestureData(false); } #elif UNITY_ANDROID && !UNITY_EDITOR AndroidPlugin.DisableGesture(gestureId); #endif }
/// <summary> /// Simulate some gesture data. /// </summary> /// <returns>True if a gesture was generated, else false</returns> private bool UpdateGestureData() { if (_pendingGestures.Count > 0) { GestureId gesture = _pendingGestures.Dequeue(); if (_gestureStatus[gesture]) { // If the gesture is enabled, go ahead and trigger it. if (_verbose) { Debug.LogFormat(WearableConstants.DebugProviderTriggerGesture, Enum.GetName(typeof(GestureId), gesture)); } _lastSensorFrame.gestureId = gesture; return(true); } else { // Otherwise, warn, and drop the gesture from the queue. Debug.LogWarning(WearableConstants.DebugProviderTriggerDisabledGestureWarning); } } _lastSensorFrame.gestureId = GestureId.None; return(false); }
public void DisableGesture(GestureId gestureId) { if (_wearablePlugin != null) { _wearablePlugin.Call(EnableGestureMethod, (byte)gestureId, false); } }
/// <summary> /// Check an arbitrary intent for validity against the configurable sensor and gesture availability. /// </summary> /// <param name="profile"></param> /// <returns></returns> private bool CheckIntentValidity(AppIntentProfile profile) { // Sensors for (int i = 0; i < WearableConstants.SensorIds.Length; i++) { SensorId id = WearableConstants.SensorIds[i]; if (profile.GetSensorInProfile(id) && !_virtualDevice.IsSensorAvailable(id)) { return(false); } } // Check gestures for (int i = 0; i < WearableConstants.GestureIds.Length; i++) { GestureId id = WearableConstants.GestureIds[i]; if (id == GestureId.None) { continue; } if (profile.GetGestureInProfile(id) && !_virtualDevice.IsGestureAvailable(id)) { return(false); } } // NB All intervals are supported by the debug provider, so this part of the intent profile is not validated. return(true); }
/// <summary> /// Sets the <see cref="GestureId"/> <paramref name="gestureId"/> for this control. /// </summary> /// <param name="gestureId"></param> public void SetGestureId(GestureId gestureId) { Assert.AreNotEqual(gestureId, GestureId.None); _gestureId = gestureId; _labelText.text = _gestureId.ToString().Nicify().ToUpper(); }
/// <summary> /// Invokes the <see cref="GestureDetected"/> event. /// </summary> /// <param name="gestureId"></param> protected void OnGestureDetected(GestureId gestureId) { if (GestureDetected != null) { GestureDetected.Invoke(gestureId); } }
/// <summary> /// Get pose data for a supported gesture. /// </summary> public static ArticulatedHandPose GetGesturePose(GestureId gesture) { if (handPoses.TryGetValue(gesture, out ArticulatedHandPose pose)) { return(pose); } return(null); }
private void GestureDetected(GestureId gesture) { if (gesture != _gesture) { return; } _onGestureDetected.Invoke(); }
/// <summary> /// Sets the appropriate <see cref="GestureId"/> <paramref name="gestureId"/> to detect and display. /// </summary> /// <param name="gestureId"></param> /// <param name="gestureSpriteIcon"></param> /// <param name="gestureGlowSpriteIcon"></param> public void Set(GestureId gestureId, Sprite gestureSpriteIcon, Sprite gestureGlowSpriteIcon) { Assert.IsFalse(gestureId == GestureId.None, string.Format(WearableConstants.NoneIsInvalidGesture, GetType())); _gestureDetector.Gesture = gestureId; _gestureIcon.sprite = gestureSpriteIcon; _gestureGlowIcon.sprite = gestureGlowSpriteIcon; }
/// <summary> /// Checks if a gesture is part of a complex gesture /// </summary> /// <param name="cg">A complex gesture</param> /// <param name="i">Index of gesture from complex gesture to test</param> /// <param name="leftGesture">Left gesture to test</param> /// <param name="rightGesture">Right gesture to test</param> /// <returns></returns> public bool CheckNextGestureInComplexGesture(Gesture cg, int i, GestureId leftGesture, GestureId rightGesture) { if (i <= cg.SequenceofGesturesToRecognize.Count - 1) { return(cg.SequenceofGesturesToRecognize[i].LeftAndRightHandSymbols[0] == leftGesture || cg.SequenceofGesturesToRecognize[i].LeftAndRightHandSymbols[1] == rightGesture); } return(false); }
private void GestureDetected(GestureId gestureId) { if (_gestureAnimationCoroutine != null) { StopCoroutine(_gestureAnimationCoroutine); } _gestureAnimationCoroutine = StartCoroutine(AnimateGestureEvent(gestureId)); }
internal override void DisableGesture(GestureId gestureId) { if (!_gestureStatus[gestureId]) { return; } _gestureStatus[gestureId] = false; }
private void Start() { var deviceAgnosticChildCount = _deviceAgnosticRootTransform.childCount; for (var i = deviceAgnosticChildCount - 1; i >= 0; i--) { var childGameObject = _deviceAgnosticRootTransform.GetChild(i); Destroy(childGameObject.gameObject); } var deviceSpecificChildCount = _deviceSpecificRootTransform.childCount; for (var i = deviceSpecificChildCount - 1; i >= 0; i--) { var childGameObject = _deviceSpecificRootTransform.GetChild(i); Destroy(childGameObject.gameObject); } _wearableControl = WearableControl.Instance; for (var i = 0; i < WearableConstants.GESTURE_IDS.Length; i++) { GestureId gestureId = WearableConstants.GESTURE_IDS[i]; if (gestureId == GestureId.None) { continue; } if (_wearableControl.GetWearableGestureById(gestureId).IsAvailable == false) { continue; } Sprite sprite; if (!_gestureIconFactory.TryGetGestureIcon(gestureId, out sprite)) { Debug.LogWarningFormat(this, GESTURE_ICON_NOT_FOUND_FORMAT, gestureId); continue; } Sprite glowSprite; if (!_gestureGlowIconFactory.TryGetGestureIcon(gestureId, out glowSprite)) { Debug.LogWarningFormat(this, GESTURE_ICON_NOT_FOUND_FORMAT, gestureId); continue; } Transform displayRoot = (gestureId.IsGestureDeviceAgnostic())? _deviceAgnosticRootTransform : _deviceSpecificRootTransform; var gestureDisplay = Instantiate(_gestureDisplay, displayRoot, false); gestureDisplay.Set(gestureId, sprite, glowSprite); gestureDisplay.gameObject.SetActive(true); } }
private static ArticulatedHandPose LoadGesturePose(GestureId gesture, string filePath) { if (!string.IsNullOrEmpty(filePath)) { var pose = new ArticulatedHandPose(); pose.FromJson(File.ReadAllText(filePath)); handPoses.Add(gesture, pose); return(pose); } return(null); }
private void OnGestureControlPacket(GestureId gestureId, bool enabled) { if (enabled) { _deviceProvider.EnableGesture(gestureId); } else { _deviceProvider.DisableGesture(gestureId); } }
private void SendWelcomePackets() { // Prepare to transmit _transmitIndex = 0; // Device connection info if (_deviceProvider.ConnectedDevice == null) { WearableProxyServerProtocol.EncodeConnectionStatus( _transmitBuffer, ref _transmitIndex, WearableProxyProtocolBase.ConnectionState.Disconnected, new Device { name = String.Empty, uid = WearableConstants.EmptyUID }); } else { _transmitIndex = 0; WearableProxyServerProtocol.EncodeConnectionStatus( _transmitBuffer, ref _transmitIndex, WearableProxyProtocolBase.ConnectionState.Connected, _deviceProvider.ConnectedDevice.Value); } // Update interval value WearableProxyServerProtocol.EncodeUpdateIntervalValue(_transmitBuffer, ref _transmitIndex, _deviceProvider.GetSensorUpdateInterval()); // Rotation source WearableProxyServerProtocol.EncodeRotationSourceValue(_transmitBuffer, ref _transmitIndex, _deviceProvider.GetRotationSource()); // Sensor status SensorId[] sensors = (SensorId[])Enum.GetValues(typeof(SensorId)); for (int i = 0; i < sensors.Length; i++) { SensorId sensor = sensors[i]; WearableProxyServerProtocol.EncodeSensorStatus(_transmitBuffer, ref _transmitIndex, sensor, _deviceProvider.GetSensorActive(sensor)); } // Gesture status GestureId[] gestures = WearableConstants.GestureIds; for (int i = 0; i < gestures.Length; i++) { GestureId gestureId = gestures[i]; if (gestureId != GestureId.None) { WearableProxyServerProtocol.EncodeGestureStatus(_transmitBuffer, ref _transmitIndex, gestureId, _deviceProvider.GetGestureEnabled(gestureId)); } } // Transmit SendTransmitBuffer(); }
private void GestureDetected(GestureId gesture) { if (gesture != _gesture) { return; } _onGestureDetected.Invoke(); Debug.Log("hoy"); //cube.GetComponent<AudioSource>().Play(); }
/// <summary> /// Loads the gestures configuration and loads all necessary gesture files /// </summary> /// <param name="config">The configuration node</param> private void LoadGestures(XmlDocument config) { config.ProcessXmlNodes("//configuration/gestures/gesture", gesture => { ArrayList frames = this.LoadGesture(gesture.Attributes["filename"].Value); GestureId gestureId = (GestureId)int.Parse(gesture.Attributes["id"].Value); this.Gestures[gestureId] = frames; }); }
/// <summary> /// Simulate a triggered gesture. If multiple gestures are triggered in a single update, they will be /// triggered simultaneously. /// </summary> /// <param name="gesture"></param> public void SimulateGesture(GestureId gesture) { if (gesture != GestureId.None) { GestureData gestureData = new GestureData { gestureId = gesture, timestamp = _nextSensorUpdateTime }; _pendingGestures.Enqueue(gestureData); } }
/// <summary> /// Disables the <see cref="WearableGesture"/> for <see cref="GestureId"/> <paramref name="gestureId"/> /// </summary> /// <param name="gestureId"></param> private void DisableGesture(GestureId gestureId) { if (gestureId == GestureId.None) { throw new Exception(WearableConstants.GestureIdNoneInvalidError); } if (DisableGestureInternal(gestureId)) { LockDeviceStateUpdate(); } }
/// <summary> /// Sets the gesture configuration for <see cref="GestureId"/> <paramref name="gestureId"/> to be disabled. /// </summary> /// <param name="gestureId"></param> public void DisableGesture(GestureId gestureId) { var gesture = DeviceConfig.GetGestureConfig(gestureId); if (!gesture.isEnabled) { return; } gesture.isEnabled = false; SetDirty(); }
/// <summary> /// Loads the gestures based on the current state /// </summary> private void LoadGesturesToMatch() { Configuration cfg = Configuration.Instance; foreach (var pair in cfg.GestureTransitions) { if (pair.Key.Key == base.Id) { GestureId gestureId = pair.Key.Value; this.recognizer.AddPatterns(gestureId, cfg.Gestures[gestureId], cfg.GestureSettings[gestureId]); } } }
/// <summary> /// Add a gesture to the profile. /// </summary> /// <param name="id"></param> public void AddGesture(GestureId id) { if (id == GestureId.None) { return; } if (!GetGestureInProfile(id)) { _gestures.Add(id); _dirty = true; } }
/// <summary> /// Stop a gesture with a given <see cref="GestureId"/>. /// </summary> /// <param name="gestureId"></param> private bool DisableGestureInternal(GestureId gestureId) { var gestureConfig = _wearableDeviceConfig.GetGestureConfig(gestureId); if (!gestureConfig.isEnabled) { return(false); } gestureConfig.isEnabled = false; return(true); }
/// <summary> /// Checks if current gesture is contained in a complexe gesture. /// If it is not the case, current gesture will be considered a transition gesture. /// Otherwise, it counts as a normal gesture. /// </summary> /// <param name="leftGesture">Symbol corresponding to current left hand's gesture</param> /// <param name="rightGesture">Symbol corresponding to current right hand's gesture</param> /// <returns></returns> public bool IsNotIncludedInOtherComplexGesture(GestureId leftGesture, GestureId rightGesture) { foreach (Gesture cg in complexGestures.allComplexGestures) { for (int i = 0; i < cg.SequenceofGesturesToRecognize.Count; i++) { if (cg.SequenceofGesturesToRecognize[i].LeftAndRightHandSymbols[0] == leftGesture && cg.SequenceofGesturesToRecognize[i].LeftAndRightHandSymbols[1] == rightGesture) { return(false); } } } return(true); }
public void ConfigureGesture(GestureId gesture) { this.ConfigureGesture(gesture, true); }
public void ConfigureGesture(GestureId gesture, bool allow) { switch (gesture) { case GestureId.All: this.SetFlag(ref this.mAllGestures.config, 1, allow); break; case GestureId.Zoom: this.SetFlag(ref this.mZoom.config, 1, allow); this.mZoom.dirty = true; break; case GestureId.Pan: this.SetFlag(ref this.mPan.config, 1, allow); this.mPan.dirty = true; break; case GestureId.Pan_Single_Vert: this.SetFlag(ref this.mPan.config, 2, allow); this.mPan.dirty = true; break; case GestureId.Pan_Single_Hor: this.SetFlag(ref this.mPan.config, 4, allow); this.mPan.dirty = true; break; case GestureId.Pan_With_Gutter: this.SetFlag(ref this.mPan.config, 8, allow); this.mPan.dirty = true; break; case GestureId.Pan_With_Inertia: this.SetFlag(ref this.mPan.config, 0x10, allow); this.mPan.dirty = true; break; case GestureId.Rotate: this.SetFlag(ref this.mRotate.config, 1, allow); this.mRotate.dirty = true; break; case GestureId.TwoFingerTap: this.SetFlag(ref this.mTwoFingerTap.config, 1, allow); this.mTwoFingerTap.dirty = true; break; case GestureId.PressAndTap: this.SetFlag(ref this.mPressAndTap.config, 1, allow); this.mPressAndTap.dirty = true; break; } if (gesture == GestureId.All) { this.mAllGestures.dirty = true; this.ClearGestureConfigs(); } else { this.mAllGestures.dirty = false; } }