leapMotionFrame.h
Engine/source/platform/input/leapMotion/leapMotionFrame.h
Classes:
class
Public Typedefs
LeapMotionFramePointableType
Public Functions
Detailed Description
Public Typedefs
typedef LeapMotionFrame::PointableType LeapMotionFramePointableType
Public Functions
DefineEnumType(LeapMotionFramePointableType )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _LEAPMOTIONFRAME_H_ 25#define _LEAPMOTIONFRAME_H_ 26 27#include "console/simObject.h" 28#include "math/mPoint3.h" 29#include "math/mMatrix.h" 30#include "math/mQuat.h" 31#include "Leap.h" 32 33class LeapMotionFrame : public SimObject 34{ 35 typedef SimObject Parent; 36 37public: 38 enum PointableType 39 { 40 PT_UNKNOWN = -1, 41 PT_FINGER = 0, 42 PT_TOOL, 43 }; 44 45protected: 46 static U32 smNextInternalFrameId; 47 48 // Frame 49 bool mFrameValid; 50 U64 mFrameId; 51 U64 mFrameTimeStamp; 52 53 // Torque 3D frame information 54 U32 mFrameInternalId; 55 S32 mFrameSimTime; 56 S32 mFrameRealTime; 57 58 // Hands 59 U32 mHandCount; 60 Vector<bool> mHandValid; 61 Vector<S32> mHandId; 62 Vector<Point3F> mHandRawPos; 63 Vector<Point3I> mHandPos; 64 Vector<MatrixF> mHandRot; 65 Vector<QuatF> mHandRotQuat; 66 Vector<Point2F> mHandRotAxis; 67 Vector<U32> mHandPointablesCount; 68 69 // Pointables 70 U32 mPointableCount; 71 Vector<bool> mPointableValid; 72 Vector<S32> mPointableId; 73 Vector<S32> mPointableHandIndex; 74 Vector<PointableType> mPointableType; 75 Vector<Point3F> mPointableRawPos; 76 Vector<Point3I> mPointablePos; 77 Vector<MatrixF> mPointableRot; 78 Vector<QuatF> mPointableRotQuat; 79 Vector<F32> mPointableLength; 80 Vector<F32> mPointableWidth; 81 82protected: 83 void copyFromFrameHands(const Leap::HandList& hands, const F32& maxHandAxisRadius); 84 void copyFromFramePointables(const Leap::PointableList& pointables); 85 86public: 87 LeapMotionFrame(); 88 virtual ~LeapMotionFrame(); 89 90 static void initPersistFields(); 91 92 virtual bool onAdd(); 93 virtual void onRemove(); 94 95 void clear(); 96 97 /// Copy a Leap Frame into our data structures 98 void copyFromFrame(const Leap::Frame& frame, const F32& maxHandAxisRadius); 99 100 // Frame 101 bool isFrameValid() const { return mFrameValid; } 102 U32 getFrameInternalId() const { return mFrameInternalId; } 103 S32 getFrameSimTime() const { return mFrameSimTime; } 104 S32 getFrameRealTime() const { return mFrameRealTime; } 105 106 // Hands 107 U32 getHandCount() const { return mHandCount; } 108 bool getHandValid(U32 index) const; 109 S32 getHandId(U32 index) const; 110 const Point3F& getHandRawPos(U32 index) const; 111 const Point3I& getHandPos(U32 index) const; 112 const MatrixF& getHandRot(U32 index) const; 113 const QuatF& getHandRotQuat(U32 index) const; 114 const Point2F& getHandRotAxis(U32 index) const; 115 U32 getHandPointablesCount(U32 index) const; 116 117 // Pointables 118 U32 getPointablesCount() const { return mPointableCount; } 119 bool getPointableValid(U32 index) const; 120 S32 getPointableId(U32 index) const; 121 S32 getPointableHandIndex(U32 index) const; 122 PointableType getPointableType(U32 index) const; 123 const Point3F& getPointableRawPos(U32 index) const; 124 const Point3I& getPointablePos(U32 index) const; 125 const MatrixF& getPointableRot(U32 index) const; 126 const QuatF& getPointableRotQuat(U32 index) const; 127 F32 getPointableLength(U32 index) const; 128 F32 getPointableWidth(U32 index) const; 129 130 DECLARE_CONOBJECT(LeapMotionFrame); 131}; 132 133typedef LeapMotionFrame::PointableType LeapMotionFramePointableType; 134DefineEnumType( LeapMotionFramePointableType ); 135 136//----------------------------------------------------------------------------- 137 138inline bool LeapMotionFrame::getHandValid(U32 index) const 139{ 140 return (index < mHandCount && mHandValid[index]); 141} 142 143inline S32 LeapMotionFrame::getHandId(U32 index) const 144{ 145 return (index >= mHandCount) ? -1 : mHandId[index]; 146} 147 148inline const Point3F& LeapMotionFrame::getHandRawPos(U32 index) const 149{ 150 return (index >= mHandCount) ? Point3F::Zero : mHandRawPos[index]; 151} 152 153inline const Point3I& LeapMotionFrame::getHandPos(U32 index) const 154{ 155 return (index >= mHandCount) ? Point3I::Zero : mHandPos[index]; 156} 157 158inline const MatrixF& LeapMotionFrame::getHandRot(U32 index) const 159{ 160 return (index >= mHandCount) ? MatrixF::Identity : mHandRot[index]; 161} 162 163inline const QuatF& LeapMotionFrame::getHandRotQuat(U32 index) const 164{ 165 return (index >= mHandCount) ? QuatF::Identity : mHandRotQuat[index]; 166} 167 168inline const Point2F& LeapMotionFrame::getHandRotAxis(U32 index) const 169{ 170 return (index >= mHandCount) ? Point2F::Zero : mHandRotAxis[index]; 171} 172 173inline U32 LeapMotionFrame::getHandPointablesCount(U32 index) const 174{ 175 return (index >= mHandCount) ? 0 : mHandPointablesCount[index]; 176} 177 178inline bool LeapMotionFrame::getPointableValid(U32 index) const 179{ 180 return (index < mPointableCount && mPointableValid[index]); 181} 182 183inline S32 LeapMotionFrame::getPointableId(U32 index) const 184{ 185 return (index >= mPointableCount) ? -1 : mPointableId[index]; 186} 187 188inline S32 LeapMotionFrame::getPointableHandIndex(U32 index) const 189{ 190 return (index >= mPointableCount) ? -1 : mPointableHandIndex[index]; 191} 192 193inline LeapMotionFrame::PointableType LeapMotionFrame::getPointableType(U32 index) const 194{ 195 return (index >= mPointableCount) ? PT_UNKNOWN : mPointableType[index]; 196} 197 198inline const Point3F& LeapMotionFrame::getPointableRawPos(U32 index) const 199{ 200 return (index >= mPointableCount) ? Point3F::Zero : mPointableRawPos[index]; 201} 202 203inline const Point3I& LeapMotionFrame::getPointablePos(U32 index) const 204{ 205 return (index >= mPointableCount) ? Point3I::Zero : mPointablePos[index]; 206} 207 208inline const MatrixF& LeapMotionFrame::getPointableRot(U32 index) const 209{ 210 return (index >= mPointableCount) ? MatrixF::Identity : mPointableRot[index]; 211} 212 213inline const QuatF& LeapMotionFrame::getPointableRotQuat(U32 index) const 214{ 215 return (index >= mPointableCount) ? QuatF::Identity : mPointableRotQuat[index]; 216} 217 218inline F32 LeapMotionFrame::getPointableLength(U32 index) const 219{ 220 return (index >= mPointableCount) ? 0.0f : mPointableLength[index]; 221} 222 223inline F32 LeapMotionFrame::getPointableWidth(U32 index) const 224{ 225 return (index >= mPointableCount) ? 0.0f : mPointableWidth[index]; 226} 227 228#endif // _LEAPMOTIONFRAME_H_ 229