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