Example #1
0
    void OnEnable()
    {
        motion = TrailCurveDrawCtrl.Instance().curMotion;
        hand   = new GameObject();

        length      = TrailCurveDrawCtrl.Instance().curve_length;
        start_index = 0;
        end_index   = (int)motion.getTraj(cur_traj).size();
    }
 protected virtual void OnHandMotionDetected(HandMotion motion)
 {
     if (handMotionDetected != null)
     {
         HandMotionDetectedEventArgs e = new HandMotionDetectedEventArgs();
         e.motion = motion;
         handMotionDetected(this, e);
     }
 }
 protected virtual void OnHandMotionDetected(HandMotion motion)
 {
     if (handMotionDetected != null)
     {
         HandMotionDetectedEventArgs e = new HandMotionDetectedEventArgs();
         e.motion = motion;
         handMotionDetected(this, e);
     }
 }
Example #4
0
    void OnEnable()
    {
        motion = TrailCurveDrawCtrl.Instance().studyMotion;
        hand   = new GameObject();

        length      = TrailCurveDrawCtrl.Instance().curve_length;
        start_index = 0;
        end_index   = (int)motion.getTraj(cur_traj).size();

        left_color_list  = TrailCurveAppraiseCtrl.left_color_list;
        right_color_list = TrailCurveAppraiseCtrl.left_color_list;
    }
Example #5
0
 /// <summary>
 /// Ends the motion define and add this motion to the dictionary.
 /// </summary>
 /// <returns><c>true</c>, if motion was ended and added successfully, <c>false</c> otherwise.</returns>
 public bool EndMotion()
 {
     if (isDefiningNewMotion && currentEditMotion != null)
     {
         handMotionList.Add(currentEditMotion.MotionName, currentEditMotion);
         Debug.Log("Action:Successfully Added. has " + currentEditMotion._actionList.Count + " actions.");
         currentEditMotion   = null;
         isDefiningNewMotion = false;
         return(true);
     }
     return(false);
 }
 private TrailCurveDrawCtrl()
 {
     trajs_num = 2;
     curMotion = new HandMotion();
     for (int i = 0; i < trajs_num; ++i)
     {
         curMotion.Add(new Trajectory());
     }
     studyMotion = new HandMotion();
     for (int i = 0; i < trajs_num; ++i)
     {
         studyMotion.Add(new Trajectory());
     }
 }
Example #7
0
    /// <summary>
    /// Begins the motion. You must call this before you defines a new motion that you're interested in.
    /// </summary>
    /// <returns><c>true</c>, if this motion name is available, <c>false</c> otherwise.</returns>
    /// <param name="motionName">The new motion name.</param>
    public bool BeginMotion(string motionName)
    {
        if (handMotionList.ContainsKey(motionName))
        {
            return(false);
        }

        if (isDefiningNewMotion)
        {
            Debug.LogWarning("Try to define a new motion when last motion define hasn't finished.");
            return(false);
        }

        // now start new motion
        currentEditMotion   = new HandMotion(motionName);
        isDefiningNewMotion = true;
        return(true);
    }
        private async void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Step 1: Connect to Microsoft Gestures service
            _gesturesService = GesturesServiceEndpointFactory.Create();
            _gesturesService.StatusChanged += (s, args) => Dispatcher.Invoke(() => GeturesServiceStatus.Text = $"[{args.Status}]");
            Closed += (s, args) => _gesturesService?.Dispose();
            await _gesturesService.ConnectAsync();

            // Step 2: Define the RewindGesture gesture as follows:
            //  ┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐
            //  │          │    │          │    │          │    │          │    │          │    │          │    │          │
            //  │   Idle   │ -> │  Spread  │ -> │  Pause   │ -> │  Rewind  │ -> │KeepRewind│ -> │ Release  │ -> │   Idle   │
            //  │          │    │(unpinch) │    │ (pinch)  │    │  (left)  │    │ (pinch)  │    │(unpinch) │    │          │
            //  └──────────┘    └──────────┘    └────┬─────┘    └──────────┘    └──────────┘    └──────────┘    └──────────┘
            //                                       │                                               ^
            //                                       └───────────────────────────────────────────────┘
            //
            // Whenever the gesture returns to the Idle state, playback will resume
            //
            var spreadPose = GeneratePinchPose("Spread", true);
            var pausePose  = GeneratePinchPose("Pause");

            pausePose.Triggered += (s, args) => Dispatcher.Invoke(() => VideoStatus.Text = "⏸");

            var rewindMotion = new HandMotion("Rewind", new PalmMotion(VerticalMotionSegment.Left));

            rewindMotion.Triggered += (s, args) => Dispatcher.Invoke(() => VideoStatus.Text = "⏪");

            var keepRewindingPose = GeneratePinchPose("KeepRewind");
            var releasePose       = GeneratePinchPose("Release", true);

            // Then define the gesture by concatenating the previous objects to form a simple state machine
            _rewindGesture = new Gesture("RewindGesture", spreadPose, pausePose, rewindMotion, keepRewindingPose, releasePose);
            // Detect if the user releases the pinch-grab hold in order to resume the playback
            _rewindGesture.AddSubPath(pausePose, releasePose);

            // Continue playing the video when the gesture resets (either successful or aborted)
            _rewindGesture.Triggered     += (s, args) => Dispatcher.Invoke(() => VideoStatus.Text = "▶");
            _rewindGesture.IdleTriggered += (s, args) => Dispatcher.Invoke(() => VideoStatus.Text = "▶");

            // Step 3: Register the gesture (When window focus is lost (gained) the service will automatically unregister (register) the gesture)
            //         To manually control the gesture registration, pass 'isGlobal: true' parameter in the function call below
            await _gesturesService.RegisterGesture(_rewindGesture);
        }
    // Use this for initialization
    void OnEnable()
    {
        motion = TrailCurveDrawCtrl.Instance().curMotion;
        //isPlay = TrailCurveDrawCtrl.Instance().getIsPlay();
        length = TrailCurveDrawCtrl.Instance().curve_length;

        start_index = 0;
        end_index   = (int)motion.getTraj(cur_traj).size();
        for (int i = 0; i < motion.size(); ++i)
        {
            initLineRenderer(i, Color.red, Color.red, 0.04f, 0.04f);
        }

        /*残影部分gameobject初始化
         * root1 = GameObject.Find("GameObject1");
         * root2 = GameObject.Find("GameObject2");
         * hand1 = root1.transform.Find("lefthand").gameObject;
         **/
    }
