H3D API  2.4.1
RazerHydraSensor.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __RAZERHYDRASENSOR_H__
30 #define __RAZERHYDRASENSOR_H__
31 
32 
33 #include <H3D/X3DSensorNode.h>
34 #include <H3D/SFVec3f.h>
35 #include <H3D/SFVec2f.h>
36 #include <H3D/SFFloat.h>
37 #include <H3D/SFInt32.h>
38 #include <H3D/SFRotation.h>
39 #include <H3DUtil/Threads.h>
40 
41 
42 namespace H3D {
56  class H3DAPI_API RazerHydraSensor : public X3DSensorNode {
57  public:
58 
59  class H3DAPI_API EnableHydraSensor : public OnValueChangeSField< SFBool > {
60  protected:
62  virtual void onValueChange( const bool &new_value );
63  };
64 
67  Inst< EnableHydraSensor > _enabled = 0,
68  Inst< SFNode > _metadata = 0,
69  Inst< SFBool > _isActive = 0,
70  Inst< SFVec3f > _c0Position = 0,
71  Inst< SFRotation > _c0Orientation = 0,
72  Inst< SFVec2f > _c0Joystick = 0,
73  Inst< SFFloat > _c0Trigger = 0,
74  Inst< SFInt32 > _c0Buttons = 0,
75  Inst< SFBool > _c0Connected = 0,
76  Inst< SFBool > _c0Docked = 0,
77  Inst< SFInt32 > _c0WhichHand = 0,
78  Inst< SFBool > _c0HemiTrackingEnabled = 0,
79  Inst< SFBool > _c0Button1 = 0,
80  Inst< SFBool > _c0Button2 = 0,
81  Inst< SFBool > _c0Button3 = 0,
82  Inst< SFBool > _c0Button4 = 0,
83  Inst< SFBool > _c0ButtonStart = 0,
84  Inst< SFBool > _c0ButtonBumper = 0,
85  Inst< SFBool > _c0ButtonJoystick = 0,
86 
87  Inst< SFVec3f > _c1Position = 0,
88  Inst< SFRotation > _c1Orientation = 0,
89  Inst< SFVec2f > _c1Joystick = 0,
90  Inst< SFFloat > _c1Trigger = 0,
91  Inst< SFInt32 > _c1Buttons = 0,
92  Inst< SFBool > _c1Connected = 0,
93  Inst< SFBool > _c1Docked = 0,
94  Inst< SFInt32 > _c1WhichHand = 0,
95  Inst< SFBool > _c1HemiTrackingEnabled = 0,
96  Inst< SFBool > _c1Button1 = 0,
97  Inst< SFBool > _c1Button2 = 0,
98  Inst< SFBool > _c1Button3 = 0,
99  Inst< SFBool > _c1Button4 = 0,
100  Inst< SFBool > _c1ButtonStart = 0,
101  Inst< SFBool > _c1ButtonBumper = 0,
102  Inst< SFBool > _c1ButtonJoystick = 0
103  );
104 
106  ~RazerHydraSensor();
107 
111  virtual void traverseSG( TraverseInfo &ti );
112 
118  H3DUniquePtr< SFVec3f > c0Position;
119 
125  H3DUniquePtr< SFRotation > c0Orientation;
126 
135  H3DUniquePtr< SFVec2f > c0Joystick;
136 
144  H3DUniquePtr< SFFloat > c0Trigger;
145 
162  H3DUniquePtr< SFInt32 > c0Buttons;
163 
169  H3DUniquePtr< SFBool > c0Connected;
170 
177  H3DUniquePtr< SFBool > c0Docked;
178 
186  H3DUniquePtr< SFInt32 > c0WhichHand;
187 
194  H3DUniquePtr< SFBool > c0HemiTrackingEnabled;
195 
203  H3DUniquePtr< SFBool > c0Button1;
204 
212  H3DUniquePtr< SFBool > c0Button2;
213 
221  H3DUniquePtr< SFBool > c0Button3;
222 
230  H3DUniquePtr< SFBool > c0Button4;
231 
239  H3DUniquePtr< SFBool > c0ButtonStart;
240 
248  H3DUniquePtr< SFBool > c0ButtonBumper;
249 
257  H3DUniquePtr< SFBool > c0ButtonJoystick;
258 
264  H3DUniquePtr< SFVec3f > c1Position;
265 
271  H3DUniquePtr< SFRotation > c1Orientation;
272 
281  H3DUniquePtr< SFVec2f > c1Joystick;
282 
290  H3DUniquePtr< SFFloat > c1Trigger;
291 
308  H3DUniquePtr< SFInt32 > c1Buttons;
309 
315  H3DUniquePtr< SFBool > c1Connected;
316 
323  H3DUniquePtr< SFBool > c1Docked;
324 
332  H3DUniquePtr< SFInt32 > c1WhichHand;
333 
340  H3DUniquePtr< SFBool > c1HemiTrackingEnabled;
341 
349  H3DUniquePtr< SFBool > c1Button1;
350 
358  H3DUniquePtr< SFBool > c1Button2;
359 
367  H3DUniquePtr< SFBool > c1Button3;
368 
376  H3DUniquePtr< SFBool > c1Button4;
377 
385  H3DUniquePtr< SFBool > c1ButtonStart;
386 
394  H3DUniquePtr< SFBool > c1ButtonBumper;
395 
403  H3DUniquePtr< SFBool > c1ButtonJoystick;
404 
407 
408  private:
409 #ifdef HAVE_SIXENSE
410  struct RazerHydraData {
411  Vec3f position;
412  Rotation orientation;
413  Vec2f joystick;
414  H3DFloat trigger;
415  H3DInt32 buttons;
416  bool connected, docked, hemi_tracking_enabled;
417  H3DInt32 which_hand, controller;
418  };
419  list< RazerHydraData > hydra_data;
420  MutexLock data_lock;
421 
422  static PeriodicThread::CallbackCode addHydraInstanceCB( void *data );
423  static PeriodicThread::CallbackCode removeHydraInstanceCB( void *data );
424  // the handle of the communication thread.
425  static H3DUniquePtr< H3DUtil::PeriodicThread > thread_handle;
426  static list< RazerHydraSensor * > razer_hydra_instances;
427  static vector< unsigned char > last_sequence_number;
428  // The function used as the thread for reading data from
429  // the Razer Hydra device.
430  static PeriodicThread::CallbackCode razerHydraCallback( void* data );
433  void transferValues( const vector< RazerHydraData > &new_data );
434 #endif
435  };
436 }
437 
438 #endif
Contains the SFFloat field class.
Contains the SFInt32 field class.
Contains the SFRotation field class.
Contains the SFVec2f field class.
Contains the SFVec3f field class.
Header file for X3DSensorNode, X3D scene-graph node.
Template for adding the virtual function onValueChange that can be overridden in subclasses in order ...
Definition: FieldTemplates.h:49
This is a X3DSensorNode for reading values from a Razer hydra sensor.
Definition: RazerHydraSensor.h:56
H3DUniquePtr< SFBool > c0Docked
c0Docked is true if controller c0 is docked.
Definition: RazerHydraSensor.h:177
H3DUniquePtr< SFVec3f > c0Position
c0Position is the position for controller c0.
Definition: RazerHydraSensor.h:118
H3DUniquePtr< SFInt32 > c1WhichHand
c1WhichHand is 0 until controller c1 is docked.
Definition: RazerHydraSensor.h:332
H3DUniquePtr< SFBool > c0Button1
c0Button1 is true if button 1 of controller c0 has been pressed.
Definition: RazerHydraSensor.h:203
H3DUniquePtr< SFBool > c1Button2
c1Button2 is true if button 2 of controller c1 has been pressed.
Definition: RazerHydraSensor.h:358
H3DUniquePtr< SFBool > c0Button4
c0Button4 is true if button 4 of controller c0 has been pressed.
Definition: RazerHydraSensor.h:230
H3DUniquePtr< SFVec3f > c1Position
c1Position is the position for controller c1.
Definition: RazerHydraSensor.h:264
H3DUniquePtr< SFInt32 > c0WhichHand
c0WhichHand is 0 until controller c0 is docked.
Definition: RazerHydraSensor.h:186
H3DUniquePtr< SFBool > c1HemiTrackingEnabled
c1HemiTrackingEnabled is false until both controllers have been docked.
Definition: RazerHydraSensor.h:340
H3DUniquePtr< SFFloat > c1Trigger
c1Trigger is the status of the analog trigger for controller c1.
Definition: RazerHydraSensor.h:290
H3DUniquePtr< SFInt32 > c0Buttons
c0Buttons is a bit mask describing the state of each button for controller c0.
Definition: RazerHydraSensor.h:162
H3DUniquePtr< SFBool > c0ButtonStart
c0ButtonStart is true if start button of controller c0 has been pressed.
Definition: RazerHydraSensor.h:239
H3DUniquePtr< SFBool > c1Button3
c1Button3 is true if button 3 of controller c1 has been pressed.
Definition: RazerHydraSensor.h:367
H3DUniquePtr< SFBool > c1Docked
c1Docked is true if controller c1 is docked.
Definition: RazerHydraSensor.h:323
H3DUniquePtr< SFFloat > c0Trigger
c0Trigger is the status of the analog trigger for controller c0.
Definition: RazerHydraSensor.h:144
H3DUniquePtr< SFBool > c1Connected
c1Connected is true if controller c1 is connected.
Definition: RazerHydraSensor.h:315
H3DUniquePtr< SFBool > c1ButtonBumper
c1ButtonBumper is true if bumper button of controller c1 has been pressed.
Definition: RazerHydraSensor.h:394
H3DUniquePtr< SFBool > c0Button2
c0Button2 is true if button 2 of controller c0 has been pressed.
Definition: RazerHydraSensor.h:212
H3DUniquePtr< SFInt32 > c1Buttons
c1Buttons is a bit mask describing the state of each button for controller c1.
Definition: RazerHydraSensor.h:308
H3DUniquePtr< SFVec2f > c0Joystick
c0Joystick is the position of the (thumb) joystick for controller c0.
Definition: RazerHydraSensor.h:135
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: RazerHydraSensor.h:406
H3DUniquePtr< SFRotation > c1Orientation
c1Orientation is the orientation for controller c1.
Definition: RazerHydraSensor.h:271
H3DUniquePtr< SFBool > c1Button4
c1Button4 is true if button 4 of controller c1 has been pressed.
Definition: RazerHydraSensor.h:376
H3DUniquePtr< SFVec2f > c1Joystick
c1Joystick is the position of the (thumb) joystick for controller c1.
Definition: RazerHydraSensor.h:281
H3DUniquePtr< SFBool > c1Button1
c1Button1 is true if button 1 of controller c1 has been pressed.
Definition: RazerHydraSensor.h:349
H3DUniquePtr< SFBool > c0Connected
c0Connected is true if controller c0 is connected.
Definition: RazerHydraSensor.h:169
H3DUniquePtr< SFRotation > c0Orientation
c0Orientation is the orientation for controller c0.
Definition: RazerHydraSensor.h:125
H3DUniquePtr< SFBool > c0ButtonBumper
c0ButtonBumper is true if bumper button of controller c0 has been pressed.
Definition: RazerHydraSensor.h:248
H3DUniquePtr< SFBool > c0HemiTrackingEnabled
c0HemiTrackingEnabled is false until both controllers have been docked.
Definition: RazerHydraSensor.h:194
H3DUniquePtr< SFBool > c0ButtonJoystick
c0ButtonJoystick is true if joystick button of controller c0 has been pressed.
Definition: RazerHydraSensor.h:257
H3DUniquePtr< SFBool > c1ButtonJoystick
c1ButtonJoystick is true if joystick button of controller c1 has been pressed.
Definition: RazerHydraSensor.h:403
H3DUniquePtr< SFBool > c1ButtonStart
c1ButtonStart is true if start button of controller c1 has been pressed.
Definition: RazerHydraSensor.h:385
H3DUniquePtr< SFBool > c0Button3
c0Button3 is true if button 3 of controller c0 has been pressed.
Definition: RazerHydraSensor.h:221
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
This abstract node type is the base type for all sensors.
Definition: X3DSensorNode.h:40
Rotation()
Vec2f()
int H3DInt32
float H3DFloat
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194