当前位置: 首页>>代码示例>>C++>>正文


C++ Hand::direction方法代码示例

本文整理汇总了C++中leap::Hand::direction方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::direction方法的具体用法?C++ Hand::direction怎么用?C++ Hand::direction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在leap::Hand的用法示例。


在下文中一共展示了Hand::direction方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onFrame

void LeapListener::onFrame(const Controller& controller) {
	const Frame frame = controller.frame();
	static int64_t lastFrameID = 0;

	if(frame.id() < lastFrameID+10)
		return;

	Leap::HandList hands = frame.hands();
	Leap::Hand hand = hands[0];

	if(hand.isValid()) {
		float pitch = hand.direction().pitch();
		float yaw = hand.direction().yaw();
		float roll = hand.palmNormal().roll();
		float height = hand.palmPosition().y;

		std::cout << "Pitch: " << RAD_TO_DEG*pitch << " Yaw: " << RAD_TO_DEG*yaw << " Roll: " << RAD_TO_DEG*roll << " Height: " << height << " Frame: " << frame.id() << std::endl;

// 		switch(gest.type()) {
// 			case Gesture::TYPE_CIRCLE:
// 				std::cout << "Takeoff" << std::endl;
// 				if (jakopter_takeoff() < 0)
// 					return;
// 				break;
// 			case Gesture::TYPE_SWIPE:
// 				std::cout << "Land" << std::endl;
// 				if (jakopter_land() < 0)
// 					return;
// 				break;
// 			default:
// 				break;
// 		}

		char c = 's';

		if (height > 300)
			c = 'u';
		else if(height < 75)
			c = 'k';
		else if (height < 150)
			c = 'd';


		if (roll > 0.7)
			c = 'l';
		else if (roll < -0.7)
			c = 'r';

		if (pitch > 0.7)
			c = 'b';
		else if (pitch < -0.7)
			c = 'f';

		FILE *cmd = fopen(CMDFILENAME,"w");
		fprintf(cmd, "%c\n", c);
		fclose(cmd);
	}

	lastFrameID = frame.id();
}
开发者ID:Drone2,项目名称:utils,代码行数:60,代码来源:leap.cpp

示例2: prepareDataClone

GestureFrame LMRecorder::prepareDataClone(const Leap::Frame frame, double timestamp)
{

	GestureFrame outputFrame;

	outputFrame.setTimestamp(timestamp);

	Leap::HandList handsInFrame = frame.hands();
	for(int handIndex=0; handIndex<handsInFrame.count(); handIndex++)
	{
		Leap::Hand currHand = handsInFrame[handIndex];

		//create GestureHand
		GestureHand gestureHand(
			currHand.id(),
			Vertex(currHand.palmPosition().x, currHand.palmPosition().y, currHand.palmPosition().z),
			Vertex(0, 0, 0/*currHand.stabilizedPalmPosition().x, currHand.stabilizedPalmPosition().y, currHand.stabilizedPalmPosition().z*/),
			Vertex(currHand.palmNormal().x, currHand.palmNormal().y, currHand.palmNormal().z),
			Vertex(currHand.direction().x, currHand.direction().y, currHand.direction().z)
		);
		gestureHand.setOrderValue(currHand.palmPosition().x);

		Vertex planeNormalVec = gestureHand.getDirection().crossProduct(gestureHand.getPalmNormal()).getNormalized();

		Leap::FingerList fingersInCurrHand = currHand.fingers();
		for (int fingerIndex=0; fingerIndex<fingersInCurrHand.count(); fingerIndex++)
		{
			Leap::Finger currFinger = fingersInCurrHand[fingerIndex];

			Leap::Vector leapFingerTipPos = currFinger.tipPosition();
			Vertex fingerTipPos(leapFingerTipPos.x, leapFingerTipPos.y, leapFingerTipPos.z);
			float distance = getPointDistanceFromPlane(fingerTipPos, gestureHand.getPalmPosition(), planeNormalVec);

			//create GestureFinger
			GestureFinger gestureFinger(
				currFinger.id(),
				fingerTipPos,
				Vertex(currFinger.stabilizedTipPosition().x, currFinger.stabilizedTipPosition().y, currFinger.stabilizedTipPosition(). z),
				Vertex(currFinger.direction().x, currFinger.direction().y, currFinger.direction().z),
				currFinger.length(),
				currFinger.width()
			);
			gestureFinger.setOrderValue(distance);

			gestureHand.addFinger(gestureFinger);
		}
		gestureHand.sortFingers();

		outputFrame.addHand(gestureHand);
	}
	outputFrame.sortHands();
}
开发者ID:Belial2010,项目名称:LeapGesture-library,代码行数:52,代码来源:LMRecorder.cpp