Example #10
0
    /// <summary>
    /// Determines whether a motion is satisfied.
    /// </summary>
    /// <returns><c>true</c> if the motion with motionName is satisfied; otherwise, <c>false</c>.</returns>
    /// <param name="motionName">Motion name.</param>
    public bool IsMotion(string motionName, bool isLeftHand = true)
    {
        // If not enabled, just return false.
        if (!isEnabled)
        {
            return(false);
        }

        if (handMotionList.ContainsKey(motionName))
        {
            HandMotion hm = handMotionList [motionName];

            // Debug.Log ("Action:Prepare Match");
            if (isLeftHand)
            {
                return(hm.Match(leftHandList));
            }
            else
            {
                return(hm.Match(rightHandList));
            }
        }
        return(false);
    }
    // Update is called once per frame
    void Update()
    {
        if (sw.pollSkeleton()) {
            float currentTime = Time.time;
            this.rightHandPos = sw.bonePos[PlayerId, 11];
            this.leftHandPos = sw.bonePos[PlayerId, 7];

            // get right hand velocity
            this.rightHandVelo = rightHandPos - rightHandPosPre;
            // get left hand velocity
            this.leftHandVelo = leftHandPos - leftHandPosPre;
            // right hand motion detection

            if (this.rightHandVelo.x > accuracy && Math.Abs(this.rightHandVelo.x) > Math.Abs(this.rightHandVelo.y))
            {
                if (currentRightHandMotion != HandMotion.RIGHT_HAND_WAVE_OUT)
                {
                    currentRightHandMotion = HandMotion.RIGHT_HAND_WAVE_OUT;
                    motionRightHandStartTime = currentTime;
                    motionStartRightHandPos = rightHandPos;
                }
            }
            else if (this.rightHandVelo.y > accuracy && Math.Abs(this.rightHandVelo.x) < Math.Abs(this.rightHandVelo.y))
            {
                if (currentRightHandMotion != HandMotion.RIGHT_HAND_RISE)
                {
                    currentRightHandMotion = HandMotion.RIGHT_HAND_RISE;
                    motionRightHandStartTime = currentTime;
                    motionStartRightHandPos = rightHandPos;
                }
            }
            else
            {
                currentRightHandMotion = HandMotion.NON;
            }

            // left hand motion detection
            if (this.leftHandVelo.x < -accuracy && Math.Abs(this.leftHandVelo.x) > Math.Abs(this.leftHandVelo.y))
            {
                if (currentLeftHandMotion != HandMotion.LEFT_HAND_WAVE_OUT)
                {
                    currentLeftHandMotion = HandMotion.LEFT_HAND_WAVE_OUT;
                    motionLeftHandStartTime = currentTime;
                    motionStartLeftHandPos = leftHandPos;
                }
            }
            else if (this.leftHandVelo.y > accuracy && Math.Abs(this.leftHandVelo.x) < Math.Abs(this.leftHandVelo.y))
            {
                if (currentLeftHandMotion != HandMotion.LEFT_HAND_RISE)
                {
                    currentLeftHandMotion = HandMotion.LEFT_HAND_RISE;
                    motionLeftHandStartTime = currentTime;
                    motionStartLeftHandPos = leftHandPos;
                }
            }
            else
            {
                currentLeftHandMotion = HandMotion.NON;
            }

            // validation of hand motion
            bool rightHandRiseValide = false;
            bool leftHandRiseValide = false;

            if (currentRightHandMotion == HandMotion.RIGHT_HAND_WAVE_OUT
                && currentTime - motionRightHandStartTime <= detectMotionDuration
                && rightHandPos.x - motionStartRightHandPos.x >= detectMotionDistance)
            {
                // right hand wave out detected
                // rise motion detected event
                OnHandMotionDetected(HandMotion.RIGHT_HAND_WAVE_OUT);
                // reset timer for new detection
                motionRightHandStartTime = currentTime;
                motionStartRightHandPos = rightHandPos;
            }
            else if (currentRightHandMotion == HandMotion.RIGHT_HAND_RISE
                    && currentTime - motionRightHandStartTime <= detectMotionDuration
                    && rightHandPos.y - motionStartRightHandPos.y >= detectMotionDistance)
            {
                rightHandRiseValide = true;
                OnHandMotionDetected(HandMotion.RIGHT_HAND_RISE);
            }
            // left
            if (currentLeftHandMotion == HandMotion.LEFT_HAND_WAVE_OUT
                && currentTime - motionLeftHandStartTime <= detectMotionDuration
                && motionStartLeftHandPos.x - leftHandPos.x >= detectMotionDistance)
            {
                // left hand wave out detected
                // rise motion detected event
                OnHandMotionDetected(HandMotion.LEFT_HAND_WAVE_OUT);
                // reset timer for new detection
                motionLeftHandStartTime = currentTime;
                motionStartLeftHandPos = leftHandPos;
            }
            else if (currentLeftHandMotion == HandMotion.LEFT_HAND_RISE
                    && currentTime - motionLeftHandStartTime <= detectMotionDuration
                    && leftHandPos.y - motionStartLeftHandPos.y >= detectMotionDistance)
            {
                leftHandRiseValide = true;
                OnHandMotionDetected(HandMotion.LEFT_HAND_RISE);
            }
            // double hand
            if (rightHandRiseValide && leftHandRiseValide)
            {
                // double hands rise detected
                // rise motion detected event
                OnHandMotionDetected(HandMotion.TWO_HAND_RISE);
                motionRightHandStartTime = currentTime;
                motionLeftHandStartTime = currentTime;
                motionStartRightHandPos = rightHandPos;
                motionStartLeftHandPos = leftHandPos;
            }

            rightHandPosPre = rightHandPos;
            leftHandPosPre = leftHandPos;

        }
    }
	public bool destroyDirdByHandMotion(HandMotion _enum_handMotion)
	{
		bool b_destroyed = false;

		if(_enum_handMotion == HandMotion.LEFT_HAND_WAVE_OUT)
		{
			if(list_leftSidebirds.Count != 0 && list_leftSidebirds[0] != null)
			{
				GameObject go_bird = list_leftSidebirds[0];
				list_leftSidebirds.RemoveAt(0);
				GameObject.Destroy(go_bird);
				b_destroyed = true;
				//Debug.Log("Left bird has been destroyed!!!!!");
			}
		}
		else if(_enum_handMotion == HandMotion.DOUBLE_HAND_RISE)
		{
			if(list_upSidebirds.Count != 0 && list_upSidebirds[0] != null)
			{
				GameObject go_bird = list_upSidebirds[0];
				list_upSidebirds.RemoveAt(0);
				GameObject.Destroy(go_bird);
				b_destroyed = true;
				//Debug.Log("Up bird has been destroyed");

			}
		}
		else if(_enum_handMotion == HandMotion.RIGHT_HAND_WAVE_OUT)
		{
			if(list_rightSidebirds.Count != 0 && list_rightSidebirds[0] != null)
			{
				GameObject go_bird = list_rightSidebirds[0];
				list_rightSidebirds.RemoveAt(0);
				GameObject.Destroy(go_bird);
				b_destroyed = true;
				//Debug.Log("Right bird has been destroyed");
			}
		}

		return b_destroyed;
	}
