00001 // Filename: vrpnClient.I 00002 // Created by: jason (04Aug00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 00017 //////////////////////////////////////////////////////////////////// 00018 // Function: VrpnClient::get_server_name 00019 // Access: Public 00020 // Description: Returns the name of the server as passed to the 00021 // VrpnClient constructor. 00022 //////////////////////////////////////////////////////////////////// 00023 INLINE const string &VrpnClient:: 00024 get_server_name() const { 00025 return _server_name; 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: VrpnClient::is_valid 00030 // Access: Public 00031 // Description: Returns true if everything seems to be kosher with 00032 // the server (even if there is no connection), or false 00033 // otherwise. 00034 //////////////////////////////////////////////////////////////////// 00035 INLINE bool VrpnClient:: 00036 is_valid() const { 00037 return (_connection->doing_okay() != 0); 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: VrpnClient::is_connected 00042 // Access: Public 00043 // Description: Returns true if the connection is established 00044 // successfully, false otherwise. 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE bool VrpnClient:: 00047 is_connected() const { 00048 return (_connection->connected() != 0); 00049 } 00050 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: VrpnClient::convert_to_secs 00054 // Access: Public, Static 00055 // Description: Little inline function to convert a struct timeval 00056 // to only seconds 00057 //////////////////////////////////////////////////////////////////// 00058 INLINE double VrpnClient:: 00059 convert_to_secs(struct timeval msg_time) { 00060 return (double)(msg_time.tv_sec) + (double)msg_time.tv_usec * 0.000001; 00061 } 00062 00063 00064 00065 00066 #if 0 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: VrpnClient::constructor 00070 // Access: Public 00071 // Description: 00072 //////////////////////////////////////////////////////////////////// 00073 INLINE VrpnClient:: 00074 VrpnClient(const string &server) : 00075 ClientBase(server) 00076 { 00077 _connection = vrpn_get_connection_by_name(server.c_str()); 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: VrpnClient::tracker_position 00082 // Access: Private 00083 // Description: Stores the latest position information as sent by 00084 // the tracker (for the particular sensor we have 00085 // interest in) 00086 //////////////////////////////////////////////////////////////////// 00087 INLINE void VrpnClient:: 00088 tracker_position(const string &tracker, const vrpn_TRACKERCB info) { 00089 double ptime = convert_to_secs(info.msg_time); 00090 LPoint3 pos(info.pos[0], info.pos[1], info.pos[2]); 00091 LVector4 pquat(info.quat[0], info.quat[1], info.quat[2], info.quat[3]); 00092 00093 push_tracker_position(tracker, info.sensor, ptime, pos, pquat); 00094 } 00095 00096 //////////////////////////////////////////////////////////////////// 00097 // Function: VrpnClient::tracker_velocity 00098 // Access: Private 00099 // Description: Stores the latest velocity information as sent by 00100 // the tracker (for the particular sensor we have 00101 // interest in) 00102 //////////////////////////////////////////////////////////////////// 00103 INLINE void VrpnClient:: 00104 tracker_velocity(const string &tracker, const vrpn_TRACKERVELCB info) { 00105 double vtime = convert_to_secs(info.msg_time); 00106 LPoint3 vel(info.vel[0], info.vel[1], info.vel[2]); 00107 LVector4 vquat(info.vel_quat[0], info.vel_quat[1], 00108 info.vel_quat[2], info.vel_quat[3]); 00109 PN_stdfloat dt = info.vel_quat_dt; 00110 00111 push_tracker_velocity(tracker, info.sensor, vtime, vel, vquat, dt); 00112 } 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: VrpnClient::tracker_acceleration 00115 // Access: Private 00116 // Description: Stores the latest acceleration information as sent by 00117 // the tracker (for the particular sensor we have 00118 // interest in) 00119 //////////////////////////////////////////////////////////////////// 00120 INLINE void VrpnClient:: 00121 tracker_acceleration(const string &tracker, const vrpn_TRACKERACCCB info) { 00122 double atime = convert_to_secs(info.msg_time); 00123 LPoint3 acc(info.acc[0], info.acc[1], info.acc[2]); 00124 LVector4 aquat(info.acc_quat[0], info.acc_quat[1], 00125 info.acc_quat[2], info.acc_quat[3]); 00126 PN_stdfloat dt = info.acc_quat_dt; 00127 00128 push_tracker_acceleration(tracker, info.sensor, atime, acc, aquat, dt); 00129 } 00130 00131 //////////////////////////////////////////////////////////////////// 00132 // Function: VrpnClient::analog 00133 // Access: Private 00134 // Description: Stores the latest information as sent by 00135 // the analog device 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE void VrpnClient:: 00138 analog(const string &analog, const vrpn_ANALOGCB info) { 00139 double atime = convert_to_secs(info.msg_time); 00140 00141 push_analog(analog, atime, info.channel, info.num_channel); 00142 } 00143 00144 //////////////////////////////////////////////////////////////////// 00145 // Function: VrpnClient::button 00146 // Access: Private 00147 // Description: Stores the latest button pressed information as sent by 00148 // the button 00149 //////////////////////////////////////////////////////////////////// 00150 INLINE void VrpnClient:: 00151 button(const string &button, const vrpn_BUTTONCB info) { 00152 double btime = convert_to_secs(info.msg_time); 00153 00154 push_button(button, btime, info.button, info.state); 00155 } 00156 00157 //////////////////////////////////////////////////////////////////// 00158 // Function: VrpnClient::dial 00159 // Access: Private 00160 // Description: Stores the latest change information as sent by 00161 // the dial 00162 //////////////////////////////////////////////////////////////////// 00163 INLINE void VrpnClient:: 00164 dial(const string &dial, const vrpn_DIALCB info) { 00165 double dtime = convert_to_secs(info.msg_time); 00166 00167 push_dial(dial, dtime, info.dial, info.change); 00168 } 00169 00170 #endif