Torque3D Documentation / _generateds / leapMotionDevice.h

leapMotionDevice.h

Engine/source/platform/input/leapMotion/leapMotionDevice.h

More...

Classes:

Public Defines

define
LEAPMOTIONDEV() <>::instance()

Returns the LeapMotionDevice singleton.

Detailed Description

Public Defines

DEFAULT_MOTION_UNIT() 0
LEAPMOTIONDEV() <>::instance()

Returns the LeapMotionDevice singleton.

  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 _LEAPMOTIONDEVICE_H_
 25#define _LEAPMOTIONDEVICE_H_
 26
 27#include "platform/input/IInputDevice.h"
 28#include "platform/input/event.h"
 29#include "platformWin32/platformWin32.h"
 30#include "core/util/tSingleton.h"
 31#include "math/mQuat.h"
 32#include "platform/input/leapMotion/leapMotionConstants.h"
 33#include "Leap.h"
 34
 35#define DEFAULT_MOTION_UNIT 0
 36
 37struct LeapMotionDeviceData;
 38
 39class LeapMotionDevice : public IInputDevice
 40{
 41protected:
 42   class MotionListener : public Leap::Listener
 43   {
 44   public:
 45      MotionListener() {}
 46      virtual ~MotionListener() {}
 47
 48      virtual void onConnect (const Leap::Controller &controller);
 49      virtual void onDisconnect (const Leap::Controller &controller);
 50   };
 51
 52   /// The connection to the Leap Motion
 53   Leap::Controller* mController;
 54
 55   /// Our Leap Motion listener class
 56   MotionListener* mListener;
 57
 58   /// Used with the LM listener object
 59   void* mActiveMutex;
 60
 61   /// Is the Leap Motion active
 62   bool mActive;
 63
 64   /// Buffer to store data Leap Motion data in a Torque friendly way
 65   LeapMotionDeviceData*  mDataBuffer[2];
 66
 67   /// Points to the buffers that holds the previously collected data
 68   LeapMotionDeviceData*  mPrevData;
 69
 70protected:
 71   /// Build out the codes used for controller actions with the
 72   /// Input Event Manager
 73   void buildCodeTable();
 74
 75public:
 76   static bool smEnableDevice;
 77
 78   // Indicates that events for each hand and pointable will be created
 79   static bool smGenerateIndividualEvents;
 80
 81   // Indicates that we track hand IDs and will ensure that the same hand
 82   // will remain at the same index between frames.
 83   static bool smKeepHandIndexPersistent;
 84
 85   // Indicates that we track pointable IDs and will ensure that the same
 86   // pointable will remain at the same index between frames.
 87   static bool smKeepPointableIndexPersistent;
 88
 89   // Broadcast single hand rotation as axis
 90   static bool smGenerateSingleHandRotationAsAxisEvents;
 91
 92   // The maximum hand angle when used as an axis event
 93   // as measured from a vector pointing straight up (in degrees)
 94   static F32 smMaximumHandAxisAngle;
 95
 96   // Indicates that a whole frame event should be generated and frames
 97   // should be buffered.
 98   static bool smGenerateWholeFrameEvents;
 99
100   // Frame action codes
101   static U32 LM_FRAMEVALIDDATA;    // SI_BUTTON
102
103   // Hand action codes
104   static U32 LM_HAND[LeapMotionConstants::MaxHands];    // SI_POS
105   static U32 LM_HANDROT[LeapMotionConstants::MaxHands]; // SI_ROT
106
107   static U32 LM_HANDAXISX;   // SI_AXIS
108   static U32 LM_HANDAXISY;
109
110   // Pointables action codes
111   static U32 LM_HANDPOINTABLE[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand];    // SI_POS
112   static U32 LM_HANDPOINTABLEROT[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand]; // SI_ROT
113
114   // Whole frame
115   static U32 LM_FRAME;    // SI_INT
116
117public:
118   LeapMotionDevice();
119   ~LeapMotionDevice();
120
121   static void staticInit();
122
123   bool enable();
124   void disable();
125
126   bool getActive();
127   void setActive(bool state);
128
129   bool process();
130
131public:
132   // For ManagedSingleton.
133   static const char* getSingletonName() { return "LeapMotionDevice"; }   
134};
135
136/// Returns the LeapMotionDevice singleton.
137#define LEAPMOTIONDEV ManagedSingleton<LeapMotionDevice>::instance()
138
139#endif   // _LEAPMOTIONDEVICE_H_
140