Example #13
0
        public async Task Init()
        {
            var pausePose = new HandPose("PausePose", new PalmPose(new AnyHandContext(), PoseDirection.Forward, PoseDirection.Up),
                                         new FingerPose(new AllFingersContext(), FingerFlexion.Open, PoseDirection.Up));

            //pausePose.Triggered += (s, arg) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureType.Pause.ToString()));
            pausePose.Triggered += (s, arg) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.PLAYER_PAUSE));

            var selectPose = new HandPose("selectPose", new PalmPose(new AnyHandContext(), PoseDirection.Left, PoseDirection.Forward),
                                          new FingerPose(Finger.Index, FingerFlexion.OpenStretched, PoseDirection.Forward),
                                          new FingerPose(new AllFingersContext(new [] { Finger.Middle, Finger.Ring, Finger.Pinky }), PoseDirection.Backward));

            selectPose.Triggered += (s, arg) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_SELECT));

            var menuPose = new HandPose("menuPose", new PalmPose(new AnyHandContext(), PoseDirection.Backward, PoseDirection.Down),
                                        new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle, Finger.Ring }), FingerFlexion.OpenStretched, PoseDirection.Down),
                                        new FingerPose(new AllFingersContext(new [] { Finger.Thumb, Finger.Pinky }), FingerFlexion.Folded)
                                        );

            //menuPose.Triggered += (s, arg) => KinectActionRecognized?.Invoke(GestureType.Menu);
            menuPose.Triggered += (s, arg) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_HOME));

            var contextPose = new HandPose("contextPose", new PalmPose(new AnyHandContext(), PoseDirection.Backward, PoseDirection.Up),
                                           new FingerPose(new AllFingersContext(new[] { Finger.Thumb, Finger.Pinky }), FingerFlexion.Open),
                                           new FingerPose(new AllFingersContext(new[] { Finger.Middle, Finger.Index, Finger.Ring }), FingerFlexion.Folded));

            contextPose.Triggered += (s, arg) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_CONTEXTMENU));

            var backPose = new HandPose("BackPose", new PalmPose(new AnyHandContext(), PoseDirection.Backward, PoseDirection.Left),
                                        new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle, Finger.Ring, Finger.Pinky }), FingerFlexion.Open, PoseDirection.Left));

            backPose.Triggered += (s, arg) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_BACK));

            var leftPose = new HandPose("LeftPose", new PalmPose(new AnyHandContext(), PoseDirection.Backward, PoseDirection.Left),
                                        new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle }), FingerFlexion.OpenStretched, PoseDirection.Left),
                                        new FingerPose(new AllFingersContext(new[] { Finger.Ring, Finger.Pinky }), FingerFlexion.Folded));

            leftPose.Triggered += (s, arg) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_PREVIOUS));

            var leftStopPose = new HandPose("LeftStopPose", new PalmPose(new AnyHandContext()),
                                            new FingerPose(new AnyFingerContext(new[] { Finger.Index, Finger.Middle }), FingerFlexion.Folded));

            var rightPose = new HandPose("RightPose", new PalmPose(new AnyHandContext(), PoseDirection.Forward, PoseDirection.Right),
                                         new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle }), FingerFlexion.OpenStretched, PoseDirection.Right),
                                         new FingerPose(new AllFingersContext(new[] { Finger.Ring, Finger.Pinky }), FingerFlexion.Folded));

            rightPose.Triggered += (s, arg) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_NEXT));

            var rightStopPose = new HandPose("RightStopPose", new PalmPose(new AnyHandContext()),
                                             new FingerPose(new AnyFingerContext(new[] { Finger.Index, Finger.Middle }), FingerFlexion.Folded));

            var volumeUpPose = new HandPose("VolumeUpPose", new PalmPose(new AnyHandContext(), PoseDirection.Backward, PoseDirection.Up),
                                            new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle }), FingerFlexion.Open, PoseDirection.Up),
                                            new FingerPose(new AllFingersContext(new[] { Finger.Thumb, Finger.Ring, Finger.Pinky }), FingerFlexion.Folded));

            volumeUpPose.Triggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.VOLUME_UP));

            var volumeUpStop = new HandPose("VolumeUpStopPose", new PalmPose(new AnyHandContext()),
                                            new FingerPose(new AnyFingerContext(new[] { Finger.Index, Finger.Middle }), FingerFlexion.Folded));

            _volumeUpGesture = new Gesture("VolumeUpGesture", volumeUpPose, volumeUpStop);
            _volumeUpGesture.IdleTriggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.VOLUME_DONE));

            var volumeDownPose = new HandPose("VolumeDownPose", new PalmPose(new AnyHandContext(), PoseDirection.Backward, PoseDirection.Down),
                                              new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle }), FingerFlexion.Open, PoseDirection.Down),
                                              new FingerPose(new AllFingersContext(new[] { Finger.Thumb, Finger.Ring, Finger.Pinky }), FingerFlexion.Folded));

            volumeDownPose.Triggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.VOLUME_DOWN));

            var volumeDownStop = new HandPose("VolumeDownStopPose", new PalmPose(new AnyHandContext()),
                                              new FingerPose(new AnyFingerContext(new[] { Finger.Index, Finger.Middle }), FingerFlexion.Folded));

            _volumeDownGesture = new Gesture("VolumeDownGesture", volumeDownPose, volumeDownStop);
            _volumeDownGesture.IdleTriggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.VOLUME_DONE));

            var pinchPoseRewind  = GeneratePinchPose("PinchPoseRewind");
            var pinchPoseForward = GeneratePinchPose("PinchPoseForward");

            var rewindMotion = new HandMotion("RewindMotion", new PalmMotion(VerticalMotionSegment.Left));

            rewindMotion.Triggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.PLAYER_REWIND));

            var forwardMotion = new HandMotion("ForwardMotion", new PalmMotion(VerticalMotionSegment.Right));

            forwardMotion.Triggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.PLAYER_FORWARD));

            var keepRewindingPose  = GeneratePinchPose("KeepRewindPose");
            var keepForwardingPose = GeneratePinchPose("KeepForwardingPose");

            var releasePoseRewind  = GeneratePinchPose("ReleasePoseRewind", true);
            var releasePoseForward = GeneratePinchPose("ReleasePoseForward", true);

            _rewindGesture = new Gesture("RewindGesture", pinchPoseRewind, rewindMotion, keepRewindingPose, releasePoseRewind);
            _rewindGesture.IdleTriggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.PLAYER_SEEKDONE));

            _forwardGesture = new Gesture("ForwardGesture", pinchPoseForward, forwardMotion, keepForwardingPose, releasePoseForward);
            _forwardGesture.IdleTriggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.PLAYER_SEEKDONE));

            var downStartPose = new HandPose("DownStartPose", new PalmPose(new AnyHandContext(), PoseDirection.Up, PoseDirection.Forward),
                                             new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle, Finger.Ring, Finger.Pinky }), FingerFlexion.Open, PoseDirection.Forward),
                                             new FingerPose(Finger.Thumb, FingerFlexion.Open, PoseDirection.Right));

            var downClamPose = new HandPose("DownClamPose", new PalmPose(new AnyHandContext(), PoseDirection.Up, PoseDirection.Forward),
                                            new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle, Finger.Ring, Finger.Pinky }), FingerFlexion.Folded, PoseDirection.Backward)
                                            // new FingerPose(Finger.Thumb, FingerFlexion.Open, PoseDirection.Right));
                                            );

            var downStopPose = new HandPose("DownStopPose", new PalmPose(new AnyHandContext()),
                                            new FingerPose(new AnyFingerContext(new[] { Finger.Index, Finger.Middle, Finger.Ring, Finger.Pinky }), FingerFlexion.Open));

            downClamPose.Triggered     += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_DOWN));
            _downGesture                = new Gesture("DownGesture", downStartPose, downClamPose, downStopPose);
            _downGesture.IdleTriggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_SCROLLDONE));

            var upStartPose = new HandPose("UpStartPose", new PalmPose(new AnyHandContext(), PoseDirection.Down, PoseDirection.Forward),
                                           new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle, Finger.Ring, Finger.Pinky }), FingerFlexion.Open, PoseDirection.Forward),
                                           new FingerPose(Finger.Thumb, FingerFlexion.Open, PoseDirection.Left));

            var upClamPose = new HandPose("UpClamPose", new PalmPose(new AnyHandContext(), PoseDirection.Down, PoseDirection.Forward),
                                          new FingerPose(new AllFingersContext(new[] { Finger.Index, Finger.Middle, Finger.Ring, Finger.Pinky }), FingerFlexion.Folded, PoseDirection.Backward)
                                          // new FingerPose(Finger.Thumb, FingerFlexion.Open, PoseDirection.Left));
                                          );

            var upStopPose = new HandPose("UpStopPose", new PalmPose(new AnyHandContext()),
                                          new FingerPose(new AnyFingerContext(new[] { Finger.Index, Finger.Middle, Finger.Ring, Finger.Pinky }), FingerFlexion.Open));

            upClamPose.Triggered     += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_UP));
            _upGesture                = new Gesture("UpGesture", upStartPose, upClamPose, upStopPose);
            _upGesture.IdleTriggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_SCROLLDONE));

            _pauseGesture   = new Gesture("PauseGesture", pausePose, GenerateSpacerPose("PauseSpacer"));
            _selectGesture  = new Gesture("SelectGesture", selectPose, GenerateSpacerPose("SelectSpacer"));
            _menuGesture    = new Gesture("MenuGesture", menuPose, GenerateSpacerPose("MenuSpacer"));
            _contextGesture = new Gesture("ContextGesture", contextPose, GenerateSpacerPose("ContextSpacer"));
            _backGesture    = new Gesture("BackGesture", backPose, GenerateSpacerPose("BackSpacer"));
            _leftGesture    = new Gesture("LeftGesture", leftPose, leftStopPose);
            _rightGesture   = new Gesture("RightGesture", rightPose, rightStopPose);

            _leftGesture.IdleTriggered  += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_SCROLLDONE));
            _rightGesture.IdleTriggered += (s, args) => KinectActionRecognized?.Invoke(this, new KinectRecognizedActionEventArgs(KinectActionRecognizedSource.Gesture, GestureAction.INPUT_SCROLLDONE));

            // Step2: Connect to Gesture Service, route StatusChanged event to the UI and register the gesture
            _gesturesService = GesturesServiceEndpointFactory.Create();
            _gesturesService.StatusChanged += (oldStatus, newStatus) => GesturesDetectionStatusChanged?.Invoke(oldStatus, newStatus);
            await _gesturesService.ConnectAsync();

            await _gesturesService.RegisterGesture(_pauseGesture, true);

            await _gesturesService.RegisterGesture(_selectGesture, true);

            await _gesturesService.RegisterGesture(_rewindGesture, true);

            await _gesturesService.RegisterGesture(_forwardGesture, true);

            await _gesturesService.RegisterGesture(_menuGesture, true);

            await _gesturesService.RegisterGesture(_contextGesture, true);

            await _gesturesService.RegisterGesture(_backGesture, true);

            await _gesturesService.RegisterGesture(_downGesture, true);

            await _gesturesService.RegisterGesture(_upGesture, true);

            await _gesturesService.RegisterGesture(_leftGesture, true);

            await _gesturesService.RegisterGesture(_rightGesture, true);

            await _gesturesService.RegisterGesture(_volumeDownGesture, true);

            await _gesturesService.RegisterGesture(_volumeUpGesture, true);
        }
