2

尝试使用 Controller.EnableGesture 启用任何/所有手势,尝试从当前帧 > 手势(0)或新的 CircleGesture(或任何其他类型)获取。总是得到无效的手势......这是代码,我正在使用他们的 Unity 示例中的 LeapInput 静态类(它所做的只是保存控制器并更新当前帧)。

 void Update()
    {
        LeapInput.Update();
        Frame thisFrame = LeapInput.Frame;
        for (int i = 0; i < thisFrame.Gestures().Count; i++)
            {
                Gesture gesture = thisFrame.Gesture(i);
            }
    }

Ps 是的,我在同一个控制器实例中启用手势。

4

2 回答 2

1

你有最新的驱动程序吗?(截至本文为 1.0.7+7648)这是您在我的处理程序类中的代码,它可以很好地返回圆圈手势:

更新代码(工作)

我没有注意 OP 的原始代码。.gestures(0)不起作用,只需更改为.gestures[0],请参见下面的示例。

using UnityEngine;
using System.Collections;
using Leap;

public class LeapTest : Leap.Listener {
    public Leap.Controller Controller;

    // Use this for initialization
    public void Start () {
        Controller = new Leap.Controller(this);
        Debug.Log("Leap start");
    }

    public override void OnConnect(Controller controller){
        Debug.Log("Leap Connected");
        controller.EnableGesture(Gesture.GestureType.TYPECIRCLE,true);
    }

    public override void OnFrame(Controller controller)
    {
        Frame frame = controller.Frame();
        GestureList gestures = frame.Gestures();
        for (int i = 0; i < gestures.Count; i++)
        {
            Gesture gesture = gestures[0];
            switch(gesture.Type){
                case Gesture.GestureType.TYPECIRCLE:
                    Debug.Log("Circle");
                    break;
                default:
                    Debug.Log("Bad gesture type");
                    break;
            }
        }
    }
}
于 2013-08-17T22:04:57.563 回答
0

我也将添加一个答案,因为我遇到了困难。看起来你解决了你的特定问题,但我的有点不同。我在 Gestures 数组中根本没有收到任何数据。

我发现除了启用手势之外,我还必须回顾帧历史,看看事后是否有任何手势附加到旧帧。换句话说,controller.Frame()不一定有任何与之关联的手势数据,而是跳过帧,或者之前轮询的帧确实有手势数据。所以这样的事情解决了(尽管记住你必须做一些长整数类型转换):

Frame lastFrame;
Frame thisFrame;

void Update()
{
    LeapInput.Update();
    lastFrame = thisFrame;
    thisFrame = LeapInput.Frame;

    long difference = thisFrame.Id - lastFrame.Id;

    while(difference > 0){
      Frame f = controller.Frame(difference);
      GestureList gestures = f.Gestures();
      if(gestures.Count > 0){
        foreach(Gesture gesture in gestures){
          Debug.Log(gesture.Type + " found in frame " + f.Id);
        }
      }
      difference--;
    }



}

一旦在所有跳过的帧或历史帧中找到这些手势,就可以随意使用它们。

于 2013-08-18T18:04:44.173 回答