| 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 |
#ifndef P5GLOVE_H |
| 26 |
#define P5GLOVE_H |
| 27 |
|
| 28 |
#include <stdint.h> |
| 29 |
|
| 30 |
#ifdef __cplusplus |
| 31 |
extern "C" { |
| 32 |
#endif |
| 33 |
|
| 34 |
|
| 35 |
typedef struct p5glove *P5Glove; |
| 36 |
|
| 37 |
|
| 38 |
#define P5GLOVE_BUTTON_A 1 |
| 39 |
#define P5GLOVE_BUTTON_B 2 |
| 40 |
#define P5GLOVE_BUTTON_C 4 |
| 41 |
|
| 42 |
|
| 43 |
#define P5GLOVE_IR_WRIST_TOP 0 |
| 44 |
#define P5GLOVE_IR_PINKY_R 1 |
| 45 |
#define P5GLOVE_IR_PINKY_L 2 |
| 46 |
#define P5GLOVE_IR_PALM 3 |
| 47 |
#define P5GLOVE_IR_INDEX 4 |
| 48 |
#define P5GLOVE_IR_THUMB_TOP 5 |
| 49 |
#define P5GLOVE_IR_WRIST_BOT 6 |
| 50 |
#define P5GLOVE_IR_THUMB_BOT 7 |
| 51 |
|
| 52 |
|
| 53 |
#define P5GLOVE_FINGER_INDEX 0 |
| 54 |
#define P5GLOVE_FINGER_MIDDLE 1 |
| 55 |
#define P5GLOVE_FINGER_RING 2 |
| 56 |
#define P5GLOVE_FINGER_PINKY 3 |
| 57 |
#define P5GLOVE_FINGER_THUMB 4 |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
P5Glove p5glove_open(int glove_number); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
void p5glove_close(P5Glove glove); |
| 70 |
|
| 71 |
#define P5GLOVE_DELTA_BUTTONS 0x01 |
| 72 |
#define P5GLOVE_DELTA_FINGERS 0x02 |
| 73 |
#define P5GLOVE_DELTA_POSITION 0x04 |
| 74 |
#define P5GLOVE_DELTA_ROTATION 0x08 |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
int p5glove_sample(P5Glove glove, int timeout); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
int p5glove_get_led(P5Glove glove,int led,double position[3]); |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
int p5glove_get_buttons(P5Glove glove,uint32_t *button_mask); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
int p5glove_get_finger(P5Glove glove,int finger,double *clench); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
int p5glove_get_position(P5Glove glove,double position[3]); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
int p5glove_get_rotation(P5Glove glove,double *angle,double axis[3]); |
| 108 |
|
| 109 |
|
| 110 |
void p5glove_begin_calibration(P5Glove glove); |
| 111 |
void p5glove_end_calibration(P5Glove glove); |
| 112 |
|
| 113 |
int p5glove_get_mouse_mode(P5Glove glove); |
| 114 |
void p5glove_mouse_mode_on(P5Glove glove); |
| 115 |
void p5glove_mouse_mode_off(P5Glove glove); |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
static inline double p5glove_dist(const double a[3],const double b[3]) |
| 121 |
{ |
| 122 |
double w = 0.0; |
| 123 |
int i; |
| 124 |
|
| 125 |
for (i = 0; i < 3; i++) |
| 126 |
w += (a[i]-b[i])*(a[i]-b[i]); |
| 127 |
|
| 128 |
return sqrt(w); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
static inline void p5glove_cross(const double v1[3],const double v2[3],double res[3]) |
| 133 |
{ |
| 134 |
res[0]=v1[1]*v2[2]-v1[2]*v2[1]; |
| 135 |
res[1]=v1[2]*v2[0]-v1[0]*v2[2]; |
| 136 |
res[2]=v1[0]*v2[1]-v1[1]*v2[0]; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
static inline void p5glove_vec_mat(const double vec[3],double mat[4][4],double res[3]) |
| 143 |
{ |
| 144 |
int r,c; |
| 145 |
|
| 146 |
for (r=0; r < 3; r++) { |
| 147 |
res[r]=0.0; |
| 148 |
for (c=0; c < 3; c++) |
| 149 |
res[r] += vec[c]*mat[c][r]; |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
static inline double p5glove_dot(const double a[3],const double b[3]) |
| 154 |
{ |
| 155 |
double res = 0.0; |
| 156 |
int i; |
| 157 |
|
| 158 |
for (i=0;i < 3; i++) |
| 159 |
res += a[i]*b[i]; |
| 160 |
|
| 161 |
return res; |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
static inline void p5glove_normal(const double v[3],double res[3]) |
| 167 |
{ |
| 168 |
double tmp=0.0; |
| 169 |
int i; |
| 170 |
|
| 171 |
for (i=0; i < 3; i++) { |
| 172 |
tmp += v[i]*v[i]; |
| 173 |
} |
| 174 |
|
| 175 |
tmp=sqrt(tmp); |
| 176 |
|
| 177 |
for (i=0; i < 3; i++) |
| 178 |
res[i] = v[i] / tmp; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
static inline void p5glove_plane(const double p1[3],const double p2[3],const double p3[3],double xyz[3]) |
| 183 |
{ |
| 184 |
double v1[3],v2[3]; |
| 185 |
|
| 186 |
v1[0]=p1[0]-p2[0]; |
| 187 |
v1[1]=p1[1]-p2[1]; |
| 188 |
v1[2]=p1[2]-p2[2]; |
| 189 |
|
| 190 |
v2[0]=p3[0]-p2[0]; |
| 191 |
v2[1]=p3[1]-p2[1]; |
| 192 |
v2[2]=p3[2]-p2[2]; |
| 193 |
|
| 194 |
p5glove_cross(v1,v2,xyz); |
| 195 |
|
| 196 |
if (xyz[0]==0.0 && xyz[1]==0.0 && xyz[2]==0.0) |
| 197 |
xyz[1]=1.0; |
| 198 |
|
| 199 |
p5glove_normal(xyz,xyz); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
static inline double p5glove_angle(const double p1[3],const double p2[3],const double p3[3]) |
| 204 |
{ |
| 205 |
double v1[3],v2[3]; |
| 206 |
|
| 207 |
v1[0]=p1[0]-p2[0]; |
| 208 |
v1[1]=p1[1]-p2[1]; |
| 209 |
v1[2]=p1[2]-p2[2]; |
| 210 |
|
| 211 |
v2[0]=p3[0]-p2[0]; |
| 212 |
v2[1]=p3[1]-p2[1]; |
| 213 |
v2[2]=p3[2]-p2[2]; |
| 214 |
|
| 215 |
p5glove_normal(v1,v1); |
| 216 |
p5glove_normal(v2,v2); |
| 217 |
|
| 218 |
return acos(p5glove_dot(v1,v2)); |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
#ifdef __cplusplus |
| 223 |
} |
| 224 |
#endif |
| 225 |
|
| 226 |
#endif |