leapmotion c语言开发,互动开发-(三)Leap Motion的上手使用

终于到了要应用的时候了,我们可以摆放一些3D物体让我们的物体丰富起来,这也是做项目的初衷。

aae661ba135d

修改触碰到方块的颜色

具体做法也比较简单,可以控制是那一个指头碰到的。达到这种程度也就没有什么可以说的了。足够用了!

Leap Motion 的具体用法

LeapMotion 用法一:

如何抓取一个物体?

public class MyFinger : MonoBehaviour {

LeapProvider pro;

public LeapTransform t;

void Start () {

pro = FindObjectOfType () 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 ();

}

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;

}

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值