Created
September 18, 2014 00:00
-
-
Save neptunius/7cdf21d773427517e4fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*================================================================================================================== | |
Copyright (c) 2010 - 2014 Leap Motion. All rights reserved. | |
The intellectual and technical concepts contained herein are proprietary and confidential to Leap Motion, and are | |
protected by trade secret or copyright law. Dissemination of this information or reproduction of this material is | |
strictly forbidden unless prior written permission is obtained from Leap Motion. | |
===================================================================================================================*/ | |
bool BasicMode::shouldBeInPalmSwipeMode () const { | |
static const double COS_X_AXIS_ANGLE_THRESHOLD = 0.75; // the cosine of the angle to the X axis | |
return !DisablePalmSwipe && !m_currentFrame.hands().isEmpty() | |
&& std::abs(m_currentFrame.hands()[0].palmNormal().x) >= COS_X_AXIS_ANGLE_THRESHOLD | |
&& m_currentFrame.hands()[0].palmPosition().z <= 150; | |
} | |
bool BasicMode::State_BasicMode_Palm_GestureRecognition (StateMachineInput input) { | |
switch (input) { | |
case OMB__LOST_FOCUS: | |
BASICMODE_TRANSITION_TO(State_BasicMode_0Pointables_NoInteraction); | |
return true; | |
case SM_ENTER: | |
m_gestureStart = m_currentFrame; | |
case OMB__PROCESS_FRAME: | |
// handle state changes | |
if (!shouldBeInPalmSwipeMode()) { | |
BasicMode_TransitionTo_NPointables_NoInteraction(); | |
} | |
// recognize the gesture | |
if (m_currentFrame.timestamp() - m_gestureStart.timestamp() >= 100*MILLISECONDS | |
&& rtsIsUnambiguous() && rts() == TRANSLATING) { | |
BASICMODE_TRANSITION_TO(State_BasicMode_Palm_Swipe); | |
} | |
return true; | |
case SM_EXIT: | |
return true; | |
} | |
return false; // MUST return false if an event was not handled. | |
} | |
bool BasicMode::State_BasicMode_Palm_Swipe (StateMachineInput input) { | |
switch (input) { | |
case OMB__LOST_FOCUS: | |
BASICMODE_TRANSITION_TO(State_BasicMode_0Pointables_NoInteraction); | |
return true; | |
case SM_ENTER: | |
beginGesture(LPGesture::GestureDesktopSwipeHorizontal); | |
return true; | |
case SM_EXIT: | |
endGesture(); | |
return true; | |
case OMB__PROCESS_FRAME: | |
// handle state changes | |
if (!shouldBeInPalmSwipeMode()) { | |
BasicMode_TransitionTo_NPointables_NoInteraction(); | |
} | |
// apply desktop swipe | |
generateDesktopSwipeBetweenFrames(m_currentFrame, m_sinceFrame); | |
return true; | |
} | |
return false; // MUST return false if an event was not handled. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment