LeapMotion SDK开发,常用功能总结

来源:互联网 发布:什么软件可以学数学 编辑:程序博客网 时间:2024/05/20 15:39

设置设备后台获取数据:
controller.setPolicyFlags(Leap::Controller::POLICY_BACKGROUND_FRAMES);

onDeviceChange:
获取设备列表: controller.devices();
获取设备名称:devices[i].toString();
判断设备是否传输: devices[i].isStreaming();

onConnect:
启用手势功能:
controller.enableGesture(Gesture::TYPE_CIRCLE);
controller.enableGesture(Gesture::TYPE_KEY_TAP);
controller.enableGesture(Gesture::TYPE_SCREEN_TAP);
controller.enableGesture(Gesture::TYPE_SWIPE);

------------------------
hand:
判断左右手: hand.isLeft();
手掌位置    hand.palmPosition();
法向量  Vector normal = hand.palmNormal();
方向向量  Vector direction = hand.direction();
与垂直轴Y的角度: normal.roll() * RAD_TO_DEG
与水平面-Z的夹角: direction.yaw() * RAD_TO_DEG

arm:
手臂的方向:arm.direction();
腕关节的位置: arm.wristPosition();
手肘的位置: arm.elbowPosition();

Finger:
指头的类型(名称): finger.type();
指头的ID: finger.id();
指头的长度: finger.length();
指头的宽度: finger.width();

Bone:
骨头的类型:Bone::Type
骨头的开始位置点:bone.prevJoint();
骨头的结束位置点:bone.nextJoint();
骨头的方向: bone.direction();

------------------

Tool:
工具ID: frame.id();
工具的位置:tool.tipPosition();
工具的方向: tool.direction();

Gesture:
手势类型:gesture.type();

switch (gesture.type()) {
  case Gesture::TYPE_CIRCLE:
  {
    CircleGesture circle = gesture;
    std::string clockwiseness;

    if (circle.pointable().direction().angleTo(circle.normal()) <= PI/2) {
      clockwiseness = "clockwise";
    } else {
      clockwiseness = "counterclockwise";
    }

    // Calculate angle swept since last frame
    float sweptAngle = 0;
    if (circle.state() != Gesture::STATE_START) {
      CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
      sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
    }
    std::cout << std::string(2, ' ')
              << "Circle id: " << gesture.id()
              << ", state: " << stateNames[gesture.state()]
              << ", progress: " << circle.progress()
              << ", radius: " << circle.radius()
              << ", angle " << sweptAngle * RAD_TO_DEG
              <<  ", " << clockwiseness << std::endl;
    break;
  }
  case Gesture::TYPE_SWIPE:
  {
    SwipeGesture swipe = gesture;
    std::cout << std::string(2, ' ')
      << "Swipe id: " << gesture.id()
      << ", state: " << stateNames[gesture.state()]
      << ", direction: " << swipe.direction()
      << ", speed: " << swipe.speed() << std::endl;
    break;
  }
  case Gesture::TYPE_KEY_TAP:
  {
    KeyTapGesture tap = gesture;
    std::cout << std::string(2, ' ')
      << "Key Tap id: " << gesture.id()
      << ", state: " << stateNames[gesture.state()]
      << ", position: " << tap.position()
      << ", direction: " << tap.direction()<< std::endl;
    break;
  }
  case Gesture::TYPE_SCREEN_TAP:
  {
    ScreenTapGesture screentap = gesture;
    std::cout << std::string(2, ' ')
      << "Screen Tap id: " << gesture.id()
      << ", state: " << stateNames[gesture.state()]
      << ", position: " << screentap.position()
      << ", direction: " << screentap.direction()<< std::endl;
    break;
  }
  default:
    std::cout << std::string(2, ' ')  << "Unknown gesture type." << std::endl;
    break;
}


 

0 0