vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Tracker_ButtonFly.h
Go to the documentation of this file.
1 #ifndef INCLUDED_BUTTONFLY
2 #define INCLUDED_BUTTONFLY
3 
4 #include <quat.h> // for q_matrix_type
5 #include <stdio.h> // for NULL
6 #include <string.h> // for strcpy, memcpy, strncpy
7 
8 #include "vrpn_Analog.h" // for vrpn_ANALOGCB, etc
9 #include "vrpn_Button.h" // for vrpn_BUTTONCB, etc
10 #include "vrpn_Configure.h" // for VRPN_API, VRPN_CALLBACK
11 #include "vrpn_Shared.h" // for timeval
12 #include "vrpn_Tracker.h" // for vrpn_Tracker
13 #include "vrpn_Types.h" // for VRPN_FALSE
14 
16 struct vrpn_HANDLERPARAM;
17 
18 const int vrpn_BUTTONFLY_MAXAXES = 200;
19 
20 // This parameter is passed to the constructor for the ButtonFly; it
21 // describes the action of a single button, describing which
22 // direction to translate or rotate and how fast. Translation is
23 // expressed as a vector with the length of the translation, expressed
24 // in meters/second. Rotation is specified as a vector with the number
25 // of rotations to make per second around X, Y, and Z.
26 
28 
29  public:
30 
32  { strcpy(name,""); channel = 0;
33  vec[0] = vec[1] = vec[2] = 0.0;
34  rot[0] = rot[1] = rot[2] = 0.0;
35  absolute = false;
36  };
37  vrpn_TBF_axis(const char *n, int ch, const float v[],
38  const float rv[], bool absolut)
39  { strncpy(name, n, sizeof(name)-1); name[sizeof(name)-1] = '\0';
40  channel = ch;
41  memcpy(vec, v, sizeof(vec));
42  memcpy(rot, rv, sizeof(rot));
43  absolute = absolut;
44  };
45 
46  char name[200]; //< Name of the Button device driving this axis
47  int channel; //< Which channel to use from the Button device
48  float vec[3]; //< Vector telling how far and which way to move in 1 second
49  float rot[3]; //< Vector telling rotation about X,Y,and Z
50  bool absolute; //< Whether this is an absolute or differential change
51 };
52 
54 
55  public:
56 
58  strcpy(vel_scale_name, "");
59  strcpy(rot_scale_name, "");
60  num_axes = 0;
61  }
62 
64  bool add_axis(const vrpn_TBF_axis &b) {
65  if (num_axes >= vrpn_BUTTONFLY_MAXAXES) { return false; }
66  axes[num_axes] = b;
67  num_axes++;
68  return true;
69  }
70 
73  int num_axes; //< How many axes have been filled in
74 
76  char vel_scale_name[200];
81 
83  char rot_scale_name[200];
88 };
89 
90 class VRPN_API vrpn_Tracker_ButtonFly; // Forward reference
91 
93  public:
94  vrpn_TBF_fullaxis (void) { btn = NULL; active = false; bf = NULL; };
95 
96  vrpn_TBF_axis axis;
99  bool active;
100 };
101 
103 // the buttons as constant-velocity inputs and "flying" the user around based
104 // on which buttons are held down for how long.
105 // The mapping from buttons to directions (or orientation changes) is
106 // described in the vrpn_Tracker_ButtonFlyParam parameter. Translations are
107 // specified as vectors giving direction and speed (meters per second).
108 // Rotations are given as an axis to rotate around and speed to rotate
109 // (revolutions per second) around the given axis.
110 // The time reported by button trackers is the local time that the report was
111 // generated. Velocity reports are also generated for the tracker.
112 
113 // If reportChanges is TRUE, updates are ONLY sent if there has been a
114 // change since the last update, in which case they are generated no faster
115 // than update_rate.
116 
118  public:
119  vrpn_Tracker_ButtonFly (const char * name, vrpn_Connection * trackercon,
121  float update_rate,
122  bool reportChanges = VRPN_FALSE);
123 
124  virtual ~vrpn_Tracker_ButtonFly (void);
125 
126  virtual void mainloop ();
127  virtual void reset (void);
128 
129  void update (q_matrix_type &);
130 
131  static int VRPN_CALLBACK handle_newConnection (void *, vrpn_HANDLERPARAM);
132 
133  protected:
134 
135  double d_update_interval; //< How long to wait between sends
136  struct timeval d_prevtime; //< Time of the previous report
137  bool d_reportChanges; //< Report only when something changes?
138 
141 
144  char d_vel_scale_name[200];
149  float d_vel_scale_value; //< Value computed from above, scales vel
150 
153  char d_rot_scale_name[200];
158  float d_rot_scale_value; //< Value computed from above, scales rotation
159 
163 
165  q_matrix_type d_initMatrix, d_currentMatrix, d_velMatrix;
166 
167  void update_matrix_based_on_values (double time_interval);
168  void convert_matrix_to_tracker (void);
169 
170  bool shouldReport (double elapsedInterval);
171 
172  int setup_channel(vrpn_TBF_fullaxis * full);
173  int teardown_channel(vrpn_TBF_fullaxis * full);
174 
175  static void VRPN_CALLBACK handle_velocity_update(void * userdata, const vrpn_ANALOGCB info);
176  static void VRPN_CALLBACK handle_rotation_update(void * userdata, const vrpn_ANALOGCB info);
177  static void VRPN_CALLBACK handle_button_update(void * userdata, const vrpn_BUTTONCB info);
178  static void VRPN_CALLBACK handle_reset_press(void * userdata, const vrpn_BUTTONCB info);
179 };
180 
181 #endif
vrpn_Tracker.h
vrpn_Tracker
Definition: vrpn_Tracker.h:49
vrpn_Tracker_ButtonFly::d_vel_scale_offset
float d_vel_scale_offset
Definition: vrpn_Tracker_ButtonFly.h:146
vrpn_Tracker_ButtonFly::d_rot_scale_offset
float d_rot_scale_offset
Definition: vrpn_Tracker_ButtonFly.h:155
vrpn_Tracker_ButtonFlyParam::rot_scale_scale
float rot_scale_scale
Definition: vrpn_Tracker_ButtonFly.h:86
vrpn_Tracker_ButtonFly::d_vel_scale_channel
int d_vel_scale_channel
Definition: vrpn_Tracker_ButtonFly.h:145
vrpn_Types.h
vrpn_TBF_fullaxis::bf
vrpn_Tracker_ButtonFly * bf
Definition: vrpn_Tracker_ButtonFly.h:98
vrpn_Tracker_ButtonFlyParam::vrpn_Tracker_ButtonFlyParam
vrpn_Tracker_ButtonFlyParam(void)
Definition: vrpn_Tracker_ButtonFly.h:57
vrpn_Tracker_ButtonFlyParam::vel_scale_offset
float vel_scale_offset
Definition: vrpn_Tracker_ButtonFly.h:78
vrpn_Analog_Remote
Definition: vrpn_Analog.h:181
vrpn_Tracker_ButtonFly::d_vel_scale_scale
float d_vel_scale_scale
Definition: vrpn_Tracker_ButtonFly.h:147
vrpn_Button_Remote
Definition: vrpn_Button.h:250
vrpn_TBF_axis::absolute
bool absolute
Definition: vrpn_Tracker_ButtonFly.h:50
vrpn_Tracker_ButtonFlyParam::rot_scale_channel
int rot_scale_channel
Definition: vrpn_Tracker_ButtonFly.h:84
vrpn_Tracker_ButtonFly::d_update_interval
double d_update_interval
Definition: vrpn_Tracker_ButtonFly.h:135
vrpn_Tracker_ButtonFlyParam::vel_scale_power
float vel_scale_power
Definition: vrpn_Tracker_ButtonFly.h:80
vrpn_Tracker_ButtonFly::d_rot_scale_value
float d_rot_scale_value
Definition: vrpn_Tracker_ButtonFly.h:158
vrpn_Tracker_ButtonFly
This class will turn a button device into a tracker by interpreting.
Definition: vrpn_Tracker_ButtonFly.h:117
vrpn_TBF_fullaxis
Definition: vrpn_Tracker_ButtonFly.h:92
vrpn_Tracker_ButtonFly::d_rot_scale_channel
int d_rot_scale_channel
Definition: vrpn_Tracker_ButtonFly.h:154
vrpn_TBF_fullaxis::btn
vrpn_Button_Remote * btn
Definition: vrpn_Tracker_ButtonFly.h:97
vrpn_ANALOGCB
Definition: vrpn_Analog.h:168
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition: vrpn_Connection.h:44
vrpn_Shared.h
vrpn_TBF_axis::vrpn_TBF_axis
vrpn_TBF_axis(const char *n, int ch, const float v[], const float rv[], bool absolut)
Definition: vrpn_Tracker_ButtonFly.h:37
vrpn_Tracker_ButtonFlyParam::add_axis
bool add_axis(const vrpn_TBF_axis &b)
Add an axis command to the parameter list.
Definition: vrpn_Tracker_ButtonFly.h:64
vrpn_Tracker_ButtonFlyParam::rot_scale_power
float rot_scale_power
Definition: vrpn_Tracker_ButtonFly.h:87
vrpn_Button.h
vrpn_Tracker_ButtonFly::d_reset_button
vrpn_Button_Remote * d_reset_button
Button that resets the transformation.
Definition: vrpn_Tracker_ButtonFly.h:161
vrpn_Tracker_ButtonFly::d_vel_scale
vrpn_Analog_Remote * d_vel_scale
Analog device that scales the translation.
Definition: vrpn_Tracker_ButtonFly.h:143
vrpn_BaseClass::mainloop
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Tracker_ButtonFlyParam::num_axes
int num_axes
Definition: vrpn_Tracker_ButtonFly.h:73
vrpn_BUTTONCB
Definition: vrpn_Button.h:225
vrpn_Tracker_ButtonFly
class VRPN_API vrpn_Tracker_ButtonFly
Definition: vrpn_Tracker_ButtonFly.h:90
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_Tracker_ButtonFly::d_rot_scale_power
float d_rot_scale_power
Definition: vrpn_Tracker_ButtonFly.h:157
vrpn_Tracker_ButtonFlyParam::vel_scale_channel
int vel_scale_channel
Definition: vrpn_Tracker_ButtonFly.h:77
vrpn_TBF_axis::vrpn_TBF_axis
vrpn_TBF_axis(void)
Definition: vrpn_Tracker_ButtonFly.h:31
vrpn_Analog.h
VRPN_CALLBACK
#define VRPN_CALLBACK
Definition: vrpn_Configure.h:647
vrpn_Tracker_ButtonFly::d_rot_scale_scale
float d_rot_scale_scale
Definition: vrpn_Tracker_ButtonFly.h:156
vrpn_Tracker_ButtonFlyParam
Definition: vrpn_Tracker_ButtonFly.h:53
vrpn_Tracker_ButtonFly::d_rot_scale
vrpn_Analog_Remote * d_rot_scale
Analog device that scales the rotation.
Definition: vrpn_Tracker_ButtonFly.h:152
vrpn_BUTTONFLY_MAXAXES
const int vrpn_BUTTONFLY_MAXAXES
Definition: vrpn_Tracker_ButtonFly.h:18
vrpn_Tracker_ButtonFly::d_velMatrix
q_matrix_type d_velMatrix
Definition: vrpn_Tracker_ButtonFly.h:165
vrpn_TBF_axis::channel
int channel
Definition: vrpn_Tracker_ButtonFly.h:47
vrpn_Configure.h
vrpn_Tracker_ButtonFly::d_reportChanges
bool d_reportChanges
Definition: vrpn_Tracker_ButtonFly.h:137
vrpn_Tracker_ButtonFly::d_num_axes
int d_num_axes
Definition: vrpn_Tracker_ButtonFly.h:140
vrpn_Tracker_ButtonFly::d_vel_scale_power
float d_vel_scale_power
Definition: vrpn_Tracker_ButtonFly.h:148
vrpn_Tracker_ButtonFlyParam::rot_scale_offset
float rot_scale_offset
Definition: vrpn_Tracker_ButtonFly.h:85
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646
vrpn_Tracker_ButtonFly::d_which_button
int d_which_button
Definition: vrpn_Tracker_ButtonFly.h:162
vrpn_TBF_axis
Definition: vrpn_Tracker_ButtonFly.h:27
vrpn_TBF_fullaxis::active
bool active
Definition: vrpn_Tracker_ButtonFly.h:99
vrpn_Tracker_ButtonFly::d_vel_scale_value
float d_vel_scale_value
Definition: vrpn_Tracker_ButtonFly.h:149
vrpn_TBF_fullaxis::vrpn_TBF_fullaxis
vrpn_TBF_fullaxis(void)
Definition: vrpn_Tracker_ButtonFly.h:94
vrpn_Tracker_ButtonFlyParam::vel_scale_scale
float vel_scale_scale
Definition: vrpn_Tracker_ButtonFly.h:79