Browse Source

add haptic feedback

Kenkart 2 years ago
parent
commit
e716d6f218
2 changed files with 13 additions and 7 deletions
  1. 12 2
      Assets/KinectView/Scripts/BodySourceView.cs
  2. 1 5
      Assets/Scripts/TriggerDetector.cs

+ 12 - 2
Assets/KinectView/Scripts/BodySourceView.cs

@@ -1,6 +1,7 @@
 using System.Collections.Generic;
 using UnityEngine;
 using Kinect = Windows.Kinect;
+using Valve.VR;
 
 public class BodySourceView : MonoBehaviour
 {
@@ -191,10 +192,19 @@ public class BodySourceView : MonoBehaviour
                 jointObj.GetComponent<Renderer>().enabled = false;
             }
 
-            // WristLeft and WristRight change to red color if not following the motions
+            // WristLeft and WristRight do something if not following the motions
             if ((jt == Kinect.JointType.WristLeft && wristLeftLate) || (jt == Kinect.JointType.WristRight && wristRightLate))
             {
-                jointObj.GetComponent<Renderer>().material.color = new Color(1, 0, 0);
+                if (modeController.feedback == ModeController.Feedback.ColorFeedback)
+                {
+                    // Change to red color
+                    jointObj.GetComponent<Renderer>().material.color = new Color(1, 0, 0);
+                } else if (modeController.feedback == ModeController.Feedback.HapticFeedback)
+                {
+                    // TODO: Add haptic feedback need to test
+                    SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.LeftHand].Execute(0, 1, 10, 1);
+                    SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.RightHand].Execute(0, 1, 10, 1);
+                }
             }
 
             LineRenderer lr = jointObj.GetComponent<LineRenderer>();

+ 1 - 5
Assets/Scripts/TriggerDetector.cs

@@ -10,17 +10,13 @@ public class TriggerDetector : MonoBehaviour
     {
         if (other.CompareTag("WristLeft"))
         {
-            Debug.Log("WristLeft triggered");
             other.GetComponent<Renderer>().material.color = new Color(1, 1, 1);
             BodySourceView bsv = other.GetComponentInParent<BodySourceView>();
             bsv.wristLeftLate = false;
             Visualizer_FadeIn vfi = GetComponentInParent<Visualizer_FadeIn>();
             vfi.wristLeftTriggered = true;
-        }
-
-        if (other.CompareTag("WristRight"))
+        } else if (other.CompareTag("WristRight"))
         {
-            Debug.Log("WristRight triggered");
             other.GetComponent<Renderer>().material.color = new Color(1, 1, 1);
             BodySourceView bsv = other.GetComponentInParent<BodySourceView>();
             bsv.wristRightLate = false;