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