Project

General

Profile

LeapMotion Scol plugin
sLeapMotion.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OpenSpace3D
4 For the latest info, see http://www.openspace3d.com
5 
6 Copyright (c) 2012 I-maginer
7 
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/copyleft/lesser.txt
21 
22 -----------------------------------------------------------------------------
23 */
24 
25 #ifndef S_LEAPMOTION_H
26 #define S_LEAPMOTION_H
27 
28 #include <scolPlugin.h>
29 #include <boost/thread/thread.hpp>
30 #include <boost/bind.hpp>
31 
32 #include <Leap.h>
33 
34 using namespace Leap;
35 
39 class SCbData
40 {
41 public:
42  Vector svec;
43  Vector evec;
44  Vector screenPos;
45  Vector pyr;
46  int id;
47  int handId;
48  float dir;
49  Vector vDir;
50  float fparam;
51  float progress;
52  int state;
53  std::vector<Vector> subVecs;
54 protected:
55 private:
56 
57 public:
58  SCbData()
59  {
60  id = -1;
61  handId = -1;
62  dir = 0.0f;
63  svec = Vector(0.0f, 0.0f, 0.0f);
64  evec = Vector(0.0f, 0.0f, 0.0f);
65  screenPos = Vector(0.0f, 0.0f, 0.0f);
66  pyr = Vector(0.0f, 0.0f, 0.0f);
67  vDir = Vector(0.0f, 0.0f, 0.0f);
68  fparam = 0.0f;
69  progress = 0.0f;
70  state = -1;
71  };
72 
73  ~SCbData() {};
74 protected:
75 private:
76 };
77 
78 class SGesture
79 {
80 public:
81  int id;
82  int handId;
83  int pointableId;
84 protected:
85 private:
86 
87 public:
88  SGesture()
89  {
90  id = -1;
91  handId = -1;
92  pointableId = -1;
93  };
94  SGesture(int nid, int nhandid, int npointableid)
95  {
96  id = nid;
97  handId = nhandid;
98  pointableId = npointableid;
99  };
100 
101  ~SGesture() {};
102 protected:
103 private:
104 };
105 
109 class sLeapMotion : public Listener
110 {
111 public:
112 
113 protected:
114  bool mConnected;
115 
116 private:
117  boost::mutex mMutex;
118  bool mTerminate;
119  bool mTopTracking;
120  bool mInit;
121  Frame mLastFrame;
122  std::vector<std::vector<int> > mLastPointableIds;
123  std::vector<int> mLastHandIds;
124  std::vector<int> mLastToolsIds;
125  int mLastGestureTick;
126  std::vector<SGesture> mGestureList;
127 
128  Controller mController;
129 public:
133  sLeapMotion();
134 
138  ~sLeapMotion();
139 
140  void Init();
141  virtual void onInit(const Controller&);
142  virtual void onConnect(const Controller&);
143  virtual void onDisconnect(const Controller&);
144  virtual void onExit(const Controller&);
145  virtual void onFrame(const Controller&);
146  virtual void onFocusGained(const Controller&);
147  virtual void onFocusLost(const Controller&);
148 
149  bool GetHand(int id, Hand &hand);
150  bool GetLeftHand(Hand &hand);
151  bool GetRightHand(Hand &hand);
152  bool GetHandPosition(const Hand hand, bool optim, Vector &vec);
153  bool GetHandOrientation(const Hand hand, Vector &vec);
154  bool GetHandDirection(const Hand hand, Vector &vec);
155  bool GetHandPalmNormal(const Hand hand, Vector &vec);
156  bool GetHandVelocity(const Hand hand, Vector &vec);
157  std::vector<SCbData> GetHandFingers(const Hand hand, bool optim = false);
158 
159  bool GetTool(int id, Tool &tool);
160  bool GetToolPosition(const Tool tool, bool optim, Vector &vec);
161  bool GetToolOrientation(const Tool tool, Vector &vec);
162  bool GetToolVelocity(const Tool tool, Vector &vec);
163 
164  void DetectHands(const HandList hands);
165  void DetectFingers(const Hand hand);
166  void DetectTools(const ToolList tools);
167  void DetectGestures(const GestureList gestures);
168 
169  void SetTopTrackingEnable(bool state);
170  bool GetTopTrackingEnable();
171 protected:
172 private:
173 };
174 
175 #endif