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