LeapMotion SDK开发,常用功能总结
2014-11-20 15:05
302 查看
设置设备后台获取数据:
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;
}
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;
}
相关文章推荐
- 【PHP入门篇】 8.PHP开发工具之Zend Studio常用功能--慕课网【学习总结】
- 我们搞web开发,总结一些常用功能源码
- ios开发总结:Utils常用方法等收集,添加扩展类,工具类方法,拥有很多方便快捷功能(不断更新中。。。)
- yii2-GridView在开发中常用的功能及技巧总结
- 我在开发过程总结的一套实现常用功能的函数
- VISUAL C++软件开发中几个常用功能的实现
- ASP.NET中常用功能代码总结(6)——XML文件操作篇
- ASP.NET中常用功能代码总结(4)——保存图片到XML文件
- ASP.NET中常用功能代码总结(5)——文件操作篇
- Solaris常用ssh工具功能对比总结
- ASP.NET中常用功能代码总结(3)——上传图片到数据库
- ASP.NET中常用功能代码总结(4)——保存图片到XML文件
- ASP.NET中常用功能代码总结(3)——上传图片到数据库
- ASP.NET中常用功能代码总结(6)——XML文件操作篇
- ASP.NET中常用功能代码总结——XML文件操作篇
- WinForm控件开发总结(三)------认识WinForm控件常用的Attribute
- ASP.NET中常用功能代码总结(6)——XML文件操作篇
- ASP.NET中常用功能代码总结(4)——保存图片到XML文件
- ASP.NET中常用功能代码总结(3)——上传图片到数据库
- ASP.NET中常用功能代码总结(7)——利用Jmail发送和接收邮件