Panda3D
analogNode.I
1 // Filename: analogNode.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: AnalogNode::OutputData::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE AnalogNode::OutputData::
22 OutputData() {
23  _index = -1;
24  _flip = false;
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: AnalogNode::is_valid
29 // Access: Public
30 // Description: Returns true if the AnalogNode is valid and
31 // connected to a server, false otherwise.
32 ////////////////////////////////////////////////////////////////////
33 INLINE bool AnalogNode::
34 is_valid() const {
35  return (_analog != (ClientAnalogDevice *)NULL) && _analog->is_connected();
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: AnalogNode::get_num_controls
40 // Access: Public
41 // Description: Returns the number of analog controls known to the
42 // AnalogNode. This number may change as more controls
43 // are discovered.
44 ////////////////////////////////////////////////////////////////////
45 INLINE int AnalogNode::
47  _analog->acquire();
48  int result = _analog->get_num_controls();
49  _analog->unlock();
50  return result;
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: AnalogNode::get_control_state
55 // Access: Public
56 // Description: Returns the current position of indicated analog
57 // control identified by its index number, or 0.0 if
58 // the control is unknown. The normal range of a single
59 // control is -1.0 to 1.0.
60 ////////////////////////////////////////////////////////////////////
61 INLINE double AnalogNode::
62 get_control_state(int index) const {
63  _analog->acquire();
64  double result = _analog->get_control_state(index);
65  _analog->unlock();
66  return result;
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: AnalogNode::is_control_known
71 // Access: Public
72 // Description: Returns true if the state of the indicated analog
73 // control is known, or false if we have never heard
74 // anything about this particular control.
75 ////////////////////////////////////////////////////////////////////
76 INLINE bool AnalogNode::
77 is_control_known(int index) const {
78  _analog->acquire();
79  bool result = _analog->is_control_known(index);
80  _analog->unlock();
81  return result;
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: AnalogNode::set_output
86 // Access: Public
87 // Description: Causes a particular analog control to be placed in
88 // the data graph for the indicated channel. Normally,
89 // a mouse uses channels 0 and 1 for the X and Y
90 // information, respectively; channels 0, 1, and 2 are
91 // available. If flip is true, the analog control value
92 // will be reversed before outputting it.
93 ////////////////////////////////////////////////////////////////////
94 INLINE void AnalogNode::
95 set_output(int channel, int index, bool flip) {
96  nassertv(channel >= 0 && channel < max_outputs);
97  _outputs[channel]._index = index;
98  _outputs[channel]._flip = flip;
99 }
100 
101 ////////////////////////////////////////////////////////////////////
102 // Function: AnalogNode::clear_output
103 // Access: Public
104 // Description: Removes the output to the data graph associated with
105 // the indicated channel. See set_output().
106 ////////////////////////////////////////////////////////////////////
107 INLINE void AnalogNode::
108 clear_output(int channel) {
109  nassertv(channel >= 0 && channel < max_outputs);
110  _outputs[channel]._index = -1;
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: AnalogNode::get_output
115 // Access: Public
116 // Description: Returns the analog control index that is output to
117 // the data graph on the indicated channel, or -1 if no
118 // control is output on that channel. See set_output().
119 ////////////////////////////////////////////////////////////////////
120 INLINE int AnalogNode::
121 get_output(int channel) const {
122  nassertr(channel >= 0 && channel < max_outputs, -1);
123  return _outputs[channel]._index;
124 }
125 
126 ////////////////////////////////////////////////////////////////////
127 // Function: AnalogNode::is_output_flipped
128 // Access: Public
129 // Description: Returns true if the analog control index that is
130 // output to the data graph on the indicated channel is
131 // flipped. See set_output().
132 ////////////////////////////////////////////////////////////////////
133 INLINE bool AnalogNode::
134 is_output_flipped(int channel) const {
135  nassertr(channel >= 0 && channel < max_outputs, false);
136  return _outputs[channel]._flip;
137 }
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:134
void clear_output(int channel)
Removes the output to the data graph associated with the indicated channel.
Definition: analogNode.I:108
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:121
A device, attached to the ClientBase by a AnalogNode, that records the data from a single named analo...
bool is_valid() const
Returns true if the AnalogNode is valid and connected to a server, false otherwise.
Definition: analogNode.I:34
int get_num_controls() const
Returns the number of analog controls known to the AnalogNode.
Definition: analogNode.I:46
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:95
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:77
double get_control_state(int index) const
Returns the current position of indicated analog control identified by its index number, or 0.0 if the control is unknown.
Definition: analogNode.I:62