LeapMotion HelloWorld

Leap::Controller:

  该类提供了主要的接口,当你创建一个controller对象时,它会和电脑上的服务连接使得你能从Leap::Frame对象获得帧数据

如何获得帧对象:

  调用Controller对象的frame函数,空参返回最新的Frame对象,参数为1时获取的是上一次的Frame对象

更新程序数据的两种方式:

  类似  轮询(循环里不断去获得帧对象)和中断(添加Listener,有数据更新时执行回调函数

回调函数的写法:

  继承自Leap::Listener,重写一系列回调函数:

    • onInit — dispatched once, when the controller to which the listener is registered is initialized.
    • onConnect — dispatched when the controller connects to the Leap and is ready to begin sending frames of motion tracking data.
    • onDisconnect — dispatched if the controller disconnects from the Leap (for example, if you unplug the Leap device or shut down the Leap software).
    • onExit — dispatched to a listener when it is removed from a controller.
    • onFrame — dispatched when a new frame of motion tracking data is available.

 

Frame里的数据:

  Hand对象或Finger对象都包含一个id和一些属性

 

手势:

  获取手势之前需使能手势识别,  在connect后任意时刻调用

    controller.enableGesture(Gesture::TYPE_CIRCLE);

      controller.enableGesture(Gesture::TYPE_KEY_TAP);等等即可使能

获取手势对象

const GestureList gestures = frame.gestures();

//gestures.count()

//Gestures[0]
//controller.frame(1).gesture(circle.id())//返回上一帧的某一手势,用id号查找

 

Gesture 类是手势对象的基类,获得的gesture可能需要强制转换成子类,转换类型不匹配时,返回 invalid Gesture objects

switch (gesture.type()){}分类对手势进行操作

 

posted @ 2014-04-25 00:01  熄灯就睡  阅读(282)  评论(0编辑  收藏  举报