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