RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Tracker_ButtonFly.h
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
15class VRPN_API vrpn_Connection;
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
27class VRPN_API vrpn_TBF_axis {
28
29 public:
30
31 vrpn_TBF_axis(void)
32 { vrpn_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 vrpn_strcpy(vel_scale_name, "");
59 vrpn_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
72 vrpn_TBF_axis axes[vrpn_BUTTONFLY_MAXAXES];
73 int num_axes; //< How many axes have been filled in
74
76 char vel_scale_name[200];
77 int vel_scale_channel;
78 float vel_scale_offset;
79 float vel_scale_scale;
80 float vel_scale_power;
81
83 char rot_scale_name[200];
84 int rot_scale_channel;
85 float rot_scale_offset;
86 float rot_scale_scale;
87 float rot_scale_power;
88};
89
90class VRPN_API vrpn_Tracker_ButtonFly; // Forward reference
91
92class VRPN_API vrpn_TBF_fullaxis {
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
117class VRPN_API vrpn_Tracker_ButtonFly : public vrpn_Tracker {
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
139 vrpn_TBF_fullaxis d_axes[vrpn_BUTTONFLY_MAXAXES];
140 int d_num_axes;
141
144 char d_vel_scale_name[200];
145 int d_vel_scale_channel;
146 float d_vel_scale_offset;
147 float d_vel_scale_scale;
148 float d_vel_scale_power;
149 float d_vel_scale_value; //< Value computed from above, scales vel
150
153 char d_rot_scale_name[200];
154 int d_rot_scale_channel;
155 float d_rot_scale_offset;
156 float d_rot_scale_scale;
157 float d_rot_scale_power;
158 float d_rot_scale_value; //< Value computed from above, scales rotation
159
162 int d_which_button;
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_Analog.h:181
定义 vrpn_Button.h:251
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_Tracker_ButtonFly.h:27
定义 vrpn_Tracker_ButtonFly.h:92
定义 vrpn_Tracker_ButtonFly.h:53
bool add_axis(const vrpn_TBF_axis &b)
Add an axis command to the parameter list
定义 vrpn_Tracker_ButtonFly.h:64
This class will turn a button device into a tracker by interpreting
定义 vrpn_Tracker_ButtonFly.h:117
vrpn_Button_Remote * d_reset_button
Button that resets the transformation
定义 vrpn_Tracker_ButtonFly.h:161
vrpn_Analog_Remote * d_vel_scale
Analog device that scales the translation
定义 vrpn_Tracker_ButtonFly.h:143
virtual void mainloop()
vrpn_Analog_Remote * d_rot_scale
Analog device that scales the rotation
定义 vrpn_Tracker_ButtonFly.h:152
q_matrix_type d_initMatrix
Initial, current, and velocity matrices for the tracker
定义 vrpn_Tracker_ButtonFly.h:165
定义 vrpn_Tracker.h:49
定义 vrpn_Analog.h:168
定义 vrpn_Button.h:226
This structure is what is passed to a vrpn_Connection message callback.
定义 vrpn_Connection.h:41