示例3: onFrame

void LeapListener::onFrame(const Controller& controller) {
    const Frame frame = controller.frame();
    Leap::HandList hands = frame.hands();
    Leap::Hand hand = hands[0];

    if(hand.isValid()){
        leapData.pitch = hand.direction().pitch();
        leapData.yaw = hand.direction().yaw();
        leapData.roll = hand.palmNormal().roll();
        leapData.height = hand.palmPosition().y;


        std::cout << "Frame id: " << frame.id()
              << ", timestamp: " << frame.timestamp()
              << ", height: " << leapData.height
              << ", pitch: " << RAD_TO_DEG * leapData.pitch
              << ", yaw: " << RAD_TO_DEG * leapData.yaw
              << ", roll: " << RAD_TO_DEG * leapData.roll << std::endl;
    }
}
开发者ID:AlexandreMumble,项目名称:Jakopter,代码行数:20,代码来源:Leap.cpp

示例4: convertHandRotation

void convertHandRotation(const Leap::Hand& hand, MatrixF& outRotation)
{
   // We need to convert from Motion coordinates to
   // Torque coordinates.  The conversion is:
   //
   // Motion                       Torque
   // a b c         a  b  c        a -c  b
   // d e f   -->  -g -h -i  -->  -g  i -h
   // g h i         d  e  f        d -f  e
   const Leap::Vector& handToFingers = hand.direction();
   Leap::Vector handFront = -handToFingers;
   const Leap::Vector& handDown = hand.palmNormal();
   Leap::Vector handUp = -handDown;
   Leap::Vector handRight = handUp.cross(handFront);

   outRotation.setColumn(0, Point4F(  handRight.x, -handRight.z,  handRight.y,  0.0f));
   outRotation.setColumn(1, Point4F( -handFront.x,  handFront.z, -handFront.y,  0.0f));
   outRotation.setColumn(2, Point4F(  handUp.x,    -handUp.z,     handUp.y,     0.0f));
   outRotation.setPosition(Point3F::Zero);
}
开发者ID:03050903,项目名称:Torque3D,代码行数:20,代码来源:leapMotionUtil.cpp

示例5: updateFrame

