LeapMotion使用入门

转 https://blog.csdn.net/moonlightpeng/article/details/80174509

先把资料转下来,明天考完试好好研究

1,Leap Motion 之 准备工作。

a, 官方文档链接, 手势对应类的结构数据。

https://leapmotion.github.io/UnityModules/ 

这儿对leap手势的所有官方资料,非常不错。

https://leapmotion.github.io/UnityModules

b, Interaction-Engine.

c, Getting Started (Interaction Engine)

2,每次在unity中使用时先一定要把leap motion control panel打开。

2 获得手的相关信息

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Leap;
using Leap.Unity;

public class LeapGestures : MonoBehaviour {

private LeapProvider mProvider;
private Frame mFrame;
private Hand mHand;

[Tooltip ("Velocity (m/s) of Palm ")]
public float smallestVelocity = 0.4f;//手掌移动的最小速度
[Tooltip ("Velocity (m/s) of Single Direction ")]
public float deltaVelocity = 0.8f;//单方向上手掌移动的速度
[Tooltip ("Distance(m) of Fingertip to Palm")]
public float deltaCloseFinger = 0.5f;//指尖到手掌中心的距离阈值


// Use this for initialization
void Start () {
mProvider = FindObjectOfType<LeapProvider>() as LeapProvider;

}

// Update is called once per frame
void Update () {
mFrame = mProvider.CurrentFrame;//获取当前帧
//获得手的个数
//print ("hand num are " + mFrame.Hands.Count);

if (mFrame.Hands.Count > 0) {

foreach (var item in mFrame.Hands) {
int numFinger = item.Fingers.Count;
print ("item is " + numFinger);


}
}

}
}

 
mFrame = mProvider.CurrentFrame;//获取当前帧
//获得手的个数
//print ("hand num are " + mFrame.Hands.Count);

if (mFrame.Hands.Count > 0) {

foreach (var item in mFrame.Hands) {
int numFinger = item.Fingers.Count;
//print ("item is " + numFinger);

//print("hand are " + isOpenFullHand (item));

if (item.IsLeft) {

//print ("isOpenFullHands is " + isOpenFullHands(item));
print ("isOpenFullHand is " + isOpenFullHand(item));
}

}
}
 

//判断有多少个手指是伸开的,以及伸开的手指是哪个
public int extendFingerNum(Hand hand)
{
int extendedFingers = 0;
//一个手指的一次遍历
for (int f = 0; f < hand.Fingers.Count; f++)
{
Finger digit = hand.Fingers[f];
if (digit.IsExtended) {
print ("Fingers is " + digit);
extendedFingers++;
}
}
return extendedFingers;
}
 

3,其它函数

hand.GrabStrength

通过握拳晃动时,它的Strength值大多数情况下在0.8-0.9范围内。通过该事件响应操作便会不精确。通常情况下,我们只需要两种状态: 

握拳事件Strength值为:1;非握拳状态的值为:0。 

GrabStrength float ⼿的姿势判断,⼿全张开状态为0,握拳时为1,范围是[0,1]
GrabAngle float
所有⼿指的弯曲程度。通过观察四个⼿指的⽅向和⼿的⽅向
之间的夹⻆来计算这个⻆。当计算⻆度时,不考虑拇指。这
个⻆度是⼀个开着的⼿的0弧度,当这个姿势是⼀个紧的拳
头时,它就会到达pi弧度。
PinchStrength float “捏”的⼒度,⼿掌摊开时为0,最⼤为1;针对拇指与同⼀只
⼿的任意其他⼿指的组合
PinchDistance float 拇指和⻝指的距离,⽤来判断“捏”这个操作。
Rotation Vector3 返回⼿掌旋转的四元数
IsLeft bool 判断是否是左⼿
TimeVisible float 返回⼿在controller中可⻅的持续时间
Fingers List<Finger> ⼿指列表,从拇指到⽆名指排列
PalmNormal Vector3 ⼿掌法向量,如果你的⼿是平的,这个⽮量会向下,或者是你⼿掌的前表⾯。你可以⽤⼿掌法向量来计算⽔平⾯上的⼿掌的滚动⻆度。
PalmPosition Vector3 ⼿掌中⼼在controller坐标系中的位置(mm级)
PalmVelocity Vector3 ⼿掌位置的速度,mm/s
PalmWidth float ⼿掌在平的位置时,⼿掌的估计宽度。
WristPosition 返回⼿腕的位置
 

4 Unity3D使用左手坐标系统,而Leap Motion API使用右手坐标系统。(基本上,在相反的方向。Z轴点)统一使用米的默认单位,而Leap Motion API使用毫米。插件脚本内部转换跟踪数据使用左手坐标系和尺度距离值米。

5, this.cube.transform.rotation = Quaternion.EulerRotation(h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll); 

6, Unity集成Leap Motion

7, Leap Motion这三个实验,告诉你手势还能实现这些操作

对应的英文官方文档 (Summoning and Superpowers: Designing VR Interactions at a Distance)

8,LEAPMotion VR 各种手势的判断。

9,官网的例子https://gallery.leapmotion.com/

10, unity 下载leap的官网。

原文地址:https://www.cnblogs.com/HIT-ryp/p/11098564.html