LEAPMotion VR 各种手势的判断~
来源:互联网 发布:中国老龄化数据 编辑:程序博客网 时间:2024/04/28 14:17
LEAPMotion VR 各种手势的判断~
Created by miccall (转载请注明出处)
1.手划向左边
protected bool isMoveLeft (Hand hand) // 手划向左边 { //x轴移动的速度 deltaVelocity = 0.7f isStationary (hand) 判断hand是否禁止 return hand.PalmVelocity.x < -deltaVelocity && !isStationary (hand); } [Tooltip ("Velocity (m/s) move toward ")] protected float deltaVelocity = 0.7f;
2.手划向右边
protected bool isMoveRight (Hand hand)// 手划向右边 { return hand.PalmVelocity.x > deltaVelocity && !isStationary (hand); } [Tooltip ("Velocity (m/s) move toward ")] protected float deltaVelocity = 0.7f;
3.手划向上边
protected bool isMoveUp (Hand hand) //手向上 { return hand.PalmVelocity.y > deltaVelocity && !isStationary (hand); }
4.手划向下边
protected bool isMoveDown (Hand hand) //手向下 { return hand.PalmVelocity.y < -deltaVelocity && !isStationary (hand); }
5.手固定不动
protected bool isStationary (Hand hand)// 固定不动的 { return hand.PalmVelocity.Magnitude < smallestVelocity; } [Tooltip ("Velocity (m/s) move toward ")] //速度(m/s)走向 protected float smallestVelocity = 0.4f;
6.是否抓取
protected bool isGrabHand (Hand hand) //是否抓取 { return hand.GrabStrength > 0.8f; //抓取力 }
7.是否握拳
protected bool isCloseHand (Hand hand) //是否握拳 { List<Finger> listOfFingers = hand.Fingers; int count = 0; for (int f = 0; f < listOfFingers.Count; f++) { //循环遍历所有的手~~ Finger finger = listOfFingers [f]; if ((finger.TipPosition - hand.PalmPosition).Magnitude < deltaCloseFinger) // Magnitude 向量的长度 。是(x*x+y*y+z*z)的平方根。 //float deltaCloseFinger = 0.05f; { count++; //if (finger.Type == Finger.FingerType.TYPE_THUMB) //Debug.Log ((finger.TipPosition - hand.PalmPosition).Magnitude); } } return (count == 5); }
8.手掌是否全张开
protected bool isOpenFullHand (Hand hand) //手掌全展开~ { //Debug.Log (hand.GrabStrength + " " + hand.PalmVelocity + " " + hand.PalmVelocity.Magnitude); return hand.GrabStrength == 0; }
9.向量的判断
(1)向量转化成 角度
protected float angle2LeapVectors (Leap.Vector a, Leap.Vector b){ //向量转化成 角度 return Vector3.Angle (UnityVectorExtension.ToVector3 (a), UnityVectorExtension.ToVector3 (b));}
(2)判断两个向量是否 相同 方向
protected bool isSameDirection (Vector a, Vector b){ //判断两个向量是否 相同 方向 //Debug.Log (angle2LeapVectors (a, b) + " " + b); return angle2LeapVectors (a, b) < handForwardDegree;}
(3)判断两个向量是否 相反 方向
protected bool isOppositeDirection (Vector a, Vector b {//判断两个向量是否 相反 方向 return angle2LeapVectors (a, b) > (180 - handForwardDegree);}
(4)判断手的掌心方向于一个 向量 是否方向相同
protected bool isPalmNormalSameDirectionWith (Hand hand, Vector3 dir){ //判断手的掌心方向于一个 向量 是否方向相同 return isSameDirection (hand.PalmNormal, UnityVectorExtension.ToVector (dir));} [Tooltip ("Delta degree to check 2 vectors same direction")] //三角度检查2个向量的方向相同 protected float handForwardDegree = 30;
10.向手掌的方向 移动
protected bool isHandMoveForward (Hand hand) { return isSameDirection (hand.PalmNormal, hand.PalmVelocity) && !isStationary (hand); }
11.手掌是否垂直(掌心水平)
protected bool checkPalmNormalInXZPlane (Hand hand) // hand.PalmNormal 垂直于掌心的向量 { float anglePalmNormal = angle2LeapVectors (hand.PalmNormal, UnityVectorExtension.ToVector (Vector3.up)); return (anglePalmNormal > 70 && anglePalmNormal < 110); }
12.判断大拇指是否竖直或向下
protected bool isThumbDirection (Hand hand, Vector3 dir) { List<Finger> listOfFingers = hand.Fingers; for (int f = 0; f < listOfFingers.Count; f++) { Finger finger = listOfFingers [f]; if (finger.Type == Finger.FingerType.TYPE_THUMB) { float angleThumbFinger = angle2LeapVectors (finger.Direction, UnityVectorExtension.ToVector (dir)); float angleThumbFinger2 = angle2LeapVectors ( finger.StabilizedTipPosition - hand.PalmPosition, UnityVectorExtension.ToVector (dir)); //Debug.Log (angleThumbFinger + " " + angleThumbFinger2); if (angleThumbFinger < deltaAngleThumb || angleThumbFinger2 < deltaAngleThumb) return true; else return false; } } return false; }
13.判断四指是否靠拢掌心
protected bool checkFingerCloseToHand (Hand hand){ List<Finger> listOfFingers = hand.Fingers; int count = 0; for (int f = 0; f < listOfFingers.Count; f++) { Finger finger = listOfFingers [f]; if ((finger.TipPosition - hand.PalmPosition).Magnitude < deltaCloseFinger) { if (finger.Type == Finger.FingerType.TYPE_THUMB) { return false; } else { count++; } } } //Debug.Log (count); return (count == 4);}
0 0
- LEAPMotion VR 各种手势的判断~
- UIGestureRecognizer 各种手势的判断
- LeapMotion VR开发
- Gesture手势-------LeapMotion API
- LEAPMotion猎户座(VR)开发~001~
- LEAPMotion猎户座(VR)开发~002~
- LEAPMotion猎户座(VR)开发~003~UI
- UIGestureRecognizer手势的判断
- 简单的手势判断
- UISwipeGestureRecognizer各种手势的用法
- IOS各种手势的使用
- Leapmotion的一个错误
- 应用于VR/AR的主流光学手势识别技术解析
- LeapMotion
- android GestureDetector 手势的判断
- android GestureDetector 手势的判断
- UIGestureRecognizer 真的很好用: 各种手势,
- ios中上下左右滑动的各种手势
- 【区块链之技术实战】区块链开源项目合集:Hello,BlockChain!
- nginx 配置 google代理
- MySQL2
- 负环图检测
- 大闹天竺、西游伏妖篇、免费电影资源
- LEAPMotion VR 各种手势的判断~
- 如何来实现一个Linux内核的系统调用(基于tiny4412开发板)
- npm 常用命令详解 [此文来自转载]
- 通过XMLHttpRequest对象实现Ajax跳转
- SharedSDK(四):sharedSdK集成、分享、第三方登录(项目中进行相关配置x下列)
- PAT甲级1102
- 新手初到借地,请海涵。
- 优雅的实现多类型列表的Adapter
- python技巧(3)