//-------------------------------------------------------------------------------------
bool DigitalForensicsVisualisation::updateFrame(const Ogre::FrameEvent& evt)
{
	
	pointLight->setPosition(mCamera->getPosition());

	//leap
	const Frame frame = leapController.frame();
	Leap::Hand rightMost = frame.hands().rightmost();

	
#pragma region hand
	//
	//
	//if (!frame.hands().isEmpty() && !handOrientationFlag) 
	//{
	//		
	//	palmNode->resetOrientation();
	//	handOrientationFlag = true;	
	//}
	//else if (handOrientationFlag && frame.hands().isEmpty() )
	//{
	//	handOrientationFlag = false;
	//}

#pragma endregion hand


	if (!frame.hands().isEmpty())
	{
		
		

		Leap::Hand rightMost = frame.hands().rightmost();
		


		float pitchValue = rightMost.direction().pitch() * RAD_TO_DEG;
		float rollValue = rightMost.palmNormal().roll() * RAD_TO_DEG;
		float yawValue = rightMost.direction().yaw() * RAD_TO_DEG;

		// to detect open and closed hand
		Ogre::Vector3 indexTip = toVector(rightMost.fingers()[1].tipPosition());
		Ogre::Vector3 pinkyTip = toVector(rightMost.fingers()[3].tipPosition());

	
		float angle = std::abs(indexTip.x - pinkyTip.x);
		angle /= rightMost.fingers()[1].length(); // to normalise 

		if (rightMost.grabStrength() == 1)
		{
			if (mCamera->getOrientation().getPitch() + (Ogre::Radian) (rightMost.palmPosition().y - previousPosition.y) / 80 < (Ogre::Radian) 0.17 && mCamera->getOrientation().getPitch() + (Ogre::Radian) (rightMost.palmPosition().y - previousPosition.y) / 80 > (Ogre::Radian) -1.4)
				mCamera->pitch((Ogre::Radian) (rightMost.palmPosition().y - previousPosition.y) / 80);
			//mCamera->yaw((Ogre::Radian) (rightMost.palmPosition().x - previousPosition.x) / -80);
			//mCamera->roll((Ogre::Radian) (rollValue - previousFrameRoll) / 30);
			
		}
		else if (angle > 0.65)
		{
			
			//palmNode->setPosition(toVector(frame.hands().rightmost().palmPosition())); // between 100 and 250	
			if ((mCamera->getPosition().y + (frame.hands().rightmost().palmPosition().y - previousPosition.y)*2 ) > -290)
				mCamera->setPosition(mCamera->getPosition() + (toVector(frame.hands().rightmost().palmPosition()) - previousPosition)*2 );

			
		}
		//else
		//{
		//	mCamera->yaw((Ogre::Radian) (yawValue - previousFrameYaw) / -10);
		//}

		previousPosition = toVector(frame.hands().rightmost().palmPosition());
		

#pragma region hand
		//palmNode->pitch((Ogre::Radian) (pitchValue - previousFramePitch) );

		//
		//palmNode->roll((Ogre::Radian) (rollValue - previousFrameRoll) );

		//
		//palmNode->yaw((Ogre::Radian) (yawValue - previousFrameYaw) );

		//previousFramePitch = rightMost.direction().pitch() * RAD_TO_DEG;
		//previousFrameYaw = rightMost.direction().yaw() * RAD_TO_DEG;
		//previousFrameRoll = rightMost.palmNormal().roll() * RAD_TO_DEG;

		// Get fingers
		//FingerList fingers; 
		//fingers = rightMost.fingers();
		//int i = 0; //between 0 and 19 (finger bones)
		//
		//for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) 
		//{
		//	
		//	Finger finger;
		//	finger = *fl;
		//	
		//	
		//  /*char* dummy = (char*) malloc(128);
//.........这里部分代码省略.........
开发者ID:ljmu-cms,项目名称:digital-forensics-visualisation,代码行数:101,代码来源:DigitalForensicsVisualisation.cpp

示例6: main


//.........这里部分代码省略.........
						}
					}
				}

				//2014.02.22
				// height value enable 150 - 400
				// x 150 - 600  center:400
				// y 150 - 600  center:400
				//printf(" x:%02d y:%02d w:%02d h:%02d",faces[0].x,faces[0].y,faces[0].width,faces[0].height);
				//printf(" cx:%02d cy:%02d w:%02d h:%02d",cPt1.x,cPt1.y,faces[0].width,faces[0].height);
				//printf("\n");
				//
				IplImage wimage = captureFrameMat;
				//static IplImage wimage = grayscaleFrame;
				//cvCopy( image, wimage);
				image = &wimage;
			}

		}catch(char *e)
		{
			printf("%s\n",e);
		}
