Exemple #1
0
void Quickstart::onFrame(const Leap::Controller &controller) {
    // returns the most recent frame. older frames can be accessed by passing in 
    // a "history" parameter to retrieve an older frame, up to about 60
    // (exact number subject to change)
    const Leap::Frame frame = controller.frame();

    // do nothing unless hands are detected
    if (frame.hands().empty())
        return;
    
    // first detected hand
    const Leap::Hand firstHand = frame.hands()[0];
    // first pointable object (finger or tool)
    const Leap::PointableList pointables = firstHand.pointables();
    if (pointables.empty()) return;
    const Leap::Pointable firstPointable = pointables[0];
    
    // print velocity on the X axis
    cout << "Pointable X velocity: " << firstPointable.tipVelocity()[0] << endl;
    
    const Leap::FingerList fingers = firstHand.fingers();
    if (fingers.empty()) return;
    
    for (int i = 0; i < fingers.count(); i++) {
        const Leap::Finger finger = fingers[i];
        
        std::cout << "Detected finger " << i << " at position (" <<
            finger.tipPosition().x << ", " <<
            finger.tipPosition().y << ", " <<
            finger.tipPosition().z << ")" << std::endl;
    }
}
void FubiLeapSensor::getFingerTrackingData(int handID, SkeletonHandJoint::Joint joint,
	Fubi::SkeletonJointPosition& position, Fubi::SkeletonJointOrientation& orientation)
{
	bool fingerFound = false;
	if (m_currFrame.isValid())
	{
		const Leap::Hand& h = m_currFrame.hand(handID);
		if (h.isValid())
		{
			Leap::Vector pos;
			float roll, yaw, pitch;

			if (joint == SkeletonHandJoint::PALM)
			{
				fingerFound = true;
				pos = h.palmPosition();
				roll = h.direction().roll();
				yaw = h.direction().yaw();
				pitch = h.direction().pitch();
			}
			else
			{
				int fingerIndex = joint - 1;
				Leap::FingerList fingers = h.fingers();
				if (fingerIndex < fingers.count())
				{
					const Leap::Finger& f = fingers[fingerIndex];
					if (f.isValid())
					{
						fingerFound = true;
						pos = f.tipPosition();
						roll = f.direction().roll();
						yaw = f.direction().yaw();
						pitch = f.direction().pitch();
					}
				}
			}

			if (fingerFound)
			{
				position.m_confidence = h.confidence();
				position.m_position.x = pos.x + m_offsetPos.x;
				position.m_position.y = pos.y + m_offsetPos.y;
				position.m_position.z = pos.z + m_offsetPos.z;

				orientation.m_confidence = h.confidence();
				orientation.m_orientation = Matrix3f::RotMat(pitch, -yaw, -(roll+Math::Pi));
			}
		}
	}

	if (!fingerFound)
	{
		// not found so reset the confidence
		position.m_confidence = 0;
		orientation.m_confidence = 0;
	}
}
void LeapCinderVectorFieldApp::processFingers()
{
	Leap::Frame frame = m_LeapController.frame();
	Leap::FingerList fingers = frame.fingers();

	m_VectorField->ClearPointTo();

	for( int i = 0; i < fingers.count(); i++ )
	{
		m_VectorField->CheckPointTo( normalizeCoords( fingers[i].tipPosition() ) );
	}
}
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();
}
Exemple #5
0
//Main Event driven tick
void ULeapController::InterfaceEventTick(float DeltaTime)
{
	//This is our tick event that is forwarded from the delegate, check validity
	if (!_private->interfaceDelegate) return;

	//Pointers
	Leap::Frame frame = _private->leap.frame();
	Leap::Frame pastFrame = _private->leap.frame(1);

	//-Hands-

	//Hand Count
	int handCount = frame.hands().count();

	if (_private->pastState.handCount != handCount)
	{
		ILeapEventInterface::Execute_HandCountChanged(_private->interfaceDelegate, handCount);
		
		//Zero our input mapping orientations (akin to letting go of a joystick)
		if (handCount == 0)
		{
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmPitch, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmYaw, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmRoll, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmPitch, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmYaw, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmRoll, 0, 0, 0);
		}
	}

	//Cycle through each hand
	for (int i = 0; i < handCount; i++)
	{
		Leap::Hand hand = frame.hands()[i];
		LeapHandStateData pastHandState = _private->pastState.stateForId(hand.id());		//we use a custom class to hold reliable state tracking based on id's

		//Make a ULeapHand
		if (_private->eventHand == NULL)
		{
			_private->eventHand = NewObject<ULeapHand>(this);
			_private->eventHand->SetFlags(RF_RootSet);
		}
		_private->eventHand->setHand(hand);

		//Emit hand
		ILeapEventInterface::Execute_LeapHandMoved(_private->interfaceDelegate, _private->eventHand);

		//Left/Right hand forwarding
		if (hand.isRight())
		{
			ILeapEventInterface::Execute_LeapRightHandMoved(_private->interfaceDelegate, _private->eventHand);
			//Input Mapping
			FRotator palmOrientation = _private->eventHand->PalmOrientation;
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmPitch, palmOrientation.Pitch * LEAP_IM_SCALE, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmYaw, palmOrientation.Yaw * LEAP_IM_SCALE, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmRoll, palmOrientation.Roll * LEAP_IM_SCALE, 0, 0);
		} else if (hand.isLeft())
		{
			ILeapEventInterface::Execute_LeapLeftHandMoved(_private->interfaceDelegate, _private->eventHand);
			//Input Mapping
			FRotator palmOrientation = _private->eventHand->PalmOrientation;
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmPitch, palmOrientation.Pitch * LEAP_IM_SCALE, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmYaw, palmOrientation.Yaw * LEAP_IM_SCALE, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmRoll, palmOrientation.Roll * LEAP_IM_SCALE, 0, 0);
		}

		//Grabbing
		float grabStrength = hand.grabStrength();
		bool grabbed = handClosed(grabStrength);

		if (grabbed)
			ILeapEventInterface::Execute_LeapHandGrabbing(_private->interfaceDelegate, grabStrength, _private->eventHand);

		if (grabbed && !pastHandState.grabbed)
		{
			ILeapEventInterface::Execute_LeapHandGrabbed(_private->interfaceDelegate, grabStrength, _private->eventHand);
			
			//input mapping
			if (_private->eventHand->HandType == LeapHandType::HAND_LEFT)
				EmitKeyDownEventForKey(EKeysLeap::LeapLeftGrab, 0, 0);
			else
				EmitKeyDownEventForKey(EKeysLeap::LeapRightGrab, 0, 0);
		}else if (!grabbed && pastHandState.grabbed)
		{
			ILeapEventInterface::Execute_LeapHandReleased(_private->interfaceDelegate, grabStrength, _private->eventHand);

			//input mapping
			if (_private->eventHand->HandType == LeapHandType::HAND_LEFT)
				EmitKeyUpEventForKey(EKeysLeap::LeapLeftGrab, 0, 0);
			else
				EmitKeyUpEventForKey(EKeysLeap::LeapRightGrab, 0, 0);
		}

		//Pinching
		float pinchStrength = hand.pinchStrength();
		bool pinched = handPinched(pinchStrength);

		//While grabbing disable pinching detection, this helps to reduce spam as pose confidence plummets
		if (grabbed) pinched = pastHandState.pinched;
		else
		{
			if (pinched)
				ILeapEventInterface::Execute_LeapHandPinching(_private->interfaceDelegate, pinchStrength, _private->eventHand);

			if (pinched && !pastHandState.pinched)
			{
				ILeapEventInterface::Execute_LeapHandPinched(_private->interfaceDelegate, pinchStrength, _private->eventHand);
				//input mapping
				if (_private->eventHand->HandType == LeapHandType::HAND_LEFT)
					EmitKeyDownEventForKey(EKeysLeap::LeapLeftPinch, 0, 0);
				else
					EmitKeyDownEventForKey(EKeysLeap::LeapRightPinch, 0, 0);
			}
			else if (!pinched && pastHandState.pinched)
			{
				ILeapEventInterface::Execute_LeapHandUnpinched(_private->interfaceDelegate, pinchStrength, _private->eventHand);
				//input mapping
				if (_private->eventHand->HandType == LeapHandType::HAND_LEFT)
					EmitKeyUpEventForKey(EKeysLeap::LeapLeftPinch, 0, 0);
				else
					EmitKeyUpEventForKey(EKeysLeap::LeapRightPinch, 0, 0);
			}
		}

		//-Fingers-
		Leap::FingerList fingers = hand.fingers();

		//Count
		int fingerCount = fingers.count();
		if ((pastHandState.fingerCount != fingerCount))
			ILeapEventInterface::Execute_FingerCountChanged(_private->interfaceDelegate, fingerCount);

		if (_private->eventFinger == NULL)
		{
			_private->eventFinger = NewObject<ULeapFinger>(this);
			_private->eventFinger->SetFlags(RF_RootSet);
		}

		Leap::Finger finger;

		//Cycle through each finger
		for (int j = 0; j < fingerCount; j++)
		{
			finger = fingers[j];
			_private->eventFinger->setFinger(finger);

			//Finger Moved
			if (finger.isValid())
				ILeapEventInterface::Execute_LeapFingerMoved(_private->interfaceDelegate, _private->eventFinger);
		}

		//Do these last so we can easily override debug shapes

		//Leftmost
		finger = fingers.leftmost();
		_private->eventFinger->setFinger(finger);
		ILeapEventInterface::Execute_LeapLeftMostFingerMoved(_private->interfaceDelegate, _private->eventFinger);

		//Rightmost
		finger = fingers.rightmost();
		_private->eventFinger->setFinger(finger);
		ILeapEventInterface::Execute_LeapRightMostFingerMoved(_private->interfaceDelegate, _private->eventFinger);

		//Frontmost
		finger = fingers.frontmost();
		_private->eventFinger->setFinger(finger);
		ILeapEventInterface::Execute_LeapFrontMostFingerMoved(_private->interfaceDelegate, _private->eventFinger);

		//touch only for front-most finger, most common use case
		float touchDistance = finger.touchDistance();
		if (touchDistance <= 0.f)
			ILeapEventInterface::Execute_LeapFrontFingerTouch(_private->interfaceDelegate, _private->eventFinger);

		//Set the state data for next cycle
		pastHandState.grabbed = grabbed;
		pastHandState.pinched = pinched;
		pastHandState.fingerCount = fingerCount;

		_private->pastState.setStateForId(pastHandState, hand.id());
	}

	_private->pastState.handCount = handCount;

	//Gestures
	for (int i = 0; i < frame.gestures().count(); i++)
	{
		Leap::Gesture gesture = frame.gestures()[i];
		Leap::Gesture::Type type = gesture.type();

		switch (type)
		{
		case Leap::Gesture::TYPE_CIRCLE:
			if (_private->eventCircleGesture == NULL){
				_private->eventCircleGesture = NewObject<ULeapCircleGesture>(this);
				_private->eventCircleGesture->SetFlags(RF_RootSet);
			}
			_private->eventCircleGesture->setGesture(Leap::CircleGesture(gesture));
			ILeapEventInterface::Execute_CircleGestureDetected(_private->interfaceDelegate, _private->eventCircleGesture);
			_private->eventGesture = _private->eventCircleGesture;
			break;
		case Leap::Gesture::TYPE_KEY_TAP:
			if (_private->eventKeyTapGesture == NULL)
			{
				_private->eventKeyTapGesture = NewObject<ULeapKeyTapGesture>(this);
				_private->eventKeyTapGesture->SetFlags(RF_RootSet);
			}
			_private->eventKeyTapGesture->setGesture(Leap::KeyTapGesture(gesture));
			ILeapEventInterface::Execute_KeyTapGestureDetected(_private->interfaceDelegate, _private->eventKeyTapGesture);
			_private->eventGesture = _private->eventKeyTapGesture;
			break;
		case Leap::Gesture::TYPE_SCREEN_TAP:
			if (_private->eventScreenTapGesture == NULL)
			{
				_private->eventScreenTapGesture = NewObject<ULeapScreenTapGesture>(this);
				_private->eventScreenTapGesture->SetFlags(RF_RootSet);
			}
			_private->eventScreenTapGesture->setGesture(Leap::ScreenTapGesture(gesture));
			ILeapEventInterface::Execute_ScreenTapGestureDetected(_private->interfaceDelegate, _private->eventScreenTapGesture);
			_private->eventGesture = _private->eventScreenTapGesture;
			break;
		case Leap::Gesture::TYPE_SWIPE:
			if (_private->eventSwipeGesture == NULL)
			{
				_private->eventSwipeGesture = NewObject<ULeapSwipeGesture>(this);
				_private->eventSwipeGesture->SetFlags(RF_RootSet);
			}
			_private->eventSwipeGesture->setGesture(Leap::SwipeGesture(gesture));
			ILeapEventInterface::Execute_SwipeGestureDetected(_private->interfaceDelegate, _private->eventSwipeGesture);
			_private->eventGesture = _private->eventSwipeGesture;
			break;
		default:
			break;
		}

		//emit gesture
		if (type != Leap::Gesture::TYPE_INVALID)
		{
			ILeapEventInterface::Execute_GestureDetected(_private->interfaceDelegate, _private->eventGesture);
		}
	}

	//Image
	if (_private->allowImages && _private->imageEventsEnabled)
	{
		int imageCount = frame.images().count();
		for (int i = 0; i < imageCount; i++)
		{
			Leap::Image image = frame.images()[i];

			//Loop modification - Only emit 0 and 1, use two different pointers so we can get different images
			if (i == 0)
			{
				if (_private->eventImage1 == NULL)
				{
					_private->eventImage1 = NewObject<ULeapImage>(this);
					_private->eventImage1->SetFlags(RF_RootSet);
				}
				_private->eventImage1->setLeapImage(image);

				ILeapEventInterface::Execute_RawImageReceived(_private->interfaceDelegate, _private->eventImage1->Texture(), _private->eventImage1);
			}
			else if (i == 1)
			{
				if (_private->eventImage2 == NULL)
                {
					_private->eventImage2 = NewObject<ULeapImage>(this);
					_private->eventImage2->SetFlags(RF_RootSet);
				}
				_private->eventImage2->setLeapImage(image);

				ILeapEventInterface::Execute_RawImageReceived(_private->interfaceDelegate, _private->eventImage2->Texture(), _private->eventImage2);
			}
		}
	}
}
Exemple #6
0
//--------------------------------------------------------------
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();
    
    
}
void FLeapMotionInputDevice::ParseEvents()
{
	//Optimization: If we don't have any delegates, skip
	if (EventDelegates.Num() == 0)
	{
		return;
	}

	//Pointers
	Leap::Frame Frame = ControllerData.LeapController.frame();
	Leap::Frame PastFrame = ControllerData.LeapController.frame(1);

	//Calculate HMD Timewarp if valid
	if (GEngine->HMDDevice.IsValid() && ControllerData.bTimeWarpEnabled) {
		LeapHMDSnapshot ThenSnapshot = HMDSamples->HMDSampleClosestToTimestamp(Frame.timestamp());
		LeapHMDSnapshot NowSnapShot = HMDSamples->CurrentHMDSample();

		LeapHMDSnapshot HistorySnapshot = HMDSamples->LastHMDSample();	//reduce jitter
		//ControllerData.TimeWarpSnapshot = NowSnapShot.Difference(ThenSnapshot, ControllerData.TimeWarpFactor);// * ControllerData.TimeWarpFactor;

		FQuat WarpQuat = NowSnapShot.Orientation;//FQuat::Slerp(NowSnapShot.Orientation, HistorySnapshot.Orientation, ControllerData.TimeWarpTween);
		FQuat ThenTweened = FQuat::Slerp(ThenSnapshot.Orientation, HistorySnapshot.Orientation, ControllerData.TimeWarpTween);

		ControllerData.TimeWarpSnapshot.Orientation = (WarpQuat.Inverse() * ControllerData.TimeWarpFactor) * ThenTweened;

		ControllerData.TimeWarpAmountMs = (ControllerData.TimeWarpSnapshot.Timestamp) / 1000.f;
	}

	//-Hands-

	//Hand Count
	int HandCount = Frame.hands().count();

	if (PastState->HandCount != HandCount)
	{
		CallFunctionOnDelegates([&](UObject* EventDelegate)
		{
			ILeapEventInterface::Execute_HandCountChanged(EventDelegate, HandCount);
		});
		//Zero our input mapping orientations (akin to letting go of a joystick)
		if (HandCount == 0)
		{
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmPitch, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmYaw, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmRoll, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmPitch, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmYaw, 0, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmRoll, 0, 0, 0);
		}
	}

	//Cycle through each hand
	for (int i = 0; i < HandCount; i++)
	{
		Leap::Hand Hand = Frame.hands()[i];
		LeapHandStateData PastHandState = PastState->StateForId(Hand.id());		//we use a custom class to hold reliable state tracking based on id's

																				//Make a ULeapHand
		if (PEventHand == nullptr)
		{
			PEventHand = NewObject<ULeapHand>();
			PEventHand->AddToRoot();
		}
		PEventHand->SetHand(Hand);

		//Emit hand
		CallFunctionOnDelegates([&](UObject* EventDelegate)
		{
			ILeapEventInterface::Execute_LeapHandMoved(EventDelegate, PEventHand);
		});


		//Left/Right hand forwarding
		if (Hand.isRight())
		{
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_LeapRightHandMoved(EventDelegate, PEventHand);
			});

			//Input Mapping
			FRotator PalmOrientation = PEventHand->PalmOrientation;
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmPitch, PalmOrientation.Pitch * LEAP_IM_SCALE, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmYaw, PalmOrientation.Yaw * LEAP_IM_SCALE, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapRightPalmRoll, PalmOrientation.Roll * LEAP_IM_SCALE, 0, 0);
		}
		else if (Hand.isLeft())
		{
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_LeapLeftHandMoved(EventDelegate, PEventHand);
			});

			//Input Mapping
			FRotator PalmOrientation = PEventHand->PalmOrientation;
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmPitch, PalmOrientation.Pitch * LEAP_IM_SCALE, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmYaw, PalmOrientation.Yaw * LEAP_IM_SCALE, 0, 0);
			EmitAnalogInputEventForKey(EKeysLeap::LeapLeftPalmRoll, PalmOrientation.Roll * LEAP_IM_SCALE, 0, 0);
		}

		//Grabbing
		float GrabStrength = Hand.grabStrength();
		bool Grabbed = HandClosed(GrabStrength);

		if (Grabbed)
		{
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_LeapHandGrabbing(EventDelegate, GrabStrength, PEventHand);
			});

		}

		if (Grabbed && !PastHandState.Grabbed)
		{
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_LeapHandGrabbed(EventDelegate, GrabStrength, PEventHand);
			});

			//input mapping
			if (PEventHand->HandType == LeapHandType::HAND_LEFT)
			{
				EmitKeyDownEventForKey(EKeysLeap::LeapLeftGrab, 0, 0);
			}
			else
			{
				EmitKeyDownEventForKey(EKeysLeap::LeapRightGrab, 0, 0);
			}
		}
		else if (!Grabbed && PastHandState.Grabbed)
		{
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_LeapHandReleased(EventDelegate, GrabStrength, PEventHand);
			});

			//input mapping
			if (PEventHand->HandType == LeapHandType::HAND_LEFT)
			{
				EmitKeyUpEventForKey(EKeysLeap::LeapLeftGrab, 0, 0);
			}
			else
			{
				EmitKeyUpEventForKey(EKeysLeap::LeapRightGrab, 0, 0);
			}
		}

		//Pinching
		float PinchStrength = Hand.pinchStrength();
		bool Pinched = HandPinched(PinchStrength);

		//While grabbing disable pinching detection, this helps to reduce spam as pose confidence plummets
		if (Grabbed)
		{
			Pinched = PastHandState.Pinched;
		}
		else
		{
			if (Pinched)
			{
				CallFunctionOnDelegates([&](UObject* EventDelegate)
				{
					ILeapEventInterface::Execute_LeapHandPinching(EventDelegate, PinchStrength, PEventHand);
				});
			}
			if (Pinched && !PastHandState.Pinched)
			{
				CallFunctionOnDelegates([&](UObject* EventDelegate)
				{
					ILeapEventInterface::Execute_LeapHandPinched(EventDelegate, PinchStrength, PEventHand);
				});
				//input mapping
				if (PEventHand->HandType == LeapHandType::HAND_LEFT)
				{
					EmitKeyDownEventForKey(EKeysLeap::LeapLeftPinch, 0, 0);
				}
				else
				{
					EmitKeyDownEventForKey(EKeysLeap::LeapRightPinch, 0, 0);
				}
			}
			else if (!Pinched && PastHandState.Pinched)
			{
				CallFunctionOnDelegates([&](UObject* EventDelegate)
				{
					ILeapEventInterface::Execute_LeapHandUnpinched(EventDelegate, PinchStrength, PEventHand);
				});
				//input mapping
				if (PEventHand->HandType == LeapHandType::HAND_LEFT)
				{
					EmitKeyUpEventForKey(EKeysLeap::LeapLeftPinch, 0, 0);
				}
				else
				{
					EmitKeyUpEventForKey(EKeysLeap::LeapRightPinch, 0, 0);
				}
			}
		}

		//-Fingers-
		Leap::FingerList Fingers = Hand.fingers();

		//Count
		int FingerCount = Fingers.count();
		if ((PastHandState.FingerCount != FingerCount))
		{
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_FingerCountChanged(EventDelegate, FingerCount);
			});
		}
		if (PEventFinger == nullptr)
		{
			PEventFinger = NewObject<ULeapFinger>();
			PEventFinger->AddToRoot();
		}

		Leap::Finger Finger;

		//Cycle through each finger
		for (int j = 0; j < FingerCount; j++)
		{
			Finger = Fingers[j];
			PEventFinger->SetFinger(Finger);

			//Finger Moved
			if (Finger.isValid())
			{
				CallFunctionOnDelegates([&](UObject* EventDelegate)
				{
					ILeapEventInterface::Execute_LeapFingerMoved(EventDelegate, PEventFinger);
				});
			}
		}

		//Do these last so we can easily override debug shapes

		//Leftmost
		Finger = Fingers.leftmost();
		PEventFinger->SetFinger(Finger);
		CallFunctionOnDelegates([&](UObject* EventDelegate)
		{
			ILeapEventInterface::Execute_LeapLeftMostFingerMoved(EventDelegate, PEventFinger);
		});

		//Rightmost
		Finger = Fingers.rightmost();
		PEventFinger->SetFinger(Finger);
		CallFunctionOnDelegates([&](UObject* EventDelegate)
		{
			ILeapEventInterface::Execute_LeapRightMostFingerMoved(EventDelegate, PEventFinger);
		});

		//Frontmost
		Finger = Fingers.frontmost();
		PEventFinger->SetFinger(Finger);
		CallFunctionOnDelegates([&](UObject* EventDelegate)
		{
			ILeapEventInterface::Execute_LeapFrontMostFingerMoved(EventDelegate, PEventFinger);
		});

		//touch only for front-most finger, most common use case
		float touchDistance = Finger.touchDistance();
		if (touchDistance <= 0.f)
		{
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_LeapFrontFingerTouch(EventDelegate, PEventFinger);
			});
		}

		//Set the state data for next cycle
		PastHandState.Grabbed = Grabbed;
		PastHandState.Pinched = Pinched;
		PastHandState.FingerCount = FingerCount;

		PastState->SetStateForId(PastHandState, Hand.id());
	}

	PastState->HandCount = HandCount;

	//Gestures
	for (int i = 0; i < Frame.gestures().count(); i++)
	{
		Leap::Gesture Gesture = Frame.gestures()[i];
		Leap::Gesture::Type Type = Gesture.type();

		switch (Type)
		{
		case Leap::Gesture::TYPE_CIRCLE:
			if (PEventCircleGesture == nullptr)
			{
				PEventCircleGesture = NewObject<ULeapCircleGesture>();
				PEventCircleGesture->AddToRoot();
			}
			PEventCircleGesture->SetGesture(Leap::CircleGesture(Gesture));
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_CircleGestureDetected(EventDelegate, PEventCircleGesture);
			});
			PEventGesture = PEventCircleGesture;
			break;
		case Leap::Gesture::TYPE_KEY_TAP:
			if (PEventKeyTapGesture == nullptr)
			{
				PEventKeyTapGesture = NewObject<ULeapKeyTapGesture>();
				PEventKeyTapGesture->AddToRoot();
			}
			PEventKeyTapGesture->SetGesture(Leap::KeyTapGesture(Gesture));
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_KeyTapGestureDetected(EventDelegate, PEventKeyTapGesture);
			});
			PEventGesture = PEventKeyTapGesture;
			break;
		case Leap::Gesture::TYPE_SCREEN_TAP:
			if (PEventScreenTapGesture == nullptr)
			{
				PEventScreenTapGesture = NewObject<ULeapScreenTapGesture>();
				PEventScreenTapGesture->AddToRoot();
			}
			PEventScreenTapGesture->SetGesture(Leap::ScreenTapGesture(Gesture));
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_ScreenTapGestureDetected(EventDelegate, PEventScreenTapGesture);
			});
			PEventGesture = PEventScreenTapGesture;
			break;
		case Leap::Gesture::TYPE_SWIPE:
			if (PEventSwipeGesture == nullptr)
			{
				PEventSwipeGesture = NewObject<ULeapSwipeGesture>();
				PEventSwipeGesture->AddToRoot();
			}
			PEventSwipeGesture->SetGesture(Leap::SwipeGesture(Gesture));
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_SwipeGestureDetected(EventDelegate, PEventSwipeGesture);
			});
			PEventGesture = PEventSwipeGesture;
			break;
		default:
			break;
		}

		//emit gesture
		if (Type != Leap::Gesture::TYPE_INVALID)
		{
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_GestureDetected(EventDelegate, PEventGesture);
			});
		}
	}

	//Image
	if (ControllerData.bAllowImageEvents && ControllerData.bImageEventsEnabled)
	{
		int ImageCount = Frame.images().count();

		//We only support getting both images
		if (ImageCount >= 2)
		{
			Leap::Image Image1 = Frame.images()[0];
			if (PEventImage1 == nullptr)
			{
				PEventImage1 = NewObject<ULeapImage>();
				PEventImage1->AddToRoot();
			}
			PEventImage1->UseGammaCorrection = ControllerData.bUseGammaCorrection;
			PEventImage1->SetLeapImage(Image1);

			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_RawImageReceived(EventDelegate, PEventImage1->Texture(), PEventImage1);
			});

			Leap::Image Image2 = Frame.images()[1];
			if (PEventImage2 == nullptr)
			{
				PEventImage2 = NewObject<ULeapImage>();
				PEventImage2->AddToRoot();
			}
			PEventImage2->UseGammaCorrection = ControllerData.bUseGammaCorrection;
			PEventImage2->SetLeapImage(Image2);

			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_RawImageReceived(EventDelegate, PEventImage2->Texture(), PEventImage2);
			});
		}
	}
}