本文整理汇总了C++中leap::Hand::sphereRadius方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::sphereRadius方法的具体用法?C++ Hand::sphereRadius怎么用?C++ Hand::sphereRadius使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类leap::Hand
的用法示例。
在下文中一共展示了Hand::sphereRadius方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: modeStreamDataToSL
// This experimental mode sends chat messages into SL on a back channel for LSL scripts
// to intercept with a listen() event. This is experimental and not sustainable for
// a production feature ... many avatars using this would flood the chat system and
// hurt server performance. Depending on how useful this proves to be, a better
// mechanism should be designed to stream data from the viewer into SL scripts.
void LLLMImpl::modeStreamDataToSL(Leap::HandList & hands)
{
S32 numHands = hands.count();
if (numHands == 1 &&
mChatMsgTimer.checkExpirationAndReset(LLLEAP_CHAT_MSG_INTERVAL))
{
// Get the first (and only) hand
Leap::Hand hand = hands[0];
Leap::Vector palm_pos = hand.palmPosition();
Leap::Vector palm_normal = hand.palmNormal();
F32 ball_radius = (F32) hand.sphereRadius();
Leap::Vector ball_center = hand.sphereCenter();
// Chat message looks like "/2343 LM1,<palm pos>,<palm normal>,<sphere center>,<sphere radius>"
LLVector3 vec;
std::stringstream status_chat_msg;
status_chat_msg << "/2343 LM,";
status_chat_msg << "<" << palm_pos.x << "," << palm_pos.y << "," << palm_pos.z << ">,";
status_chat_msg << "<" << palm_normal.x << "," << palm_normal.y << "," << palm_normal.z << ">,";
status_chat_msg << "<" << ball_center.x << "," << ball_center.y << "," << ball_center.z << ">," << ball_radius;
FSNearbyChat::instance().sendChatFromViewer(status_chat_msg.str(), CHAT_TYPE_SHOUT, FALSE);
}
}
示例2: modeDumpDebugInfo
// This controller mode just dumps out a bunch of the Leap Motion device data, which can then be
// analyzed for other use.
void LLLMImpl::modeDumpDebugInfo(Leap::HandList & hands)
{
S32 numHands = hands.count();
if (numHands == 1)
{
// Get the first hand
Leap::Hand hand = hands[0];
// Check if the hand has any fingers
Leap::FingerList finger_list = hand.fingers();
S32 num_fingers = finger_list.count();
if (num_fingers >= 1)
{ // Calculate the hand's average finger tip position
Leap::Vector pos(0, 0, 0);
Leap::Vector direction(0, 0, 0);
for (size_t i = 0; i < num_fingers; ++i)
{
Leap::Finger finger = finger_list[i];
pos += finger.tipPosition();
direction += finger.direction();
// Lots of log spam
LL_INFOS("LeapMotion") << "Finger " << i << " string is " << finger.toString() << LL_ENDL;
}
pos = Leap::Vector(pos.x/num_fingers, pos.y/num_fingers, pos.z/num_fingers);
direction = Leap::Vector(direction.x/num_fingers, direction.y/num_fingers, direction.z/num_fingers);
LL_INFOS("LeapMotion") << "Hand has " << num_fingers << " fingers with average tip position"
<< " (" << pos.x << ", " << pos.y << ", " << pos.z << ")"
<< " direction (" << direction.x << ", " << direction.y << ", " << direction.z << ")"
<< LL_ENDL;
}
Leap::Vector palm_pos = hand.palmPosition();
Leap::Vector palm_normal = hand.palmNormal();
LL_INFOS("LeapMotion") << "Palm pos " << palm_pos.x
<< ", " << palm_pos.y
<< ", " << palm_pos.z
<< ". Normal: " << palm_normal.x
<< ", " << palm_normal.y
<< ", " << palm_normal.z
<< LL_ENDL;
F32 ball_radius = (F32) hand.sphereRadius();
Leap::Vector ball_center = hand.sphereCenter();
LL_INFOS("LeapMotion") << "Ball pos " << ball_center.x
<< ", " << ball_center.y
<< ", " << ball_center.z
<< ", radius " << ball_radius
<< LL_ENDL;
} // dump_out_data
}
示例3: recognizedControls
void BallGesture::recognizedControls(const Leap::Controller &controller, std::vector<ControlPtr> &controls) {
Leap::Frame frame = controller.frame();
// hands detected?
if (frame.hands().isEmpty())
return;
for (int i = 0; i < frame.hands().count(); i++) {
// gonna assume the user only has two hands. sometimes leap thinks otherwise.
if (i > 1) break;
Leap::Hand hand = frame.hands()[i];
double radius = hand.sphereRadius(); // in mm
if (! radius)
continue;
BallRadiusPtr bc = make_shared<BallRadius>(radius, i);
ControlPtr cptr = dynamic_pointer_cast<Control>(bc);
controls.push_back(cptr);
}
}
示例4: modeFlyingControlTest
// This controller mode is used to fly the avatar, going up, down, forward and turning.
void LLLMImpl::modeFlyingControlTest(Leap::HandList & hands)
{
static S32 sLMFlyingHysteresis = 0;
S32 numHands = hands.count();
BOOL agent_is_flying = gAgent.getFlying();
if (numHands == 0
&& agent_is_flying
&& sLMFlyingHysteresis > 0)
{
sLMFlyingHysteresis--;
if (sLMFlyingHysteresis == 0)
{
LL_INFOS("LeapMotion") << "LM stop flying - look ma, no hands!" << LL_ENDL;
gAgent.setFlying(FALSE);
}
}
else if (numHands == 1)
{
// Get the first hand
Leap::Hand hand = hands[0];
// Check if the hand has any fingers
Leap::FingerList finger_list = hand.fingers();
S32 num_fingers = finger_list.count();
Leap::Vector palm_pos = hand.palmPosition();
Leap::Vector palm_normal = hand.palmNormal();
F32 ball_radius = (F32) hand.sphereRadius();
Leap::Vector ball_center = hand.sphereCenter();
// Number of fingers controls flying on / off
if (num_fingers == 0 && // To do - add hysteresis or data smoothing?
agent_is_flying)
{
if (sLMFlyingHysteresis > 0)
{
sLMFlyingHysteresis--;
}
else
{
LL_INFOS("LeapMotion") << "LM stop flying" << LL_ENDL;
gAgent.setFlying(FALSE);
}
}
else if (num_fingers > 2 &&
!agent_is_flying)
{
LL_INFOS("LeapMotion") << "LM start flying" << LL_ENDL;
gAgent.setFlying(TRUE);
sLMFlyingHysteresis = 5;
}
// Radius of ball controls forward motion
if (agent_is_flying)
{
if (ball_radius > 110.f)
{ // Open hand, move fast
gAgent.setControlFlags(AGENT_CONTROL_AT_POS | AGENT_CONTROL_FAST_AT);
}
else if (ball_radius > 85.f)
{ // Partially open, move slow
gAgent.setControlFlags(AGENT_CONTROL_AT_POS);
}
else
{ // Closed - stop
gAgent.clearControlFlags(AGENT_CONTROL_AT_POS);
}
// Height of palm controls moving up and down
if (palm_pos.y > 260.f)
{ // Go up fast
gAgent.setControlFlags(AGENT_CONTROL_UP_POS | AGENT_CONTROL_FAST_UP);
}
else if (palm_pos.y > 200.f)
{ // Go up
gAgent.setControlFlags(AGENT_CONTROL_UP_POS);
}
else if (palm_pos.y < 60.f)
{ // Go down fast
gAgent.setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_NEG);
}
else if (palm_pos.y < 120.f)
{ // Go down
gAgent.setControlFlags(AGENT_CONTROL_UP_NEG);
}
else
{ // Clear up / down
gAgent.clearControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_POS | AGENT_CONTROL_UP_NEG);
}
// Palm normal going left / right controls direction
if (mYawTimer.checkExpirationAndReset(LLLEAP_YAW_INTERVAL))
{
if (palm_normal.x > 0.4f)
{ // Go left fast
//.........这里部分代码省略.........
示例5: onFrame
void LeapListener::onFrame(const Leap::Controller& controller) {
// Get the most recent frame and report some basic information
const Leap::Frame frame = controller.frame();
/*std::cout << "Frame id: " << frame.id()
<< ", timestamp: " << frame.timestamp()
<< ", hands: " << frame.hands().count()
<< ", fingers: " << frame.fingers().count()
<< ", tools: " << frame.tools().count()
<< ", gestures: " << frame.gestures().count();
*/
if (!frame.hands().isEmpty()) {
// Get the first hand
const Leap::Hand hand = frame.hands()[0];
qDebug() << "Radius: " << hand.sphereRadius();
// Grab
if(hand.sphereRadius() < 50.0 && hand.translationProbability(controller.frame(1)) > 0.6){
Leap::Vector v = hand.translation(controller.frame(1));
v = 0.1 * v;
glwidget_->camera_.translate(v.x, v.y, v.z);
glwidget_->update();
}
qDebug() << "Hand pos" << hand.palmPosition().x << hand.palmPosition().y << hand.palmPosition().z;
if(frame.fingers().count() > 200 && frame.hands().count() == 1){
Leap::Vector trans = hand.translation(controller.frame(1));
//int dir = trans.y > 0 ? 1 : -1;
trans = 0.1 * trans;
//glwidget_->camera_.translate(0, 0, dir*0.1);
//Leap::Vector rot = hand.rotationAxis(controller.frame());
float yaw = hand.rotationAngle(controller.frame(1), Leap::Vector(1, 0, 0));
float pitch = hand.rotationAngle(controller.frame(1), Leap::Vector(1, 0, 0)); // works
float roll = hand.rotationAngle(controller.frame(1), Leap::Vector(0, 0, 1));
//qDebug() << yaw << pitch << roll;
glwidget_->camera_.rotate3D(yaw, pitch, roll);
//glwidget_->camera_.rotate2D(0.01 * trans.x, 0.01 * trans.y);
glwidget_->update();
}
/*
// Check if the hand has any fingers
const Leap::FingerList fingers = hand.fingers();
if (!fingers.empty()) {
// Calculate the hand's average finger tip position
Leap::Vector avgPos;
for (int i = 0; i < fingers.count(); ++i) {
avgPos += fingers[i].tipPosition();
}
avgPos /= (float)fingers.count();
std::cout << "Hand has " << fingers.count()
<< " fingers, average finger tip position" << avgPos<< std::endl;
}
// Get the hand's sphere radius and palm position
std::cout << "Hand sphere radius: " << hand.sphereRadius()
<< " mm, palm position: " << hand.palmPosition() << std::endl;
// Get the hand's normal vector and direction
const Leap::Vector normal = hand.palmNormal();
const Leap::Vector direction = hand.direction();
// Calculate the hand's pitch, roll, and yaw angles
std::cout << "Hand pitch: " << direction.pitch() * Leap::RAD_TO_DEG << " degrees, "
<< "roll: " << normal.roll() * Leap::RAD_TO_DEG << " degrees, "
<< "yaw: " << direction.yaw() * Leap::RAD_TO_DEG << " degrees"<< std::endl;
}
// Get gestures
const Leap::GestureList gestures = frame.gestures();
for (int g = 0; g < gestures.count(); ++g) {
Leap::Gesture gesture = gestures[g];
switch (gesture.type()) {
case Leap::Gesture::TYPE_CIRCLE:
{
Leap::CircleGesture circle = gesture;
std::string clockwiseness;
if (circle.pointable().direction().angleTo(circle.normal()) <= M_PI/4) {
clockwiseness = "clockwise";
} else {
clockwiseness = "counterclockwise";
}
// Calculate angle swept since last frame
float sweptAngle = 0;
if (circle.state() != Leap::Gesture::STATE_START) {
Leap::CircleGesture previousUpdate = Leap::CircleGesture(controller.frame().gesture(circle.id()));
sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * M_PI;
//.........这里部分代码省略.........
示例6: draw
//--------------------------------------------------------------
void testApp::draw(){
ofSetWindowTitle(ofToString(ofGetFrameRate()));
//camera.begin();
float r0 = 30;
Leap::Vector ptp;
Leap::Vector ptp0;
Leap::Vector pNormal;
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight());
//ofSetColor(255, 255, 255);
Leap::Frame frame = leapController.frame();
Leap::HandList hands = frame.hands();
if (!hands.isEmpty()) {
//ofLogNotice("hand detected");
int count = hands.count();
for (int i = 0; i<count; i++) {
if (i>1) break;
Leap::Hand tempHand = hands[i];
pNormal = tempHand.palmNormal();
ofLogNotice("hand " +ofToString(i) + "normal", ofToString(pNormal.x) + " " + ofToString(pNormal.y) + " " + ofToString(pNormal.z));
}
Leap::Hand hand = hands[0];
Leap::Hand hand1 = hands[1];
double r = hand.sphereRadius();
//ofLogNotice("r is" + ofToString(r));
r0 = r * 5;
ptp = hand1.palmNormal();
ptp0 = hand.palmNormal();
ofLogNotice("distance is ", ofToString(abs(ptp.x)-abs(pNormal.x)) + " " + ofToString(abs(ptp.y)-abs(pNormal.y)));
if (abs(abs(ptp.x)-abs(pNormal.x))<0.04 && abs(abs(ptp.y)-abs(pNormal.y))<0.04) {
phase1=false;
phase2=true;
ofLogNotice("phase 2 triggered", ofToString(phase1));
}
}
if(phase1){
ofSphere(ptp.x,-ptp.y,ptp.z, r0);
}
vector<Leap::FingerList> fingers = leap.getFingers();
if (!fingers.empty() && phase1==false && phase2 == false && phase3==false
&& phase4==false && phase5==false && phase6 == false && phase7 == false) {
//ofLogNotice("finger detected");
//ofBox(100, -200, 4, 40, 40, 40);
phase1 = true;
}
if (!fingers.empty()) {
for (int cnt = 0; cnt < fingers.size(); cnt++) {
for (int fingerNum = 0; fingerNum < fingers[cnt].count(); fingerNum++) {
Leap::Vector pt = fingers[cnt][fingerNum].tipPosition();
Leap::Vector vpt = fingers[cnt][fingerNum].tipVelocity();
pt.x = pt.x*2;
pt.y = (pt.y * -1)*2;
pt.z = pt.z *2;
//ofLogNotice("finger number is " + ofToString(cnt) + ofToString(fingerNum));
//ofSphere(pt.x,pt.y,pt.z, 10);
//ofBox(pt.x, pt.y, pt.z, 10, 10, 10);
//ofLogNotice("position is " + ofToString(pt.x) + " " + ofToString(pt.y) + " " + ofToString(pt.z));
//ofLogNotice("velocity is " + ofToString(vpt.x) + " " + ofToString(vpt.y) + " " + ofToString(vpt.z));
drawSphere(pt, 10);
}
}
Leap::Vector tpt = fingers[0][0].tipPosition();
}
ofPopMatrix();
camera.end();
}
示例7: update
//--------------------------------------------------------------
void testApp::update(){
Leap::Vector pNormal;
Leap::Frame frame = leapController.frame();
Leap::HandList hands = frame.hands();
Leap::Vector pt0;
Leap::Vector pt1;
if (!hands.isEmpty()) {
fingerPos.clear();
sphereSize.clear();
sphereNorm.clear();
spherePos.clear();
//ofLogNotice("hand detected");
//----------------------------------- data collection -------------------------------------------------------------
for (int i = 0; i<hands.count(); i++) {
if (i>1) break;
Leap::Hand tempHand = hands[i];
Leap::FingerList tempfinger = tempHand.fingers();
for (int j = 0; j <= tempfinger.count(); j++) {
ofVec3f pt;
Leap::Finger finger = hands[i].fingers()[j];
Leap::Vector tempPT=finger.tipPosition();
pt.x=tempPT.x;pt.y=tempPT.y;pt.z=tempPT.z;
fingerPos.push_back(pt);
}
pt0 = tempHand.palmNormal();
Leap::Vector center = tempHand.sphereCenter();
ofVec3f sp; sp.x = center.x; sp.y = center.y; sp.z = center.z;
float r = tempHand.sphereRadius();
spherePos.push_back(sp);
sphereSize.push_back(r);
sphereNorm.push_back(pt0);
ofLogNotice("hand " +ofToString(i) + "normal", ofToString(pt0.x) + " " + ofToString(pt0.y) + " " + ofToString(pt0.z));
ofLogNotice("hand " + ofToString(i) + "center ", ofToString(sp.x) + " " + ofToString(sp.y) + " " + ofToString(sp.z));
}
//---------------------------------- state machine ------------------------------------------------------------------
if(phase1==true && phase2 == false && phase3==false && phase4 == false && phase5==false && phase6 == false && phase7 == false && (!fingerPos.empty()))
{
phase2 = true;
state = 1;
}
if (phase2 == true && (sphereNorm.size()>=2)) {
pt0 = sphereNorm[0];
pt1 = sphereNorm[1];
if (abs(abs(pt0.x)-abs(pt1.x))<0.04 && abs(abs(pt0.y)-abs(pt1.y))<0.04) {
phase3 = true;
phase2 = false;
}
}
}
// ofLogNotice("phase1: ", ofToString(phase1));
// ofLogNotice("phase2: ", ofToString(phase2));
// ofLogNotice("phase3: ", ofToString(phase3));
// ofLogNotice("phase4: ", ofToString(phase4));
// ofLogNotice("phase5: ", ofToString(phase5));
// ofLogNotice("phase6: ", ofToString(phase6));
// ofLogNotice("phase7: ", ofToString(phase7));
oldFrame = frame;
preId = frame.id();
}
示例8: oleap_bang
//.........这里部分代码省略.........
oleap_bundleMessage(bundle,buff,leftmost.direction().y);
sprintf(buff,"/hand/leftmost/direction/z");
oleap_bundleMessage(bundle,buff,leftmost.direction().z);
sprintf(buff,"/hand/leftmost/pitch");
oleap_bundleMessage(bundle,buff,leftmost.palmPosition().pitch());
sprintf(buff,"/hand/leftmost/yaw");
oleap_bundleMessage(bundle,buff,leftmost.palmPosition().yaw());
sprintf(buff,"/hand/leftmost/roll");
oleap_bundleMessage(bundle,buff,leftmost.palmPosition().roll());
sprintf(buff,"/hand/leftmost/palm/velocity/x");
oleap_bundleMessage(bundle,buff,leftmost.palmVelocity().x);
sprintf(buff,"/hand/leftmost/palm/velocity/y");
oleap_bundleMessage(bundle,buff,leftmost.palmVelocity().y);
sprintf(buff,"/hand/leftmost/palm/velocity/z");
oleap_bundleMessage(bundle,buff,leftmost.palmVelocity().z);
sprintf(buff,"/hand/leftmost/palm/sphere/center/x");
oleap_bundleMessage(bundle,buff,leftmost.sphereCenter().x);
sprintf(buff,"/hand/leftmost/palm/sphere/center/y");
oleap_bundleMessage(bundle,buff,leftmost.sphereCenter().y);
sprintf(buff,"/hand/leftmost/palm/sphere/center/z");
oleap_bundleMessage(bundle,buff,leftmost.sphereCenter().z);
sprintf(buff,"/hand/leftmost/palm/sphere/radius");
oleap_bundleMessage(bundle,buff,leftmost.sphereRadius());
sprintf(buff,"/hand/leftmost/palm/normal/x");
oleap_bundleMessage(bundle,buff,leftmost.palmNormal().x);
sprintf(buff,"/hand/leftmost/palm/normal/y");
oleap_bundleMessage(bundle,buff,leftmost.palmNormal().y);
sprintf(buff,"/hand/leftmost/palm/normal/z");
oleap_bundleMessage(bundle,buff,leftmost.palmNormal().z);
sprintf(buff,"/hand/leftmost/distance/from/rightmost");
oleap_bundleMessage(bundle,buff,leftmost.palmPosition().angleTo(rightmost.palmPosition()));
const Leap::FingerList &fingers = leftmost.fingers();
const size_t numFingers = fingers.count();
for(size_t j = 0; j < numFingers; j++)
{
const Leap::Finger &finger = fingers[j];
const int32_t finger_id = finger.id();
//const Leap::Ray& tip = finger.tip();
const Leap::Vector direction = finger.direction();
const Leap::Vector position = finger.tipPosition();
const Leap::Vector velocity = finger.tipVelocity();
const double width = finger.width();
const double length = finger.length();
const bool isTool = finger.isTool();
sprintf(buff,"/hand/leftmost/finger/%d/hand_id",j+1);
oleap_bundleMessage(bundle,buff,leftmost.id());
sprintf(buff,"/hand/leftmost/finger/%d/finger_id",j+1);