//----------------------------------------------------------------------------- // Copyright (c) 2012 GarageGames, LLC // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. //----------------------------------------------------------------------------- #include "platform/input/leapMotion/leapMotionData.h" #include "platform/input/leapMotion/leapMotionUtil.h" LeapMotionDeviceData::LeapMotionDeviceData() { reset(); } void LeapMotionDeviceData::reset() { mDataSet = false; mIsValid = false; mHasTrackingData = false; for(U32 i=0; i 0 || frame.pointables().count() > 0; const Leap::HandList hands = frame.hands(); // Check if the hand index needs to persist between frames, but only if the // previous data is valid if(keepHandIndexPersistent && prevData && prevData->mDataSet && prevData->mIsValid) { processPersistentHands(frame.hands(), keepPointableIndexPersistent, prevData); } else { processHands(frame.hands()); } // Single hand rotation as axis if(mHandValid[0]) { Point2F axis; LeapMotionUtil::calculateHandAxisRotation(mHandRot[0], maxHandAxisRadius, axis); mHandRotAxis[0] = axis.x; mHandRotAxis[1] = axis.y; } else { // The first hand is not valid so we reset the axis rotation to none mHandRotAxis[0] = 0.0f; mHandRotAxis[1] = 0.0f; } // Store the current sequence number mSequenceNum = frame.id(); mDataSet = true; } void LeapMotionDeviceData::processPersistentHands(const Leap::HandList& hands, bool keepPointableIndexPersistent, LeapMotionDeviceData* prevData) { S32 numHands = hands.count(); static S32 handDataIndex[LeapMotionConstants::MaxHands]; static bool handIndexUsed[LeapMotionConstants::MaxHands]; static Vector frameHandFound; // Clear out our lookup arrays for(U32 i=0; imHandValid[j] && hand.id() == prevData->mHandID[j]) { handDataIndex[j] = i; frameHandFound[i] = j; } } } // Process all hands that were present in the last frame for(U32 i=0; i framePointableFound; // Clear out our lookup arrays for(U32 i=0; imPointableValid[handIndex][j] && pointable.id() == prevData->mPointableID[handIndex][j]) { pointableDataIndex[j] = i; framePointableFound[i] = j; } } } // Process all hand pointables that were present in the last frame for(U32 i=0; imHandRotAxis[0] || !mDataSet) { result |= DIFF_HANDROTAXISX; } if(mHandRotAxis[1] != other->mHandRotAxis[1] || !mDataSet) { result |= DIFF_HANDROTAXISY; } return result; } U32 LeapMotionDeviceData::compareMeta(LeapMotionDeviceData* other) { S32 result = DIFF_NONE; if(mHasTrackingData != other->mHasTrackingData || !mDataSet) { result |= METADIFF_FRAME_VALID_DATA; } return result; }