#endif
		}

        //2014.03.09 add
		if((mLeapnot != true)&&(pLeapData.mLeapMode == true)&&(leapController.isConnected()))
		{
			frame = leapController.frame(); // controller is a Leap::Controller object
			hands = frame.hands();
			firstHand = hands[0];

			pitch_pre = pitch;
			pitch = firstHand.direction().pitch();//前p:-0.5 後p: 0.9
			pitch = pitch_pre*Para_pre + pitch*Para_cur;	//Para_pre:0.80 Para_cur:0.20

			yaw_pre = yaw;    //左y:-1.0 右y: 0.7
			yaw = firstHand.direction().yaw();    //左y:-1.0 右y: 0.7
			yaw = yaw_pre*Para_pre + yaw*Para_cur;

			roll_pre = roll; //左R: 0.8 右R:-1.0
			roll = firstHand.palmNormal().roll(); //左R: 0.8 右R:-1.0
			roll = roll_pre*Para_pre + roll*Para_cur;

			PosX = frame.pointables().leftmost().tipPosition().x;       //左右   左-150 〜 右 150
			PosY = frame.pointables().leftmost().tipPosition().y;       //上下昇降 下  50 〜 上 300
			PosZ = frame.pointables().leftmost().tipPosition().z * (1); //前後   手前-100 〜 奥 100

			if(pLeapData.mLeapDebugPrint == true){
				printf("%03d XYZ:%03.02f:%03.02f:%03.02f p:%03.02f y:%03.02f r:%03.02f TF:%01i: %i\n",mSoundCommandcounter, PosX,PosY,PosZ,pitch,yaw,roll,(int)mTakOffFlag,mSendCommandcounter);
			}

			//LeapMotion Value set
			//LeapMotionに近づけると TakeOFF
			if((PosY > 50) && (PosY < 75) && (mTakOffFlag == true))
			{
				if(mNonDronDebug == false)
				{
					if (ardrone.onGround())
					{
						mTakOffFlag = false;
					}else
					{
						if(mSoundCommandcounter>mSoundCommandOKcounter){
							sndPlaySound("..\\..\\src\\resource\\HackathonUser1orimasu.wav", SND_ASYNC);//orimasu
							mSoundCommandcounter = 0;
开发者ID:nakajimakou1,项目名称:cvdrone-master_leap_FaceDetect,代码行数:67,代码来源:main.cpp

示例7: oleap_bang

void oleap_bang(t_oleap *x)
{

	const Leap::Frame frame = x->leap->frame();
    const int64_t frame_id = frame.id();
    Leap::Controller controller;
    
	// ignore the same frame
	if (frame_id == x->frame_id_save) return;
	x->frame_id_save = frame_id;
	
	//outlet_anything(x->outlet, gensym("frame_start"), 0, nil);
    
    char buff[128];
    
    const Leap::HandList hands = frame.hands();
	const size_t numHands = hands.count();
    const Leap::Hand leftmost = hands.leftmost();
    const Leap::Hand rightmost = hands.rightmost();
    
    t_osc_bundle_u *bundle = osc_bundle_u_alloc();//alloc creates memory for and initializes the bundle

    controller.enableGesture(Leap::Gesture::TYPE_CIRCLE);
    controller.enableGesture(Leap::Gesture::TYPE_KEY_TAP);
    controller.enableGesture(Leap::Gesture::TYPE_SCREEN_TAP);
    controller.enableGesture(Leap::Gesture::TYPE_SWIPE);
    
    
    // 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;
                
                sprintf(buff,"/gesture/circle/center/x");
                oleap_bundleMessage(bundle,buff,circle.center().x);
                
                sprintf(buff,"/gesture/circle/center/y");
                oleap_bundleMessage(bundle,buff,circle.center().y);
                
                sprintf(buff,"/gesture/circle/center/z");
                oleap_bundleMessage(bundle,buff,circle.center().z);
                
                sprintf(buff,"/gesture/circle/pitch");
                oleap_bundleMessage(bundle,buff,circle.center().pitch());
                
                sprintf(buff,"/gesture/circle/yaw");
                oleap_bundleMessage(bundle,buff,circle.center().yaw());
                
                sprintf(buff,"/gesture/circle/roll");
                oleap_bundleMessage(bundle,buff,circle.center().roll());
                
                sprintf(buff,"/gesture/circle/radius");
                oleap_bundleMessage(bundle,buff,circle.radius());
                
                sprintf(buff,"/gesture/circle/duration");
                oleap_bundleMessage(bundle,buff,circle.duration());
                
                
                if (circle.pointable().direction().angleTo(circle.normal()) <= Leap::PI/4) {
                    clockwiseness = "clockwise";
                    
                    sprintf(buff,"/gesture/circle/clockwiseness/");
                    oleap_bundleMessage(bundle,buff,1);
                    
                } else {
                    clockwiseness = "counterclockwise";
                    
                    sprintf(buff,"/gesture/circle/clockwiseness/");
                    oleap_bundleMessage(bundle,buff,-1);
                }
                
                
                // Calculate angle swept since last frame
                float sweptAngle = 0;
                if (circle.state() != Leap::Gesture::STATE_START) {
                    Leap::CircleGesture previousUpdate = Leap::CircleGesture(controller.frame(1).gesture(circle.id()));
                    sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * Leap::PI;
                    
                    sprintf(buff,"/gesture/circle/angle/sweep");
                    oleap_bundleMessage(bundle,buff,sweptAngle);
                }
            }
                
            case Leap::Gesture::TYPE_SWIPE:
            {
                Leap::SwipeGesture swipe = gesture;
                int swipe_id = gesture.id();
                int gesture_state = gesture.state();
                Leap::Vector swipe_direction = swipe.direction();
                float swipe_speed = swipe.speed();
                
                ////////////////////////////////Swipe data
//.........这里部分代码省略.........
开发者ID:KevinGutowski,项目名称:o.io.leap,代码行数:101,代码来源:o.io.leap.cpp

示例8: onFrame

void SampleListener::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()
            << ", extended fingers: " << frame.fingers().extended().count()
            << ", tools: " << frame.tools().count()
            << ", gestures: " << frame.gestures().count() << std::endl;

  Leap::HandList hands = frame.hands();
  for (Leap::HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
    // Get the first hand
    const Leap::Hand hand = *hl;
    std::string handType = hand.isLeft() ? "Left hand" : "Right hand";
    std::cout << std::string(2, ' ') << handType << ", id: " << hand.id()
              << ", 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 << std::string(2, ' ') <<  "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 the Arm bone
    Leap::Arm arm = hand.arm();
    std::cout << std::string(2, ' ') <<  "Arm direction: " << arm.direction()
              << " wrist position: " << arm.wristPosition()
              << " elbow position: " << arm.elbowPosition() << std::endl;

    // Get fingers
    const Leap::FingerList fingers = hand.fingers();
    for (Leap::FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
      const Leap::Finger finger = *fl;
      std::cout << std::string(4, ' ') <<  fingerNames[finger.type()]
                << " finger, id: " << finger.id()
                << ", length: " << finger.length()
                << "mm, width: " << finger.width() << std::endl;

      // Get finger bones
      for (int b = 0; b < 4; ++b) {
        Leap::Bone::Type boneType = static_cast<Leap::Bone::Type>(b);
        Leap::Bone bone = finger.bone(boneType);
        std::cout << std::string(6, ' ') <<  boneNames[boneType]
                  << " bone, start: " << bone.prevJoint()
                  << ", end: " << bone.nextJoint()
                  << ", direction: " << bone.direction() << std::endl;
      }
    }
  }

  // Get tools
  const Leap::ToolList tools = frame.tools();
  for (Leap::ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) {
    const Leap::Tool tool = *tl;
    std::cout << std::string(2, ' ') <<  "Tool, id: " << tool.id()
              << ", position: " << tool.tipPosition()
              << ", direction: " << tool.direction() << 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()) <= Leap::PI/2) {
          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(1).gesture(circle.id()));
          sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * Leap::PI;
        }
        std::cout << std::string(2, ' ')
                  << "Circle id: " << gesture.id()
                  << ", state: " << stateNames[gesture.state()]
                  << ", progress: " << circle.progress()
                  << ", radius: " << circle.radius()
                  << ", angle " << sweptAngle * Leap::RAD_TO_DEG
                  <<  ", " << clockwiseness << std::endl;
        break;
      }
      case Leap::Gesture::TYPE_SWIPE:
      {
        Leap::SwipeGesture swipe = gesture;
        std::cout << std::string(2, ' ')
          << "Swipe id: " << gesture.id()
          << ", state: " << stateNames[gesture.state()]
//.........这里部分代码省略.........
开发者ID:RobDeBagel,项目名称:fadecandy,代码行数:101,代码来源:fc_leap.cpp


注:本文中的leap::Hand::direction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。