Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/device/trackerNode.cxx

Go to the documentation of this file.
00001 // Filename: trackerNode.cxx
00002 // Created by:  drose (12Mar02)
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 #include "trackerNode.h"
00020 #include "config_device.h"
00021 
00022 TypeHandle TrackerNode::_type_handle;
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: TrackerNode::Constructor
00026 //       Access: Public
00027 //  Description:
00028 ////////////////////////////////////////////////////////////////////
00029 TrackerNode::
00030 TrackerNode(ClientBase *client, const string &device_name) :
00031   DataNode(device_name)
00032 {
00033   _transform_output = define_output("transform", EventStoreTransform::get_class_type());
00034 
00035   _transform = new EventStoreTransform(TransformState::make_identity());
00036 
00037   nassertv(client != (ClientBase *)NULL);
00038   set_tracker_coordinate_system(client->get_coordinate_system());
00039   set_graph_coordinate_system(CS_default);
00040 
00041   PT(ClientDevice) device =
00042     client->get_device(ClientTrackerDevice::get_class_type(), device_name);
00043 
00044   if (device == (ClientDevice *)NULL) {
00045     device_cat.warning()
00046       << "Unable to open tracker device " << device_name << "\n";
00047     return;
00048   }
00049 
00050   if (!device->is_of_type(ClientTrackerDevice::get_class_type())) {
00051     device_cat.error()
00052       << "Inappropriate device type " << device->get_type()
00053       << " created; expected a ClientTrackerDevice.\n";
00054     return;
00055   }
00056 
00057   _tracker = DCAST(ClientTrackerDevice, device);
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: TrackerNode::Destructor
00062 //       Access: Public, Virtual
00063 //  Description:
00064 ////////////////////////////////////////////////////////////////////
00065 TrackerNode::
00066 ~TrackerNode() {
00067   // When the _tracker pointer destructs, the ClientTrackerDevice
00068   // disconnects itself from the ClientBase, and everything that needs
00069   // to get turned off does.  Magic.
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: TrackerNode::do_transmit_data
00074 //       Access: Protected, Virtual
00075 //  Description: The virtual implementation of transmit_data().  This
00076 //               function receives an array of input parameters and
00077 //               should generate an array of output parameters.  The
00078 //               input parameters may be accessed with the index
00079 //               numbers returned by the define_input() calls that
00080 //               were made earlier (presumably in the constructor);
00081 //               likewise, the output parameters should be set with
00082 //               the index numbers returned by the define_output()
00083 //               calls.
00084 ////////////////////////////////////////////////////////////////////
00085 void TrackerNode::
00086 do_transmit_data(const DataNodeTransmit &, DataNodeTransmit &output) {
00087   if (is_valid()) {
00088     _tracker->poll();
00089     _tracker->lock();
00090     _data = _tracker->get_data();
00091     _tracker->unlock();
00092 
00093     _data.get_orient().extract_to_matrix(_mat);
00094     if (_tracker_cs != _graph_cs) {
00095       // Convert the rotation for passing down the data graph.
00096       _mat = _mat * LMatrix4f::convert_mat(_tracker_cs, _graph_cs);
00097     }
00098     _mat.set_row(3, _data.get_pos());
00099 
00100     // Now send our matrix down the pipe.  TODO: store this
00101     // componentwise instead of just as a matrix-based transform.
00102     _transform->set_value(TransformState::make_mat(_mat));
00103     output.set_data(_transform_output, EventParameter(_transform));
00104   }
00105 }

Generated on Fri May 2 00:36:17 2003 for Panda by doxygen1.3