Panda3D

trackerNode.cxx

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