00001 // Filename: analogNode.h 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 #ifndef ANALOGNODE_H 00020 #define ANALOGNODE_H 00021 00022 #include "pandabase.h" 00023 00024 #include "clientBase.h" 00025 #include "clientAnalogDevice.h" 00026 #include "dataNode.h" 00027 #include "linmath_events.h" 00028 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Class : AnalogNode 00032 // Description : This is the primary interface to analog controls like 00033 // sliders and joysticks associated with a ClientBase. 00034 // This creates a node that connects to the named analog 00035 // device, if it exists, and provides hooks to the user 00036 // to read the state of any of the sequentially numbered 00037 // controls associated with that device. 00038 // 00039 // Each control can return a value ranging from -1 to 1, 00040 // reflecting the current position of the control within 00041 // its total range of motion. 00042 // 00043 // The user may choose up to two analog controls to 00044 // place on the data graph as the two channels of an 00045 // xy datagram, similarly to the way a mouse places its 00046 // position data. In this way, an AnalogNode may be 00047 // used in place of a mouse. 00048 //////////////////////////////////////////////////////////////////// 00049 class EXPCL_PANDA AnalogNode : public DataNode { 00050 PUBLISHED: 00051 AnalogNode(ClientBase *client, const string &device_name); 00052 virtual ~AnalogNode(); 00053 00054 INLINE bool is_valid() const; 00055 00056 INLINE int get_num_controls() const; 00057 00058 INLINE double get_control_state(int index) const; 00059 INLINE bool is_control_known(int index) const; 00060 00061 INLINE void set_output(int channel, int index, bool flip); 00062 INLINE void clear_output(int channel); 00063 INLINE int get_output(int channel) const; 00064 INLINE bool is_output_flipped(int channel) const; 00065 00066 public: 00067 virtual void write(ostream &out, int indent_level = 0) const; 00068 00069 private: 00070 class OutputData { 00071 public: 00072 INLINE OutputData(); 00073 int _index; 00074 bool _flip; 00075 }; 00076 00077 enum { max_outputs = 2 }; 00078 OutputData _outputs[max_outputs]; 00079 00080 PT(ClientAnalogDevice) _analog; 00081 00082 protected: 00083 // Inherited from DataNode 00084 virtual void do_transmit_data(const DataNodeTransmit &input, 00085 DataNodeTransmit &output); 00086 00087 private: 00088 // outputs 00089 int _xy_output; 00090 00091 PT(EventStoreVec2) _xy; 00092 00093 public: 00094 static TypeHandle get_class_type() { 00095 return _type_handle; 00096 } 00097 static void init_type() { 00098 DataNode::init_type(); 00099 register_type(_type_handle, "AnalogNode", 00100 DataNode::get_class_type()); 00101 } 00102 virtual TypeHandle get_type() const { 00103 return get_class_type(); 00104 } 00105 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00106 00107 private: 00108 static TypeHandle _type_handle; 00109 }; 00110 00111 #include "analogNode.I" 00112 00113 #endif