Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using Leap.Unity;
- using Leap;
- [RequireComponent (typeof (AudioSource))]
- /// <summary>
- /// Hand recognition.
- /// http://blog.leapmotion.com/getting-started-leap-motion-sdk/
- /// </summary>
- public class HandRecognition : MonoBehaviour
- {
- //Manos
- public RigidHand leftHand;
- public RigidHand rightHand;
- //Vectores dedos Mano Izquierda
- public Vector3 indexIntBoneRotL;
- public Vector3 middleIntBoneRotL;
- public Vector3 ringIntBoneRotL;
- public Vector3 pinkyIntBoneRotL;
- public Vector3 thumbIntBoneRotL;
- //Vectores dedos Mano Derecha
- //public Vector3 indexIntBoneRotR;
- //public Vector3 middleIntBoneRotR;
- //public Vector3 ringIntBoneRotR;
- //public Vector3 pinkyIntBoneRotR;
- //public Vector3 thumbIntBoneRotR;
- //Vectores posición manos Derecha/izq
- public Vector3 LeftHandPosition;
- //public Vector3 RightHandPosition;
- //Init Variables
- public float thresholdGesture = 90f;
- //Screen en el que se proyectan los videos
- public MovieTexture movieGesture1;
- public Transform Screen;
- void Start() //Función para inicializar
- {
- //Se inicializan todas las matrices en cero para corrección de posibles errores al arranque
- indexIntBoneRotL = Vector3.zero;
- middleIntBoneRotL = Vector3.zero;
- ringIntBoneRotL = Vector3.zero;
- pinkyIntBoneRotL = Vector3.zero;
- thumbIntBoneRotL = Vector3.zero;
- //indexIntBoneRotR = Vector3.zero;
- //middleIntBoneRotR = Vector3.zero;
- //ringIntBoneRotR = Vector3.zero;
- //pinkyIntBoneRotR = Vector3.zero;
- //thumbIntBoneRotR = Vector3.zero;
- //LeftHandPosition = Vector3.zero;
- //RightHandPosition = Vector3.zero;
- Screen.GetComponent<Renderer>().material.mainTexture = movieGesture1;
- ((MovieTexture)Screen.GetComponent<Renderer>().material.mainTexture).Play();
- }
- /*
- *
- * TYPE_THUMB = = 0 -
- * TYPE_INDEX = = 1 -
- * TYPE_MIDDLE = = 2 -
- * TYPE_RING = = 3 -
- * TYPE_PINKY = = 4 -
- *
- *
- *
- */
- void Update() // Update se llama una vez por frame
- {
- //Llenar los vectores de los dedos con los grados de separación entre falange media y proximal
- indexIntBoneRotL = leftHand.fingers[1].GetBoneRotation(2).eulerAngles;
- middleIntBoneRotL = leftHand.fingers[2].GetBoneRotation(2).eulerAngles;
- ringIntBoneRotL = leftHand.fingers[3].GetBoneRotation(2).eulerAngles;
- pinkyIntBoneRotL = leftHand.fingers[4].GetBoneRotation(2).eulerAngles;
- thumbIntBoneRotL = leftHand.fingers[0].GetBoneRotation(2).eulerAngles;
- //indexIntBoneRotR = rightHand.fingers[1].GetBoneRotation(2).eulerAngles;
- //middleIntBoneRotR = rightHand.fingers[2].GetBoneRotation(2).eulerAngles;
- //ringIntBoneRotR = rightHand.fingers[3].GetBoneRotation(2).eulerAngles;
- //pinkyIntBoneRotR = rightHand.fingers[4].GetBoneRotation(2).eulerAngles;
- //thumbIntBoneRotR = rightHand.fingers[0].GetBoneRotation(2).eulerAngles;
- // indexIntBonePy = leftHand.palm.localPosition;
- //Número que determina qué gesto fue aplicado. Con este se selecciona el video que se reproducirá en el screen
- int gestureId = GestureRecognized();
- if (gestureId == 1) //Acicalar de lado a lado. Dado por posición de la muñeca en x [-0.1, 0.1]
- {
- /*
- Debug.Log ("Gesto 1 reconocido!");
- Debug.Log(indexIntBonePy);
- Screen.GetComponent<Renderer> ().material.mainTexture = movieGesture1;
- ((MovieTexture)Screen.GetComponent<Renderer> ().material.mainTexture).Play();
- Gato has muecas
- print
- */
- }
- if (gestureId == 2) //Rascar mentón. Dado por palma hacia arriba y dedos 'rascando'
- {
- Debug.Log("Gesto 2 reconocido! Consintiendo mentón");
- Debug.Log(leftHand.GetPalmNormal().y);
- // play video 2
- }
- if (gestureId == 3) //Rascar cabeza. Dado por palma hacia abajo y dedos 'rascando'
- {
- Debug.Log("Gesto 3 reconocido! Consintiendo cabeza");
- Debug.Log(leftHand.GetPalmNormal().y);
- //
- }
- if (gestureId == 4) //Dar pata. Dado por mano de lado.
- {
- Debug.Log("Gesto 4 reconocido! Dar Pata");
- Debug.Log(leftHand.GetPalmNormal().y);
- //
- }
- if (gestureId == -1)//Posición de reposo. Dado por inexistencia de gestos en cercanías a cámara
- {
- Debug.Log("Nada :v");
- //
- }
- }
- int GestureRecognized()
- {
- if (indexIntBoneRotL.x == 190)
- {
- return 1;
- }
- else if (leftHand.GetPalmNormal().y >= 0.6) //mentón
- {
- return 2;
- }
- else if (leftHand.GetPalmNormal().y <= -0.6) //cabeza
- {
- return 3;
- }
- else if (leftHand.GetPalmNormal().y < 0.6 && leftHand.GetPalmNormal().y > -0.6) //pata
- {
- return 4;
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement