手势交互

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;

    }

 

}
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rick__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值