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

panda/src/device/analogNode.cxx

Go to the documentation of this file.
00001 // Filename: analogNode.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 "analogNode.h"
00020 #include "config_device.h"
00021 #include "dataNodeTransmit.h"
00022 #include "dcast.h"
00023 
00024 
00025 TypeHandle AnalogNode::_type_handle;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: AnalogNode::Constructor
00029 //       Access: Public
00030 //  Description:
00031 ////////////////////////////////////////////////////////////////////
00032 AnalogNode::
00033 AnalogNode(ClientBase *client, const string &device_name) :
00034   DataNode(device_name)
00035 {
00036   _xy_output = define_output("xy", EventStoreVec2::get_class_type());
00037   _xy = new EventStoreVec2(LPoint2f(0.0f, 0.0f));
00038 
00039   nassertv(client != (ClientBase *)NULL);
00040   PT(ClientDevice) device =
00041     client->get_device(ClientAnalogDevice::get_class_type(), device_name);
00042 
00043   if (device == (ClientDevice *)NULL) {
00044     device_cat.warning()
00045       << "Unable to open analog device " << device_name << "\n";
00046     return;
00047   }
00048 
00049   if (!device->is_of_type(ClientAnalogDevice::get_class_type())) {
00050     device_cat.error()
00051       << "Inappropriate device type " << device->get_type()
00052       << " created; expected a ClientAnalogDevice.\n";
00053     return;
00054   }
00055 
00056   _analog = DCAST(ClientAnalogDevice, device);
00057 }
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: AnalogNode::Destructor
00061 //       Access: Public, Virtual
00062 //  Description:
00063 ////////////////////////////////////////////////////////////////////
00064 AnalogNode::
00065 ~AnalogNode() {
00066   // When the _analog pointer destructs, the ClientAnalogDevice
00067   // disconnects itself from the ClientBase, and everything that needs
00068   // to get turned off does.  Magic.
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: AnalogNode::write
00073 //       Access: Public, Virtual
00074 //  Description:
00075 ////////////////////////////////////////////////////////////////////
00076 void AnalogNode::
00077 write(ostream &out, int indent_level) const {
00078   DataNode::write(out, indent_level);
00079 
00080   if (_analog != (ClientAnalogDevice *)NULL) {
00081     _analog->lock();
00082     _analog->write_controls(out, indent_level + 2);
00083     _analog->unlock();
00084   }
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: AnalogNode::do_transmit_data
00089 //       Access: Protected, Virtual
00090 //  Description: The virtual implementation of transmit_data().  This
00091 //               function receives an array of input parameters and
00092 //               should generate an array of output parameters.  The
00093 //               input parameters may be accessed with the index
00094 //               numbers returned by the define_input() calls that
00095 //               were made earlier (presumably in the constructor);
00096 //               likewise, the output parameters should be set with
00097 //               the index numbers returned by the define_output()
00098 //               calls.
00099 ////////////////////////////////////////////////////////////////////
00100 void AnalogNode::
00101 do_transmit_data(const DataNodeTransmit &, DataNodeTransmit &output) {
00102   if (is_valid()) {
00103     _analog->poll();
00104 
00105     LPoint2f out(0.0f, 0.0f);
00106 
00107     _analog->lock();
00108     for (int i = 0; i < max_outputs; i++) {
00109       if (_outputs[i]._index >= 0 &&
00110           _analog->is_control_known(_outputs[i]._index)) {
00111         if (_outputs[i]._flip) {
00112           out[i] = -_analog->get_control_state(_outputs[i]._index);
00113         } else {
00114           out[i] = _analog->get_control_state(_outputs[i]._index);
00115         }
00116       }
00117     }
00118     _analog->unlock();
00119     _xy->set_value(out);
00120     output.set_data(_xy_output, EventParameter(_xy));
00121   }
00122 }

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