Panda3D
 All Classes Functions Variables Enumerations
clientAnalogDevice.I
1 // Filename: clientAnalogDevice.I
2 // Created by: drose (26Jan01)
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: ClientAnalogDevice::AnalogState::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ClientAnalogDevice::AnalogState::
22 AnalogState() :
23  _state(0.0),
24  _known(false)
25 {
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: ClientAnalogDevice::Constructor
30 // Access: Protected
31 // Description:
32 ////////////////////////////////////////////////////////////////////
33 INLINE ClientAnalogDevice::
34 ClientAnalogDevice(ClientBase *client, const string &device_name):
35  ClientDevice(client, get_class_type(), device_name)
36 {
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: ClientAnalogDevice::get_num_controls
41 // Access: Public
42 // Description: Returns the number of analog controls known to the
43 // ClientAnalogDevice. This number may change as
44 // more controls are discovered.
45 ////////////////////////////////////////////////////////////////////
46 INLINE int ClientAnalogDevice::
48  return _controls.size();
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: ClientAnalogDevice::set_control_state
53 // Access: Public
54 // Description: Sets the state of the indicated analog index. The
55 // caller should ensure that acquire() is in effect while
56 // this call is made. This should be a number in the
57 // range -1.0 to 1.0, representing the current position
58 // of the control within its total range of movement.
59 ////////////////////////////////////////////////////////////////////
60 INLINE void ClientAnalogDevice::
61 set_control_state(int index, double state) {
62  ensure_control_index(index);
63  nassertv(index >= 0 && index < (int)_controls.size());
64  _controls[index]._state = state;
65  _controls[index]._known = true;
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: ClientAnalogDevice::get_control_state
70 // Access: Public
71 // Description: Returns the current position of indicated analog
72 // control (identified by its index number), or 0.0 if
73 // the control is unknown. The normal range of a single
74 // control is -1.0 to 1.0.
75 ////////////////////////////////////////////////////////////////////
76 INLINE double ClientAnalogDevice::
77 get_control_state(int index) const {
78  if (index >= 0 && index < (int)_controls.size()) {
79  return _controls[index]._state;
80  } else {
81  return 0.0;
82  }
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: ClientAnalogDevice::is_control_known
87 // Access: Public
88 // Description: Returns true if the state of the indicated analog
89 // control is known, or false if we have never heard
90 // anything about this particular control.
91 ////////////////////////////////////////////////////////////////////
92 INLINE bool ClientAnalogDevice::
93 is_control_known(int index) const {
94  if (index >= 0 && index < (int)_controls.size()) {
95  return _controls[index]._known;
96  } else {
97  return false;
98  }
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...
void set_control_state(int index, double state)
Sets the state of the indicated analog index.
double get_control_state(int index) const
Returns the current position of indicated analog control (identified by its index number)...
An abstract base class for a family of client device interfaces–including trackers, buttons, dials, and other analog inputs.
Definition: clientBase.h:47
int get_num_controls() const
Returns the number of analog controls known to the ClientAnalogDevice.
Any of a number of different devices that might be attached to a ClientBase, including trackers...
Definition: clientDevice.h:35