Panda3D
Loading...
Searching...
No Matches
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 */
39class EXPCL_PANDA_DEVICE AnalogNode : public DataNode {
40PUBLISHED:
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
57public:
58 virtual void write(std::ostream &out, int indent_level = 0) const;
59
60private:
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
73protected:
74 // Inherited from DataNode
75 virtual void do_transmit_data(DataGraphTraverser *trav,
76 const DataNodeTransmit &input,
77 DataNodeTransmit &output);
78
79private:
80 // outputs
81 int _xy_output;
82
83 PT(EventStoreVec2) _xy;
84
85public:
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
99private:
100 static TypeHandle _type_handle;
101};
102
103#include "analogNode.I"
104
105#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_output(int channel, int index, bool flip)
Causes a particular analog control to be placed in the data graph for the indicated channel.
Definition analogNode.I:67
bool is_output_flipped(int channel) const
Returns true if the analog control index that is output to the data graph on the indicated channel is...
Definition analogNode.I:99
bool is_control_known(int index) const
Returns true if the state of the indicated analog control is known, or false if we have never heard a...
Definition analogNode.I:56
int get_output(int channel) const
Returns the analog control index that is output to the data graph on the indicated channel,...
Definition analogNode.I:89
int get_num_controls() const
Returns the number of analog controls known to the AnalogNode.
Definition analogNode.I:37
void clear_output(int channel)
Removes the output to the data graph associated with the indicated channel.
Definition analogNode.I:78
double get_control_state(int index) const
Returns the current position of indicated analog control identified by its index number,...
Definition analogNode.I:47
bool is_valid() const
Returns true if the AnalogNode is valid and connected to a server, false otherwise.
Definition analogNode.I:28
An abstract base class for a family of client device interfaces–including trackers,...
Definition clientBase.h:43
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...
Encapsulates the data generated from (or sent into) any particular DataNode.
This is a structure representing a single input device.
Definition inputDevice.h:53
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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(),...