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的官網。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM