Advertisement
moinularif

KinectInput

Jun 24th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class KinectInput : MonoBehaviour {
  5.  
  6.     public static Vector3 leftWristPosition;
  7.     public static Vector3 rightWristPosition;
  8.  
  9.     public float turnValue;
  10.     public int coeffecientValue;
  11.     public float deltaZMax = 0.35f;
  12.  
  13.     // Use this for initialization
  14.     void Start () {
  15.  
  16.         turnValue = 0;
  17.         coeffecientValue = 0;
  18.    
  19.     }
  20.    
  21.     // Update is called once per frame
  22.     void Update () {
  23.  
  24.        
  25.         // this debug is only for testing purpose
  26.         Debug.Log(GetTurnValue());
  27.    
  28.     }
  29.  
  30.     public float GetTurnValue()
  31.     {
  32.  
  33.  
  34.        // Debug.Log(" LeftWrist Value: " + leftWristPosition.z);
  35.         //Debug.Log("RightWrist Value:" + rightWristPosition.z);
  36.  
  37.        
  38.  
  39.         if (rightWristPosition.z > leftWristPosition.z)
  40.         {
  41.              Debug.Log("right turn...");
  42.             coeffecientValue = 1;
  43.         }
  44.         else if (rightWristPosition.z < leftWristPosition.z)
  45.         {
  46.              Debug.Log("left turn...");
  47.             coeffecientValue = -1;
  48.         }
  49.         else
  50.         {
  51.             Debug.Log("No input .....");
  52.             coeffecientValue = 0;
  53.         }
  54.  
  55.         float deltaZ = Mathf.Abs(leftWristPosition.z - rightWristPosition.z);
  56.  
  57.        turnValue = deltaZ / deltaZMax;
  58.  
  59.         if(turnValue < 0.04f)
  60.         {
  61.  
  62.             return 0;
  63.         }
  64.  
  65.         else if (turnValue >= 1.0f)
  66.         {
  67.             return 1 * coeffecientValue;
  68.         }
  69.  
  70.         else
  71.         {
  72.             return turnValue * coeffecientValue;
  73.         }
  74.  
  75.        // Debug.Log("TempTurnValue: " + tempTurnValue);
  76.        
  77.        
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement