vrpn 07.35
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
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
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
17
18const 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 { vrpn_strcpy(name, n);
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
90class VRPN_API vrpn_Tracker_ButtonFly; // Forward reference
91
93 public:
94 vrpn_TBF_fullaxis (void) { btn = NULL; active = false; bf = NULL; };
95
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
Generic connection class not specific to the transport mechanism.
vrpn_TBF_axis(const char *n, int ch, const float v[], const float rv[], bool absolut)
vrpn_Button_Remote * btn
vrpn_Tracker_ButtonFly * bf
bool add_axis(const vrpn_TBF_axis &b)
Add an axis command to the parameter list.
This class will turn a button device into a tracker by interpreting.
vrpn_Button_Remote * d_reset_button
Button that resets the transformation.
static void VRPN_CALLBACK handle_reset_press(void *userdata, const vrpn_BUTTONCB info)
void update(q_matrix_type &)
vrpn_Analog_Remote * d_rot_scale
Analog device that scales the rotation.
vrpn_Analog_Remote * d_vel_scale
Analog device that scales the translation.
This structure is what is passed to a vrpn_Connection message callback.
#define VRPN_API
#define VRPN_CALLBACK
void vrpn_strcpy(char(&to)[charCount], const char *pSrc)
Null-terminated-string copy function that both guarantees not to overrun the buffer and guarantees th...
const int vrpn_BUTTONFLY_MAXAXES