Example #14
0
 public void removeHandMotion(HandMotion handler)
 {
     movement -= handler;
 }
Example #15
0
 public void registerHandMotion(HandMotion handler)
 {
     movement += handler;
 }
    // Update is called once per frame
    void Update()
    {
        if (sw.pollSkeleton())
        {
            float currentTime = Time.time;
            this.rightHandPos = sw.bonePos[PlayerId, 11];
            this.leftHandPos  = sw.bonePos[PlayerId, 7];

            // get right hand velocity
            this.rightHandVelo = rightHandPos - rightHandPosPre;
            // get left hand velocity
            this.leftHandVelo = leftHandPos - leftHandPosPre;
            // right hand motion detection

            if (this.rightHandVelo.x > accuracy && Math.Abs(this.rightHandVelo.x) > Math.Abs(this.rightHandVelo.y))
            {
                if (currentRightHandMotion != HandMotion.RIGHT_HAND_WAVE_OUT)
                {
                    currentRightHandMotion   = HandMotion.RIGHT_HAND_WAVE_OUT;
                    motionRightHandStartTime = currentTime;
                    motionStartRightHandPos  = rightHandPos;
                }
            }
            else if (this.rightHandVelo.y > accuracy && Math.Abs(this.rightHandVelo.x) < Math.Abs(this.rightHandVelo.y))
            {
                if (currentRightHandMotion != HandMotion.RIGHT_HAND_RISE)
                {
                    currentRightHandMotion   = HandMotion.RIGHT_HAND_RISE;
                    motionRightHandStartTime = currentTime;
                    motionStartRightHandPos  = rightHandPos;
                }
            }
            else
            {
                currentRightHandMotion = HandMotion.NON;
            }

            // left hand motion detection
            if (this.leftHandVelo.x < -accuracy && Math.Abs(this.leftHandVelo.x) > Math.Abs(this.leftHandVelo.y))
            {
                if (currentLeftHandMotion != HandMotion.LEFT_HAND_WAVE_OUT)
                {
                    currentLeftHandMotion   = HandMotion.LEFT_HAND_WAVE_OUT;
                    motionLeftHandStartTime = currentTime;
                    motionStartLeftHandPos  = leftHandPos;
                }
            }
            else if (this.leftHandVelo.y > accuracy && Math.Abs(this.leftHandVelo.x) < Math.Abs(this.leftHandVelo.y))
            {
                if (currentLeftHandMotion != HandMotion.LEFT_HAND_RISE)
                {
                    currentLeftHandMotion   = HandMotion.LEFT_HAND_RISE;
                    motionLeftHandStartTime = currentTime;
                    motionStartLeftHandPos  = leftHandPos;
                }
            }
            else
            {
                currentLeftHandMotion = HandMotion.NON;
            }

            // validation of hand motion
            bool rightHandRiseValide = false;
            bool leftHandRiseValide  = false;


            if (currentRightHandMotion == HandMotion.RIGHT_HAND_WAVE_OUT &&
                currentTime - motionRightHandStartTime <= detectMotionDuration &&
                rightHandPos.x - motionStartRightHandPos.x >= detectMotionDistance)
            {
                // right hand wave out detected
                // rise motion detected event
                OnHandMotionDetected(HandMotion.RIGHT_HAND_WAVE_OUT);
                // reset timer for new detection
                motionRightHandStartTime = currentTime;
                motionStartRightHandPos  = rightHandPos;
            }
            else if (currentRightHandMotion == HandMotion.RIGHT_HAND_RISE &&
                     currentTime - motionRightHandStartTime <= detectMotionDuration &&
                     rightHandPos.y - motionStartRightHandPos.y >= detectMotionDistance)
            {
                rightHandRiseValide = true;
                OnHandMotionDetected(HandMotion.RIGHT_HAND_RISE);
            }
            // left
            if (currentLeftHandMotion == HandMotion.LEFT_HAND_WAVE_OUT &&
                currentTime - motionLeftHandStartTime <= detectMotionDuration &&
                motionStartLeftHandPos.x - leftHandPos.x >= detectMotionDistance)
            {
                // left hand wave out detected
                // rise motion detected event
                OnHandMotionDetected(HandMotion.LEFT_HAND_WAVE_OUT);
                // reset timer for new detection
                motionLeftHandStartTime = currentTime;
                motionStartLeftHandPos  = leftHandPos;
            }
            else if (currentLeftHandMotion == HandMotion.LEFT_HAND_RISE &&
                     currentTime - motionLeftHandStartTime <= detectMotionDuration &&
                     leftHandPos.y - motionStartLeftHandPos.y >= detectMotionDistance)
            {
                leftHandRiseValide = true;
                OnHandMotionDetected(HandMotion.LEFT_HAND_RISE);
            }
            // double hand
            if (rightHandRiseValide && leftHandRiseValide)
            {
                // double hands rise detected
                // rise motion detected event
                OnHandMotionDetected(HandMotion.TWO_HAND_RISE);
                motionRightHandStartTime = currentTime;
                motionLeftHandStartTime  = currentTime;
                motionStartRightHandPos  = rightHandPos;
                motionStartLeftHandPos   = leftHandPos;
            }

            rightHandPosPre = rightHandPos;
            leftHandPosPre  = leftHandPos;
        }
    }
	// Update is called once per frame
	void Update () {
		if(sw.pollSkeleton()){
			float currentTime = Time.time;
			// get right hand position (index = 11)
			this.rightHandPos = sw.bonePos[PlayerId,11];
			// get left hand position (index = 7)
			this.leftHandPos = sw.bonePos[PlayerId,7];
			// get spine position (index = 1)
			this.spinePos = sw.bonePos[PlayerId,1];
			// get head position (index = 3)
			this.headPos = sw.bonePos[PlayerId,3];
			// calculate the relative position of right hand
			this.rightHandRelativePos = this.rightHandPos - this.spinePos;
			float yHandRelativePos = this.rightHandPos.y - this.spinePos.y;
			float xHandRelativePos = this.rightHandPos.x - this.spinePos.x;
			/*
			Debug.Log("=======");
			Debug.Log("right hand: "+rightHandPos);
			Debug.Log("spine: "+spinePos);
			Debug.Log ("Relative pos:" + xHandRelativePos+"# "+yHandRelativePos);
			Debug.Log ("height: " + (headPos.y - spinePos.y));
			Debug.Log("=======");
			*/
			if(xHandRelativePos >= rightHandMarginX && yHandRelativePos <= 0.1){ // right hand position: down
				if(currentRightHandPos != RightHandPosition.DOWN){
					currentRightHandPos = RightHandPosition.DOWN;
					posStartTime = currentTime;
				}
			}
			else if(xHandRelativePos >= rightHandMarginX && yHandRelativePos > 0.2 && yHandRelativePos <=0.4){ // right hand position: mid
				if(currentRightHandPos != RightHandPosition.MID){
					currentRightHandPos = RightHandPosition.MID;
					posStartTime = currentTime;
				}
			}
			else if(xHandRelativePos >= rightHandMarginX && yHandRelativePos > 0.45){ // right hand position: up
				if(currentRightHandPos != RightHandPosition.UP){
					currentRightHandPos = RightHandPosition.UP;
					posStartTime = currentTime;
				}
			}
			else{
				currentRightHandPos = RightHandPosition.NON;
			}

			// validation of right hand position
			if(currentRightHandPos!=RightHandPosition.NON && currentTime - posStartTime >= detectPositionDuration){
				// rise right hand position detected event
				OnRightHandPositionDetected(currentRightHandPos);
				// reset the timer
				posStartTime = currentTime;
			}

			if(firstPos){
				firstPos = false;
			} else{
				// get right hand velocity
				this.rightHandVelo = rightHandPos - rightHandPosPre;
				// get left hand velocity
				this.leftHandVelo = leftHandPos - leftHandPosPre;
				// right hand motion detection
				if(this.rightHandVelo.x > accuracy && Math.Abs(this.rightHandVelo.x) > Math.Abs(this.rightHandVelo.y)){
					if(currentRightHandMotion != HandMotion.RIGHT_HAND_WAVE_OUT){
						currentRightHandMotion = HandMotion.RIGHT_HAND_WAVE_OUT;
						motionRightHandStartTime = currentTime;
						motionStartRightHandPos = rightHandPos;
					}
				}
				else if(this.rightHandVelo.y > accuracy && Math.Abs(this.rightHandVelo.x) < Math.Abs(this.rightHandVelo.y)){
					if(currentRightHandMotion != HandMotion.RIGHT_HAND_RISE){
						currentRightHandMotion = HandMotion.RIGHT_HAND_RISE;
						motionRightHandStartTime = currentTime;
						motionStartRightHandPos = rightHandPos;
					}
				}
				else{
					currentRightHandMotion = HandMotion.NON;
				}

				// left hand motion detection
				if(this.leftHandVelo.x < -accuracy && Math.Abs(this.leftHandVelo.x) > Math.Abs(this.leftHandVelo.y)){
					if(currentLeftHandMotion != HandMotion.LEFT_HAND_WAVE_OUT){
						currentLeftHandMotion = HandMotion.LEFT_HAND_WAVE_OUT;
						motionLeftHandStartTime = currentTime;
						motionStartLeftHandPos = leftHandPos;
					}
				}
				else if(this.leftHandVelo.y > accuracy && Math.Abs(this.leftHandVelo.x) < Math.Abs(this.leftHandVelo.y)){
					if(currentLeftHandMotion != HandMotion.LEFT_HAND_RISE){
						currentLeftHandMotion = HandMotion.LEFT_HAND_RISE;
						motionLeftHandStartTime = currentTime;
						motionStartLeftHandPos = leftHandPos;
					}
				}
				else{
					currentLeftHandMotion = HandMotion.NON;
				}

				// validation of hand motion
				bool rightHandRiseValide = false;
				bool leftHandRiseValide = false;
				// right
				if(currentRightHandMotion == HandMotion.RIGHT_HAND_WAVE_OUT 
				   && currentTime - motionRightHandStartTime <= detectMotionDuration
				   && rightHandPos.x - motionStartRightHandPos.x >= detectMotionDistance){
					// right hand wave out detected
					// rise motion detected event
					OnHandMotionDetected(HandMotion.RIGHT_HAND_WAVE_OUT);
					// reset timer for new detection
					motionRightHandStartTime = currentTime;
					motionStartRightHandPos = rightHandPos;
				}
				else if(currentRightHandMotion == HandMotion.RIGHT_HAND_RISE 
				        && currentTime - motionRightHandStartTime <= detectMotionDuration
				        && rightHandPos.y - motionStartRightHandPos.y >= detectMotionDistance){
					rightHandRiseValide = true;
				}
				// left
				if(currentLeftHandMotion == HandMotion.LEFT_HAND_WAVE_OUT 
				   && currentTime - motionLeftHandStartTime <= detectMotionDuration
				   && motionStartLeftHandPos.x - leftHandPos.x >= detectMotionDistance){
					// left hand wave out detected
					// rise motion detected event
					OnHandMotionDetected(HandMotion.LEFT_HAND_WAVE_OUT);
					// reset timer for new detection
					motionLeftHandStartTime = currentTime;
					motionStartLeftHandPos = leftHandPos;
				}
				else if(currentLeftHandMotion == HandMotion.LEFT_HAND_RISE 
				        && currentTime - motionLeftHandStartTime <= detectMotionDuration
				        && leftHandPos.y - motionStartLeftHandPos.y >= detectMotionDistance){
					leftHandRiseValide = true;
				}
				// double hand
				if(rightHandRiseValide&&leftHandRiseValide){
					// double hands rise detected
					// rise motion detected event
					OnHandMotionDetected(HandMotion.DOUBLE_HAND_RISE);
					motionRightHandStartTime = currentTime;
					motionLeftHandStartTime = currentTime;
					motionStartRightHandPos = rightHandPos;
					motionStartLeftHandPos = leftHandPos;
				}
			}
			rightHandPosPre = rightHandPos;
			leftHandPosPre = leftHandPos;
		}
	}