27 VrpnTracker(
const std::string &tracker_name, vrpn_Connection *connection) :
28 _tracker_name(tracker_name)
30 _tracker =
new vrpn_Tracker_Remote(_tracker_name.c_str(), connection);
32 _tracker->register_change_handler((
void*)
this, &vrpn_position_callback);
33 _tracker->register_change_handler((
void*)
this, &vrpn_velocity_callback);
34 _tracker->register_change_handler((
void*)
this, &vrpn_acceleration_callback);
51 if (vrpn_cat.is_debug()) {
52 vrpn_cat.debug() << *
this <<
" marking " << *device <<
"\n";
54 _devices.push_back(device);
63 if (vrpn_cat.is_debug()) {
64 vrpn_cat.debug() << *
this <<
" unmarking " << *device <<
"\n";
67 Devices::iterator di =
68 find(_devices.begin(), _devices.end(), device);
70 if (di != _devices.end()) {
88 output(std::ostream &out)
const {
96 write(std::ostream &out,
int indent_level)
const {
99 << _devices.size() <<
" devices)\n";
106 void VRPN_CALLBACK VrpnTracker::
107 vrpn_position_callback(
void *userdata,
const vrpn_TRACKERCB info) {
109 if (vrpn_cat.is_spam()) {
111 << *
self <<
" position_callback\n";
114 Devices::iterator di;
115 for (di = self->_devices.begin(); di !=
self->_devices.end(); ++di) {
119 device->tracker_changed(LPoint3(info.pos[0], info.pos[1], info.pos[2]),
120 LOrientation(info.quat[3], info.quat[0],
121 info.quat[1], info.quat[2]),
131 void VRPN_CALLBACK VrpnTracker::
132 vrpn_velocity_callback(
void *userdata,
const vrpn_TRACKERVELCB info) {
134 if (vrpn_cat.is_spam()) {
136 << *
self <<
" velocity_callback\n";
139 Devices::iterator di;
140 for (di = self->_devices.begin(); di !=
self->_devices.end(); ++di) {
144 device->tracker_changed(LPoint3(info.vel[0], info.vel[1], info.vel[2]),
145 LOrientation(info.vel_quat[3], info.vel_quat[0],
146 info.vel_quat[1], info.vel_quat[2]),
156 void VRPN_CALLBACK VrpnTracker::
157 vrpn_acceleration_callback(
void *userdata,
const vrpn_TRACKERACCCB info) {
159 if (vrpn_cat.is_spam()) {
161 << *
self <<
" acceleration_callback\n";
164 Devices::iterator di;
165 for (di = self->_devices.begin(); di !=
self->_devices.end(); ++di) {
168 device->
get_data_type() == VrpnTrackerDevice::DT_acceleration) {
169 device->tracker_changed(LPoint3(info.acc[0], info.acc[1], info.acc[2]),
170 LOrientation(info.acc_quat[3], info.acc_quat[0],
171 info.acc_quat[1], info.acc_quat[2]),
static double convert_to_secs(struct timeval msg_time)
Little inline function to convert a struct timeval to only seconds.
The Panda interface to a VRPN tracker.
int get_sensor() const
Returns the particular sensor index that this device wants to hear about from the VrpnTracker.
DataType get_data_type() const
Returns the type of data this device represents from the VrpnTracker.
This is the actual interface to a particular VRPN tracker object, and all of its sensors.
void mark(VrpnTrackerDevice *device)
Adds the indicated VrpnTrackerDevice to the list of devices that are sharing this VrpnTracker.
const std::string & get_tracker_name() const
Returns the name of the tracker device that was used to create this VrpnTracker.
void unmark(VrpnTrackerDevice *device)
Removes the indicated VrpnTrackerDevice from the list of devices that are sharing this VrpnTracker.
void poll()
Polls the connected device.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.