终于到了要应用的时候了,我们可以摆放一些3D物体让我们的物体丰富起来,这也是做项目的初衷。
具体做法也比较简单,可以控制是那一个指头碰到的。达到这种程度也就没有什么可以说的了。足够用了!
Leap Motion 的具体用法
- LeapMotion 用法一:
如何抓取一个物体?
public class MyFinger : MonoBehaviour {
LeapProvider pro;
public LeapTransform t;
void Start () {
pro = FindObjectOfType<LeapProvider> () as LeapProvider;
}
void Update () {
Frame frame = pro.CurrentFrame;
foreach (Hand hand in frame.Hands) {
if (hand.IsLeft) {
if ( Vector3.Distance (this.transform.position, hand.PalmPosition.ToVector3 ()) < 1f) {
transform.position = hand.PalmPosition.ToVector3 () + hand.PalmNormal.ToVector3 () * (transform.localScale.y * .5f + .02f);
transform.rotation = hand.Basis.CalculateRotation ();
}
}
}
}
}
```
- LeapMotion 用法二:
hand.grabAngle()返回的是除却大拇指四根手指的平均弯曲程度,所以紧握拳头的时候数值为3.14
public class MyPinch : MonoBehaviour {
public float minDistance;
public float maxdistance;
public float pinchStart;
public float pinchToEnd;
public HandModel m_hand;
public GameObject m_cube;
private bool m_isPinching = false;
void Start () {
m_hand = GetComponent<HandModel> ();
}
void Update () {
Vector3 indexPosition = m_hand.fingers [1].GetBoneCenter (3);
Vector3 thumbPosition = m_hand.fingers [0].GetBoneCenter (3);
float distance = (indexPosition - thumbPosition).magnitude;
float nomalizedDistance = (distance - minDistance) / (maxdistance - minDistance);
float pinch = 1.0f - Mathf.Clamp01 (nomalizedDistance);
Debug.Log ("Current pinch strength" + pinch);
Debug.Log ("pinch" + m_hand.GetLeapHand ().PinchStrength);
if (pinch > pinchStart) {
m_isPinching = true;
} else if (pinch< pinchToEnd){
m_isPinching = false;
}
}
}