Panda3D
analogNode.h
1 // Filename: analogNode.h
2 // Created by: drose (12Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef ANALOGNODE_H
16 #define ANALOGNODE_H
17 
18 #include "pandabase.h"
19 
20 #include "clientBase.h"
21 #include "clientAnalogDevice.h"
22 #include "dataNode.h"
23 #include "linmath_events.h"
24 
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : AnalogNode
28 // Description : This is the primary interface to analog controls like
29 // sliders and joysticks associated with a ClientBase.
30 // This creates a node that connects to the named analog
31 // device, if it exists, and provides hooks to the user
32 // to read the state of any of the sequentially numbered
33 // controls associated with that device.
34 //
35 // Each control can return a value ranging from -1 to 1,
36 // reflecting the current position of the control within
37 // its total range of motion.
38 //
39 // The user may choose up to two analog controls to
40 // place on the data graph as the two channels of an
41 // xy datagram, similarly to the way a mouse places its
42 // position data. In this way, an AnalogNode may be
43 // used in place of a mouse.
44 ////////////////////////////////////////////////////////////////////
45 class EXPCL_PANDA_DEVICE AnalogNode : public DataNode {
46 PUBLISHED:
47  AnalogNode(ClientBase *client, const string &device_name);
48  virtual ~AnalogNode();
49 
50  INLINE bool is_valid() const;
51 
52  INLINE int get_num_controls() const;
53 
54  INLINE double get_control_state(int index) const;
55  INLINE bool is_control_known(int index) const;
56 
57  INLINE void set_output(int channel, int index, bool flip);
58  INLINE void clear_output(int channel);
59  INLINE int get_output(int channel) const;
60  INLINE bool is_output_flipped(int channel) const;
61 
62 public:
63  virtual void write(ostream &out, int indent_level = 0) const;
64 
65 private:
66  class OutputData {
67  public:
68  INLINE OutputData();
69  int _index;
70  bool _flip;
71  };
72 
73  enum { max_outputs = 2 };
74  OutputData _outputs[max_outputs];
75 
76  PT(ClientAnalogDevice) _analog;
77 
78 protected:
79  // Inherited from DataNode
80  virtual void do_transmit_data(DataGraphTraverser *trav,
81  const DataNodeTransmit &input,
82  DataNodeTransmit &output);
83 
84 private:
85  // outputs
86  int _xy_output;
87 
88  PT(EventStoreVec2) _xy;
89 
90 public:
91  static TypeHandle get_class_type() {
92  return _type_handle;
93  }
94  static void init_type() {
95  DataNode::init_type();
96  register_type(_type_handle, "AnalogNode",
97  DataNode::get_class_type());
98  }
99  virtual TypeHandle get_type() const {
100  return get_class_type();
101  }
102  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
103 
104 private:
105  static TypeHandle _type_handle;
106 };
107 
108 #include "analogNode.I"
109 
110 #endif
The fundamental type of node for the data graph.
Definition: dataNode.h:64
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
Definition: paramValue.h:109
A device, attached to the ClientBase by a AnalogNode, that records the data from a single named analo...
An abstract base class for a family of client device interfaces–including trackers, buttons, dials, and other analog inputs.
Definition: clientBase.h:47
This is the primary interface to analog controls like sliders and joysticks associated with a ClientB...
Definition: analogNode.h:45
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Encapsulates the data generated from (or sent into) any particular DataNode.
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...