leapmotion c语言开发,互动开发-(四)LeapMotion-Unity主要类

命名空间

One : Leap.Unity

using Leap.Unity

命名空间下的类,一般在Unity中要引用它才能与物体进行交互,获取跟踪数据。

** LeapServiceProvider**

访问跟踪(手势轨迹)数据,听说还转换右手>左手坐标系

** LeapHandController**

负责管理手的控制器,并处理与游戏对象的交互。

Two : Leap

using Leap

Leap空间中的类定义了LeapMotion所追踪的具体内容。

Frame

某个时间点的数据集合,包含(hand)手对象.

可以通过

pro = FindObjectOfType () as LeapProvider;

Frame frame = pro.CurrentFrame;

或者

public LeapServiceProvider spro;

spro = FindObjectOfType ();

Frame f = spro.CurrentFrame;

foreach (Hand hand in f.Hands) {

// 如果是左手

if (hand.IsRight) {

// 如果物体的距离与左手的距离小于1F

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 ();

}

}

Arm

胳膊而已,用处不大,不过可以在特定位置进行相关的开发。例如将角色动画的胳膊给它赋值。做一个游戏中的提线布偶

Frame frame = pro.CurrentFrame;

foreach (Hand h in frame.Hands) {

if (h.Arm != null) {

transform.rotation = h.Arm.Rotation.ToQuaternion();

}

Hand

一个Hand手对象表示了一个手,一个手包含5根手指

// 手的方向

Debug.Log ("1:"+h.Direction.ToVector3 ());

// 手掌的位置

Debug.Log ("2:" + h.PalmPosition.ToVector3 ());

// 拿到的是Leap的transform

Debug.Log ("3:" +h.Basis.rotation);

Finger

Finger手指对象表示了追踪的手指。手指包含四块骨头。

// 获取手指个数

Debug.Log (h.Fingers.Count);

foreach (Finger i in h.Fingers) {

Debug.Log (i.Type);

if (i.Type == Finger.FingerType.TYPE_INDEX) {

Debug.Log ("食指");

}

if (i.Type == Finger.FingerType.TYPE_THUMB) {

Debug.Log ("拇指");

}

if (i.Type == Finger.FingerType.TYPE_MIDDLE) {

Debug.Log ("中指");

}

if (i.Type == Finger.FingerType.TYPE_PINKY) {

Debug.Log ("小拇指");

}

if (i.Type == Finger.FingerType.TYPE_RING) {

Debug.Log ("无名指");

}

if (i.Type == Finger.FingerType.TYPE_UNKNOWN) {

Debug.Log ("六指");

}

}

Bone

Bone骨头对象表示手指的一段,并包含位置、大小和方位数据。

if (i.Type == Finger.FingerType.TYPE_MIDDLE) {

Debug.Log ("中指");

Debug.Log("中指有多少截" + i.bones.Length);

}

Debug.Log (h.Fingers.Count);

foreach (Finger i in h.Fingers) {

Debug.Log (i.Type);

if (i.Type == Finger.FingerType.TYPE_INDEX) {

//Debug.Log ("食指");

Debug.Log ("食指有多少截" + i.bones.Length);

//Debug.Log ("位置" + i.bones [0].Type);

foreach (Bone ss in i.bones) {

Debug.Log (ss);

if (ss.Type == Bone.BoneType.TYPE_DISTAL) {

Debug.Log ("DISTAL");

//Debug.Log (ss.Direction.ToVector3 ());

// 通过测试这是用来查看当前手指骨骼的角度(偏航角)

Debug.Log (ss.Direction.Yaw);

Debug.Log (" X:" +ss.Direction.x);

}

}

}

最后说一下,我们在通过上面的代码可以知道,leap中的坐标都需要转一下:

Vector3 v = leapVector.ToVector3();

Quaternion q = leapMatrix.Rotation();

Vector3 t = leapMatrix.origin.ToVector3();

Vector3 scale = new Vector3(leapMatrix.xBasis.Magnitude,

leapMatrix.yBasis.Magnitude,

leapMatrix.zBasis.Magnitude);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值