using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Leap;
using Leap.Unity;
public class HandCtLManeger : MonoBehaviour
{
private LeapProvider mProvider;
private Frame mFrame;
private Hand LeftHand;
private Hand RightHand;
private Hand hand;
public float average;
public float leftAverage;
public float rightAverage;
public static HandCtLManeger instance;
public bool isPlayer = false;
public bool VideoPlay = false;
public bool isCaShi = false;
public bool isOk = false;
public bool isShenShou = false;
public bool isYes = false;
public bool isHeart = false;
public bool isHug = false;
public bool isQuanTou = false;
public bool isBye = false;
void Awake ()
{
instance = this;
}
// Use this for initialization
void Start ()
{
mProvider = FindObjectOfType<LeapProvider> () as LeapProvider;
}
void Update ()
{
handCtl ();
}
private void handCtl ()
{
//获取当前帧//获得手的个数
mFrame = mProvider.CurrentFrame;
Debug.Log (mFrame.Hands.Count);
if (mFrame.Hands.Count == 0) {
isPlayer = false;
} else {
isPlayer = true;
}
if (mFrame.Hands.Count == 2) {
List<Hand> handList = mFrame.Hands;
LeftHand = handList [0];
RightHand = handList [1];
leftAverage = (float)Mathf.Round (LeftHand.GrabAngle * 100) / 100;
rightAverage = (float)Mathf.Round (RightHand.GrabAngle * 100) / 100;
Finger a = LeftHand.GetThumb ();
Finger b = RightHand.GetThumb ();
// print ((a.TipPosition - b.TipPosition).Magnitude);
if (leftAverage < 1f && rightAverage < 1f && isShuangBu (LeftHand, RightHand) == true) {
print ("开始播放");
VideoPlay = true;
}
if (leftAverage > 2f && rightAverage > 2f) {
if ((a.TipPosition - b.TipPosition).Magnitude < 0.05f) {
Debug.Log ("双手笔心");
isHeart = true;
}
}
if (leftAverage < 1.5f && rightAverage < 1.7f) {
if ((a.TipPosition - b.TipPosition).Magnitude > 0.6f) {
Debug.Log ("张开双臂");
isHug = true;
}
}
if (Mathf.Abs (LeftHand.PalmVelocity.x) > 0.5f
&& Mathf.Abs (RightHand.PalmVelocity.x) > 0.5f) {
print ("双手挥舞拜拜");
isBye = true;
}
if (leftAverage == 3.14f && rightAverage == 3.14f) {
Debug.Log ("握拳");
isQuanTou = true;
}
} else if (mFrame.Hands.Count == 1) {
//检测握拳
foreach (Hand hand in mFrame.Hands) {
average = (float)Mathf.Round (hand.GrabAngle * 100) / 100;
}
// if (average == 3.14f) {
// Debug.Log ("握拳");
// isQuanTou = true;
// }
List<Hand> handList = mFrame.Hands;
Hand singleHand = handList [0];
Finger a = singleHand.GetThumb ();
if (a.TipPosition.z > 0.5f) {
Debug.Log ("伸手");
isShenShou = true;
}
List<Finger> fingerList = singleHand.Fingers;
Finger shizhifinger = fingerList [1];
Finger zhongzhifinger = fingerList [2];
if (average > 1.4f && average < 2.1f && Ye (shizhifinger, zhongzhifinger, singleHand)) {
Debug.Log ("比耶");
isYes = true;
}
if (shizhifinger.Direction.AngleTo (singleHand.Direction) > 1.5f) {
print ("OK");
isOk = true;
}
//singleHand.PalmVelocity 挥动速率
if (Mathf.Abs (singleHand.PalmVelocity.x + singleHand.PalmVelocity.z + singleHand.PalmVelocity.z) > 2f) {
print ("擦拭");
isCaShi = true;
}
} else {
}
}
private void spriteAnimatior ()
{
}
private bool isShuangBu (Hand leftHand, Hand rightHand)
{
Finger a = leftHand.GetThumb ();
Finger b = rightHand.GetThumb ();
if ((a.TipPosition - b.TipPosition).Magnitude < 0.5f && (a.TipPosition - b.TipPosition).Magnitude > 0.15f) {
return true;
}
return false;
}
private bool Ye (Finger shizhi, Finger zhongzhi, Hand hand)
{
float a = shizhi.Direction.AngleTo (hand.Direction);
float b = zhongzhi.Direction.AngleTo (hand.Direction);
if (a < 1.2f && b < 1.2f) {
return true;
}
return false;
}
}