Panda3D

clientAnalogDevice.h

00001 // Filename: clientAnalogDevice.h
00002 // Created by:  drose (26Jan01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef CLIENTANALOGDEVICE_H
00016 #define CLIENTANALOGDEVICE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "clientDevice.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //       Class : ClientAnalogDevice
00024 // Description : A device, attached to the ClientBase by a
00025 //               AnalogNode, that records the data from a single
00026 //               named analog device.  The named device can contain
00027 //               any number of analog controls, numbered in
00028 //               sequence beginning at zero.
00029 //
00030 //               Each analog control returns a value ranging from -1
00031 //               to 1, reflecting the current position of the control
00032 //               within its total range of motion.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_PANDA_DEVICE ClientAnalogDevice : public ClientDevice {
00035 protected:
00036   INLINE ClientAnalogDevice(ClientBase *client, const string &device_name);
00037 
00038 public:
00039   INLINE int get_num_controls() const;
00040 
00041   INLINE void set_control_state(int index, double state);
00042   INLINE double get_control_state(int index) const;
00043   INLINE bool is_control_known(int index) const;
00044 
00045   virtual void write(ostream &out, int indent_level = 0) const;
00046   void write_controls(ostream &out, int indent_level) const;
00047 
00048 private:
00049   void ensure_control_index(int index);
00050 
00051 protected:
00052   class AnalogState {
00053   public:
00054     INLINE AnalogState();
00055 
00056     double _state;
00057     bool _known;
00058   };
00059 
00060   typedef pvector<AnalogState> Controls;
00061   Controls _controls;
00062 
00063 
00064 public:
00065   static TypeHandle get_class_type() {
00066     return _type_handle;
00067   }
00068   static void init_type() {
00069     ClientDevice::init_type();
00070     register_type(_type_handle, "ClientAnalogDevice",
00071                   ClientDevice::get_class_type());
00072   }
00073   virtual TypeHandle get_type() const {
00074     return get_class_type();
00075   }
00076   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00077 
00078 private:
00079   static TypeHandle _type_handle;
00080 };
00081 
00082 #include "clientAnalogDevice.I"
00083 
00084 #endif
 All Classes Functions Variables Enumerations