Torque3D Documentation / _generateds / razerHydraFrame.h

razerHydraFrame.h

Engine/source/platform/input/razerHydra/razerHydraFrame.h

More...

Classes:

Detailed Description

  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 _RAZERHYDRAFRAME_H_
 25#define _RAZERHYDRAFRAME_H_
 26
 27#include "platform/input/razerHydra/razerHydraConstants.h"
 28#include "console/simObject.h"
 29#include "math/mPoint3.h"
 30#include "math/mMatrix.h"
 31#include "math/mQuat.h"
 32#include "sixense.h"
 33
 34class RazerHydraFrame : public SimObject
 35{
 36   typedef SimObject Parent;
 37
 38protected:
 39   struct ControllerData
 40   {
 41      // Position
 42      Point3F mRawPos;
 43      Point3I mPos;
 44
 45      // Rotation
 46      MatrixF mRot;
 47      QuatF   mRotQuat;
 48
 49      // Controller rotation as axis x, y
 50      Point2F mRotAxis;
 51
 52      // Thumb stick x, y and trigger
 53      Point2F mThumbStick;
 54      F32 mTrigger;
 55
 56      // Buttons
 57      bool mShoulder;
 58      bool mThumb;
 59      bool mStart;
 60      bool mButton1;
 61      bool mButton2;
 62      bool mButton3;
 63      bool mButton4;
 64
 65      // Other data
 66      U8 mSequenceNum;
 67      bool mEnabled;
 68      bool mIsDocked;
 69   };
 70
 71   static U32 smNextInternalFrameId;
 72
 73   // Sixense Frame
 74   bool  mFrameValid;
 75
 76   // Torque 3D frame information
 77   U32   mFrameInternalId;
 78   S32   mFrameSimTime;
 79   S32   mFrameRealTime;
 80
 81   // Controller data for the frame
 82   ControllerData mControllerData[RazerHydraConstants::MaxControllers];
 83
 84public:
 85   RazerHydraFrame();
 86   virtual ~RazerHydraFrame();
 87
 88   static void initPersistFields();
 89
 90   virtual bool onAdd();
 91   virtual void onRemove();
 92
 93   void clear();
 94
 95   /// Copy a Leap Frame into our data structures
 96   void copyFromFrame(const sixenseAllControllerData& frame, const F32& maxAxisRadius);
 97
 98   // Frame
 99   bool isFrameValid() const { return mFrameValid; }
100   U32 getFrameInternalId() const { return mFrameInternalId; }
101   S32 getFrameSimTime() const { return mFrameSimTime; }
102   S32 getFrameRealTime() const { return mFrameRealTime; }
103
104   // Controller
105   const Point3F& getRawPos(U32 index) const;
106   const Point3I& getPos(U32 index) const;
107   const MatrixF& getRot(U32 index) const;
108   const QuatF& getRotQuat(U32 index) const;
109   const Point2F& getRotAxis(U32 index) const;
110
111   // Controller variable controls
112   const Point2F& getThumbStick(U32 Index) const;
113   F32 getTrigger(U32 index) const;
114
115   // Controller buttons
116   bool getShoulder(U32 index) const;
117   bool getThumb(U32 index) const;
118   bool getStart(U32 index) const;
119   bool getButton1(U32 index) const;
120   bool getButton2(U32 index) const;
121   bool getButton3(U32 index) const;
122   bool getButton4(U32 index) const;
123
124   // Controller other
125   bool getEnabled(U32 index) const;
126   bool getDocked(U32 index) const;
127   S32 getSequenceNum(U32 index) const;
128
129   DECLARE_CONOBJECT(RazerHydraFrame);
130};
131
132//-----------------------------------------------------------------------------
133
134inline const Point3F& RazerHydraFrame::getRawPos(U32 index) const
135{
136   return (index >= RazerHydraConstants::MaxControllers) ? Point3F::Zero : mControllerData[index].mRawPos;
137}
138
139inline const Point3I& RazerHydraFrame::getPos(U32 index) const
140{
141   return (index >= RazerHydraConstants::MaxControllers) ? Point3I::Zero : mControllerData[index].mPos;
142}
143
144inline const MatrixF& RazerHydraFrame::getRot(U32 index) const
145{
146   return (index >= RazerHydraConstants::MaxControllers) ? MatrixF::Identity : mControllerData[index].mRot;
147}
148
149inline const QuatF& RazerHydraFrame::getRotQuat(U32 index) const
150{
151   return (index >= RazerHydraConstants::MaxControllers) ? QuatF::Identity : mControllerData[index].mRotQuat;
152}
153
154inline const Point2F& RazerHydraFrame::getRotAxis(U32 index) const
155{
156   return (index >= RazerHydraConstants::MaxControllers) ? Point2F::Zero : mControllerData[index].mRotAxis;
157}
158
159inline const Point2F& RazerHydraFrame::getThumbStick(U32 index) const
160{
161   return (index >= RazerHydraConstants::MaxControllers) ? Point2F::Zero : mControllerData[index].mThumbStick;
162}
163
164inline F32 RazerHydraFrame::getTrigger(U32 index) const
165{
166   return (index >= RazerHydraConstants::MaxControllers) ? 0.0f : mControllerData[index].mTrigger;
167}
168
169inline bool RazerHydraFrame::getShoulder(U32 index) const
170{
171   return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mShoulder;
172}
173
174inline bool RazerHydraFrame::getThumb(U32 index) const
175{
176   return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mThumb;
177}
178
179inline bool RazerHydraFrame::getStart(U32 index) const
180{
181   return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mStart;
182}
183
184inline bool RazerHydraFrame::getButton1(U32 index) const
185{
186   return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mButton1;
187}
188
189inline bool RazerHydraFrame::getButton2(U32 index) const
190{
191   return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mButton2;
192}
193
194inline bool RazerHydraFrame::getButton3(U32 index) const
195{
196   return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mButton3;
197}
198
199inline bool RazerHydraFrame::getButton4(U32 index) const
200{
201   return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mButton4;
202}
203
204inline bool RazerHydraFrame::getEnabled(U32 index) const
205{
206   return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mEnabled;
207}
208
209inline bool RazerHydraFrame::getDocked(U32 index) const
210{
211   return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mIsDocked;
212}
213
214inline S32 RazerHydraFrame::getSequenceNum(U32 index) const
215{
216   return (index >= RazerHydraConstants::MaxControllers) ? -1 : mControllerData[index].mSequenceNum;
217}
218
219#endif   // _RAZERHYDRAFRAME_H_
220