vrpn  07.33
Virtual Reality Peripheral Network
vrpn_DirectXFFJoystick.h
Go to the documentation of this file.
1 #ifndef VRPN_DIRECTXFFJOYSTICK_H
2 #define VRPN_DIRECTXFFJOYSTICK_H
3 
4 #include "vrpn_Configure.h" // IWYU pragma: keep
5 
6 #if defined(_WIN32) && defined(VRPN_USE_DIRECTINPUT)
7 #ifndef DIRECTINPUT_VERSION
8 #define DIRECTINPUT_VERSION 0x0800
9 #endif
10 
11 #include "vrpn_Connection.h"
12 #include "vrpn_Analog.h"
13 #include "vrpn_Button.h"
14 #include "vrpn_ForceDevice.h"
15 #include "vrpn_ForceDeviceServer.h"
16 
17 #include <basetsd.h>
18 #include <dinput.h>
19 
20 class VRPN_API vrpn_DirectXFFJoystick: public vrpn_Analog
21  ,public vrpn_Button_Filter
23 {
24 public:
26  vrpn_DirectXFFJoystick (const char * name, vrpn_Connection * c,
27  double readRate = 60, double forceRate = 200);
28 
29  ~vrpn_DirectXFFJoystick ();
30 
31  // Called once through each main loop iteration to handle
32  // updates.
33  virtual void mainloop ();
34 
35 protected:
36  HWND _hWnd; // Handle to the console window
37  int _status;
38 
39  int _numbuttons; // How many buttons
40  int _numchannels; // How many analog channels
41  int _numforceaxes; // How many force-feedback channels we have
42 
43  struct timeval _timestamp; // Time of the last report from the device
44  struct timeval _forcetime; // Last time we sent a force.
45  struct timeval _last_report;// Last time we sent a report.
46  double _read_rate; // How many times per second to read the device
47  double _force_rate; // How many times per second to update forces
48 
49  double _fX, _fY; // Force to display in X and Y
50  double _fx_1, _fy_1; // Force applied last time
51  double _fx_2, _fy_2; // Force applied two times ago
52 
53  virtual int get_report(void); // Try to read a report from the device
54  void clear_values(void); // Clear the Analog and Button values
55 
56  // send report iff changed
57  virtual void report_changes (vrpn_uint32 class_of_service
59  // send report whether or not changed
60  virtual void report (vrpn_uint32 class_of_service
62  // NOTE: class_of_service is only applied to vrpn_Analog
63  // values, not vrpn_Button
64 
65  // Send forces to joystick, where forces range from -1 to 1 on X and Y axes.
66  void send_normalized_force(double fx, double fy);
67 
68  HRESULT InitDirectJoystick( void );
69  LPDIRECTINPUT8 _DirectInput; // Handle to Direct Input
70  LPDIRECTINPUTDEVICE8 _Joystick; // Handle to the joystick we are using
71  LPDIRECTINPUTEFFECT _ForceEffect; // Handle to the constant force effect
72  static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* selfPtr );
73  static BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* selfPtr );
74 
75  static int VRPN_CALLBACK handle_last_connection_dropped(void *selfPtr, vrpn_HANDLERPARAM p);
76  static int VRPN_CALLBACK handle_plane_change_message(void *selfPtr, vrpn_HANDLERPARAM p);
77  static int VRPN_CALLBACK handle_forcefield_change_message(void *selfPtr, vrpn_HANDLERPARAM p);
78 
79  //-------------------------------------------------------------------------------
80  // None of the scene-orienting or object-creation methods are supported yet, but
81  // we need to create non-empty functions to handle them.
82 
83  // Add an object to the haptic scene as root (parent -1 = default) or as child (ParentNum =the number of the parent)
84  virtual bool addObject(vrpn_int32 objNum, vrpn_int32 ParentNum=-1) {
85  struct timeval now;
86  vrpn_gettimeofday(&now, NULL);
87  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
88  return false;
89  };
90 
91  // Add an object next to the haptic scene as root
92  virtual bool addObjectExScene(vrpn_int32 objNum) {
93  struct timeval now;
94  vrpn_gettimeofday(&now, NULL);
95  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
96  return false;
97  };
98 
99  // vertNum normNum and triNum start at 0
100  virtual bool setVertex(vrpn_int32 objNum, vrpn_int32 vertNum,vrpn_float32 x,vrpn_float32 y,vrpn_float32 z) {
101  struct timeval now;
102  vrpn_gettimeofday(&now, NULL);
103  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
104  return false;
105  };
106 
107  // NOTE: ghost doesn't take normals,
108  // and normals still aren't implemented for Hcollide
109  virtual bool setNormal(vrpn_int32 objNum, vrpn_int32 normNum,vrpn_float32 x,vrpn_float32 y,vrpn_float32 z) {
110  struct timeval now;
111  vrpn_gettimeofday(&now, NULL);
112  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
113  return false;
114  };
115 
116  virtual bool setTriangle(vrpn_int32 objNum, vrpn_int32 triNum,vrpn_int32 vert0,vrpn_int32 vert1,vrpn_int32 vert2,
117  vrpn_int32 norm0=-1,vrpn_int32 norm1=-1,vrpn_int32 norm2=-1) {
118  struct timeval now;
119  vrpn_gettimeofday(&now, NULL);
120  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
121  return false;
122  };
123 
124  virtual bool removeTriangle(vrpn_int32 objNum, vrpn_int32 triNum) {
125  struct timeval now;
126  vrpn_gettimeofday(&now, NULL);
127  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
128  return false;
129  };
130 
131  // should be called to incorporate the above changes into the
132  // displayed trimesh
133  virtual bool updateTrimeshChanges(vrpn_int32 objNum,vrpn_float32 kspring, vrpn_float32 kdamp, vrpn_float32 fdyn, vrpn_float32 fstat) {
134  struct timeval now;
135  vrpn_gettimeofday(&now, NULL);
136  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
137  return false;
138  };
139 
140  // set trimesh type
141  virtual bool setTrimeshType(vrpn_int32 objNum,vrpn_int32 type) {
142  struct timeval now;
143  vrpn_gettimeofday(&now, NULL);
144  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
145  return false;
146  };
147 
148  // set the trimesh's homogen transform matrix (in row major order)
149  virtual bool setTrimeshTransform(vrpn_int32 objNum, vrpn_float32 homMatrix[16]) {
150  struct timeval now;
151  vrpn_gettimeofday(&now, NULL);
152  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
153  return false;
154  };
155 
156  // set position of an object
157  virtual bool setObjectPosition(vrpn_int32 objNum, vrpn_float32 Pos[3]) {
158  struct timeval now;
159  vrpn_gettimeofday(&now, NULL);
160  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
161  return false;
162  };
163 
164  // set orientation of an object
165  virtual bool setObjectOrientation(vrpn_int32 objNum, vrpn_float32 axis[3], vrpn_float32 angle) {
166  struct timeval now;
167  vrpn_gettimeofday(&now, NULL);
168  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
169  return false;
170  };
171 
172  // set Scale of an object
173  virtual bool setObjectScale(vrpn_int32 objNum, vrpn_float32 Scale[3]) {
174  struct timeval now;
175  vrpn_gettimeofday(&now, NULL);
176  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
177  return false;
178  };
179 
180  // remove an object from the scene
181  virtual bool removeObject(vrpn_int32 objNum) {
182  struct timeval now;
183  vrpn_gettimeofday(&now, NULL);
184  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
185  return false;
186  };
187 
188  virtual bool clearTrimesh(vrpn_int32 objNum) {
189  struct timeval now;
190  vrpn_gettimeofday(&now, NULL);
191  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
192  return false;
193  };
194 
196  // Change The parent of an object
197  virtual bool moveToParent(vrpn_int32 objNum, vrpn_int32 ParentNum) {
198  struct timeval now;
199  vrpn_gettimeofday(&now, NULL);
200  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
201  return false;
202  };
203 
204  // Set the Origin of the haptic scene
205  virtual bool setHapticOrigin(vrpn_float32 Pos[3], vrpn_float32 axis[3], vrpn_float32 angle) {
206  struct timeval now;
207  vrpn_gettimeofday(&now, NULL);
208  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
209  return false;
210  };
211 
212  // Set the Scale factor of the haptic scene
213  virtual bool setHapticScale(vrpn_float32 Scale) {
214  struct timeval now;
215  vrpn_gettimeofday(&now, NULL);
216  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
217  return false;
218  };
219 
220  // Set the Origin of the haptic scene
221  virtual bool setSceneOrigin(vrpn_float32 Pos[3], vrpn_float32 axis[3], vrpn_float32 angle) {
222  struct timeval now;
223  vrpn_gettimeofday(&now, NULL);
224  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
225  return false;
226  };
227 
228  // make an object touchable or not
229  virtual bool setObjectIsTouchable(vrpn_int32 objNum, vrpn_bool IsTouchable=true) {
230  struct timeval now;
231  vrpn_gettimeofday(&now, NULL);
232  send_text_message("vrpn_DirectXFFJoystick: Called a function not supported",now, vrpn_TEXT_ERROR);
233  return false;
234  };
235 
236 };
237 
238 #endif
239 #endif
240 
vrpn_ForceDeviceServer::setVertex
virtual bool setVertex(vrpn_int32 objNum, vrpn_int32 vertNum, vrpn_float32 x, vrpn_float32 y, vrpn_float32 z)=0
vrpn_ForceDeviceServer::setObjectPosition
virtual bool setObjectPosition(vrpn_int32 objNum, vrpn_float32 Pos[3])=0
vrpn_ForceDeviceServer::clearTrimesh
virtual bool clearTrimesh(vrpn_int32 objNum)=0
vrpn_ForceDeviceServer::setTrimeshType
virtual bool setTrimeshType(vrpn_int32 objNum, vrpn_int32 type)=0
vrpn_Analog::report
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report whether something has changed or not (for servers) Optionally, tell what time to stamp ...
Definition: vrpn_Analog.C:94
vrpn_ForceDeviceServer::setHapticScale
virtual bool setHapticScale(vrpn_float32 Scale)=0
vrpn_ForceDeviceServer::moveToParent
virtual bool moveToParent(vrpn_int32 objNum, vrpn_int32 ParentNum)=0
Functions to organize the scene.
vrpn_Analog
Definition: vrpn_Analog.h:28
vrpn_ForceDevice.h
vrpn_ForceDeviceServer::setTriangle
virtual bool setTriangle(vrpn_int32 objNum, vrpn_int32 triNum, vrpn_int32 vert0, vrpn_int32 vert1, vrpn_int32 vert2, vrpn_int32 norm0=-1, vrpn_int32 norm1=-1, vrpn_int32 norm2=-1)=0
vrpn_CONNECTION_LOW_LATENCY
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
Definition: vrpn_Connection.h:122
vrpn_ForceDeviceServer::setTrimeshTransform
virtual bool setTrimeshTransform(vrpn_int32 objNum, vrpn_float32 homMatrix[16])=0
vrpn_TEXT_ERROR
@ vrpn_TEXT_ERROR
Definition: vrpn_BaseClass.h:103
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition: vrpn_Connection.h:44
vrpn_ForceDeviceServer::updateTrimeshChanges
virtual bool updateTrimeshChanges(vrpn_int32 objNum, vrpn_float32 kspring, vrpn_float32 kdamp, vrpn_float32 fdyn, vrpn_float32 fstat)=0
vrpn_Button.h
vrpn_ForceDeviceServer::setHapticOrigin
virtual bool setHapticOrigin(vrpn_float32 Pos[3], vrpn_float32 axis[3], vrpn_float32 angle)=0
vrpn_ForceDeviceServer::setObjectIsTouchable
virtual bool setObjectIsTouchable(vrpn_int32 objNum, vrpn_bool IsTouchable=true)=0
vrpn_BaseClass::mainloop
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_ForceDeviceServer::setNormal
virtual bool setNormal(vrpn_int32 objNum, vrpn_int32 normNum, vrpn_float32 x, vrpn_float32 y, vrpn_float32 z)=0
vrpn_ForceDeviceServer::setSceneOrigin
virtual bool setSceneOrigin(vrpn_float32 Pos[3], vrpn_float32 axis[3], vrpn_float32 angle)=0
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_Connection.h
vrpn_ForceDeviceServer::setObjectOrientation
virtual bool setObjectOrientation(vrpn_int32 objNum, vrpn_float32 axis[3], vrpn_float32 angle)=0
vrpn_gettimeofday
#define vrpn_gettimeofday
Definition: vrpn_Shared.h:89
vrpn_ForceDeviceServer::removeObject
virtual bool removeObject(vrpn_int32 objNum)=0
vrpn_Analog.h
vrpn_ForceDeviceServer::addObjectExScene
virtual bool addObjectExScene(vrpn_int32 objNum)=0
VRPN_CALLBACK
#define VRPN_CALLBACK
Definition: vrpn_Configure.h:647
vrpn_ForceDeviceServer.h
vrpn_ForceDeviceServer::addObject
virtual bool addObject(vrpn_int32 objNum, vrpn_int32 ParentNum=-1)=0
vrpn_ForceDeviceServer::removeTriangle
virtual bool removeTriangle(vrpn_int32 objNum, vrpn_int32 triNum)=0
vrpn_ForceDeviceServer::setObjectScale
virtual bool setObjectScale(vrpn_int32 objNum, vrpn_float32 Scale[3])=0
vrpn_BaseClassUnique::send_text_message
int send_text_message(const char *msg, struct timeval timestamp, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0)
Sends a NULL-terminated text message from the device d_sender_id.
Definition: vrpn_BaseClass.C:568
vrpn_Configure.h
vrpn_Analog::report_changes
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report only if something has changed (for servers) Optionally, tell what time to stamp the val...
Definition: vrpn_Analog.C:71
vrpn_ForceDeviceServer
Definition: vrpn_ForceDeviceServer.h:27
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646
vrpn_Button_Filter
All button servers should derive from this class, which provides the ability to turn any of the butto...
Definition: vrpn_Button.h:65