Panda3D
vrpnClient.I
1 // Filename: vrpnClient.I
2 // Created by: jason (04Aug00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: VrpnClient::get_server_name
19 // Access: Public
20 // Description: Returns the name of the server as passed to the
21 // VrpnClient constructor.
22 ////////////////////////////////////////////////////////////////////
23 INLINE const string &VrpnClient::
24 get_server_name() const {
25  return _server_name;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: VrpnClient::is_valid
30 // Access: Public
31 // Description: Returns true if everything seems to be kosher with
32 // the server (even if there is no connection), or false
33 // otherwise.
34 ////////////////////////////////////////////////////////////////////
35 INLINE bool VrpnClient::
36 is_valid() const {
37  return (_connection->doing_okay() != 0);
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: VrpnClient::is_connected
42 // Access: Public
43 // Description: Returns true if the connection is established
44 // successfully, false otherwise.
45 ////////////////////////////////////////////////////////////////////
46 INLINE bool VrpnClient::
47 is_connected() const {
48  return (_connection->connected() != 0);
49 }
50 
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: VrpnClient::convert_to_secs
54 // Access: Public, Static
55 // Description: Little inline function to convert a struct timeval
56 // to only seconds
57 ////////////////////////////////////////////////////////////////////
58 INLINE double VrpnClient::
59 convert_to_secs(struct timeval msg_time) {
60  return (double)(msg_time.tv_sec) + (double)msg_time.tv_usec * 0.000001;
61 }
62 
63 
64 
65 
66 #if 0
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: VrpnClient::constructor
70 // Access: Public
71 // Description:
72 ////////////////////////////////////////////////////////////////////
73 INLINE VrpnClient::
74 VrpnClient(const string &server) :
75  ClientBase(server)
76 {
77  _connection = vrpn_get_connection_by_name(server.c_str());
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: VrpnClient::tracker_position
82 // Access: Private
83 // Description: Stores the latest position information as sent by
84 // the tracker (for the particular sensor we have
85 // interest in)
86 ////////////////////////////////////////////////////////////////////
87 INLINE void VrpnClient::
88 tracker_position(const string &tracker, const vrpn_TRACKERCB info) {
89  double ptime = convert_to_secs(info.msg_time);
90  LPoint3 pos(info.pos[0], info.pos[1], info.pos[2]);
91  LVector4 pquat(info.quat[0], info.quat[1], info.quat[2], info.quat[3]);
92 
93  push_tracker_position(tracker, info.sensor, ptime, pos, pquat);
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: VrpnClient::tracker_velocity
98 // Access: Private
99 // Description: Stores the latest velocity information as sent by
100 // the tracker (for the particular sensor we have
101 // interest in)
102 ////////////////////////////////////////////////////////////////////
103 INLINE void VrpnClient::
104 tracker_velocity(const string &tracker, const vrpn_TRACKERVELCB info) {
105  double vtime = convert_to_secs(info.msg_time);
106  LPoint3 vel(info.vel[0], info.vel[1], info.vel[2]);
107  LVector4 vquat(info.vel_quat[0], info.vel_quat[1],
108  info.vel_quat[2], info.vel_quat[3]);
109  PN_stdfloat dt = info.vel_quat_dt;
110 
111  push_tracker_velocity(tracker, info.sensor, vtime, vel, vquat, dt);
112 }
113 ////////////////////////////////////////////////////////////////////
114 // Function: VrpnClient::tracker_acceleration
115 // Access: Private
116 // Description: Stores the latest acceleration information as sent by
117 // the tracker (for the particular sensor we have
118 // interest in)
119 ////////////////////////////////////////////////////////////////////
120 INLINE void VrpnClient::
121 tracker_acceleration(const string &tracker, const vrpn_TRACKERACCCB info) {
122  double atime = convert_to_secs(info.msg_time);
123  LPoint3 acc(info.acc[0], info.acc[1], info.acc[2]);
124  LVector4 aquat(info.acc_quat[0], info.acc_quat[1],
125  info.acc_quat[2], info.acc_quat[3]);
126  PN_stdfloat dt = info.acc_quat_dt;
127 
128  push_tracker_acceleration(tracker, info.sensor, atime, acc, aquat, dt);
129 }
130 
131 ////////////////////////////////////////////////////////////////////
132 // Function: VrpnClient::analog
133 // Access: Private
134 // Description: Stores the latest information as sent by
135 // the analog device
136 ////////////////////////////////////////////////////////////////////
137 INLINE void VrpnClient::
138 analog(const string &analog, const vrpn_ANALOGCB info) {
139  double atime = convert_to_secs(info.msg_time);
140 
141  push_analog(analog, atime, info.channel, info.num_channel);
142 }
143 
144 ////////////////////////////////////////////////////////////////////
145 // Function: VrpnClient::button
146 // Access: Private
147 // Description: Stores the latest button pressed information as sent by
148 // the button
149 ////////////////////////////////////////////////////////////////////
150 INLINE void VrpnClient::
151 button(const string &button, const vrpn_BUTTONCB info) {
152  double btime = convert_to_secs(info.msg_time);
153 
154  push_button(button, btime, info.button, info.state);
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: VrpnClient::dial
159 // Access: Private
160 // Description: Stores the latest change information as sent by
161 // the dial
162 ////////////////////////////////////////////////////////////////////
163 INLINE void VrpnClient::
164 dial(const string &dial, const vrpn_DIALCB info) {
165  double dtime = convert_to_secs(info.msg_time);
166 
167  push_dial(dial, dtime, info.dial, info.change);
168 }
169 
170 #endif
bool is_connected() const
Returns true if the connection is established successfully, false otherwise.
Definition: vrpnClient.I:47
const string & get_server_name() const
Returns the name of the server as passed to the VrpnClient constructor.
Definition: vrpnClient.I:24
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
bool is_valid() const
Returns true if everything seems to be kosher with the server (even if there is no connection)...
Definition: vrpnClient.I:36
This is a four-component vector distance.
Definition: lvector4.h:91
An abstract base class for a family of client device interfaces–including trackers, buttons, dials, and other analog inputs.
Definition: clientBase.h:47
static double convert_to_secs(struct timeval msg_time)
Little inline function to convert a struct timeval to only seconds.
Definition: vrpnClient.I:59